On Apr 21, 6:54 pm, Beoran <
beo...@gmail.com> wrote:
> Dear ⚛,
>
> As far a I can see, I think you and the designers of many other
> programming languages are mixing up two related but not quite same
> concepts:
> that of constancy and that of immutability.
I think I disagree with such a statement. Because there is only *one*
kind of immutability. Whether you/me/someone calls it constant-ness or
immutability does not really matter that much. Every immutability is
just temporary - it is like a tag that says a certain region of
computer memory cannot be modified during the time that the
"immutability tag" applies to that region. Maybe the previous sentence
is a little rough and imprecise, but if you don't generally agree with
it, then I am afraid we cannot reach a mutual understanding here.
> To me, a constant is, said in short, and object of which both the
> binary representation of the value
> and the address is fully defined and fully determined at compile time.
Address fully determined at compile time? What about constants in a
dynamic library?
> If you look at the
> assembly output, constant objects compile down to a label and set
> of .db (define byte)
> .dw, .l, or .string pseudo-instructions, usually in the .data section
> of the binary.
So, you are saying that e.g. C-style string constants cannot be
implemented in any different way? Why not? For example, it is possible
to dump all string constants during compilation into a separate file,
then read-only map the file into the address space of the program at
startup and fix all the pointers pointing to those strings.
In other words, if you are trying to imply that .string pseudo-
instructions are the "only true way" to define string constants, then
I don't buy it.
> An immutable object is an object that cannot be modified once it has
> been created,
> until it is destroyed. Stated otherwise, operations on an immutable
> object are guaranteed to
> have no side effects. An immutable object may however live in the heap
> or on the stack, unlike
> true constant objects.
I don't agree there exist such "true" constant objects.
If there was a C compiler which decides to place some string constant
onto the stack (assuming the compiled program will run correctly, of
course), then such a string is not a "true" constant? Why not? The
program has the same semantics, why do you care so much about how the
compiler implements the constant?
> For example, IIRC, in Haskell all types are
> essentially immutable,
> because side effects are disallowed, however, most types are not true
> constants as they live
> on the stack or heap)
I guess I am not a true follower of your religious teachings about
"true" constants ...
> Any constant object is trivially immutable. However, an immutable
> object may not be constant.
> This is a crucial difference. The const modifier in C /C is a huge
> misnomer, and a result of
In C/C++, "const char*" actually means that the string is either
mutable or immutable (you can read from it). Whereas "char*" means
that the string is known to be mutable (you can both read from it and
write to it).
Yes, it is totally confusing.
> this confusing immutability with constancy. Not to mention that I
> think it's an attempt at
> avoiding certain common errors in accessing pointers in C/C++. Errors
> which are not possible
> in Go, unless you use unsafe.
What "common errors in accessing pointers" do you mean?
> So I feel like I'm not convinced that having an immutable keyword
> would do any good in Go.
No problem. I am *not* forcing you to accept my viewpoint.
> Could you perhaps think of an example in Go (not C or C++) that would
> benefit from it? Go is still young,
> so if you make a convincing case, I think your proposal may be
> considered.
1. I am afraid I am not there quite yet. In other words, I am
incapable of providing a consistent proposal.
2. It is probable that many people wouldn't like it. (That's *not*
because I am a notorious pessimist or anything like that. The hunch I
am using here is that many people don't like complex programming
languages.)
> Perhaps it would be better
> to start a new thread on this subject as we're hijacking this one.