Hacker News new | ask | show | jobs
by ptx 1466 days ago
> Variables aren’t immutable in any significant way because you can trivially turn an immutable reference into a mutable one.

To be fair, they didn't claim that the values were immutable, only the variables. Isn't the example in the article basically the same as Java's final variables, i.e. immutable references to mutable values?

> No global variables [...] Evaluation: V does not prevent you from creating and mutating globally shared state in any meaningful way.

Although I agree with the evaluation, the claim of "no global variables" might still hold, assuming it refers to mutable global variables. The global constant holds an immutable reference to a mutable value, just like how in Java a singleton object (or a class with mutable static fields) can be used to simulate global variables.

1 comments

It's just a one line bug in the checker, which can be reported via github, but it wouldn't be as dramatic.
Maybe I misunderstood then. I was saying that it seems to behave basically like Java. Is that a bug?
V has global consts, they are immutable, but can be initialized with complex expressions, for example

`const x = foo()`

There's a bug that allows to trick the compiler and modify the const via another variable, it's a one line fix, and will be fixed today.

Global mutable variables are only allowed with `-enable-globals` and are supposed to be used only in low level code, like drivers and kernels.

If I understand the example code correctly, it's modifying a heap-allocated struct that's pointed to by a global const. So the global const contains an address which is not modified, but the thing at that address is modified. Right?

What does the intended behaviour (after the fix) look like? Are mutable fields in structs disallowed if the struct is pointed to by a const?

After the fix it's not allowed to do

`mut x := immutable_var`

How's that "one line" fix in the type checker coming? Looks like it wasn't fixed yesterday.
It was fixed, but you keep fighting your fight. I'm sure there's another bug you can find to spread the "V is scam" message.
You only merged it one hour ago.

https://github.com/vlang/v/pull/14805

Over promising (hardly a one line patch) and under delivering (well beyond your "it will be fixed today" statement) as usual.