On Dec 14, 9:54 pm, SnakE <
snake.sc...@gmail.com> wrote:
> 2009/12/14 hong <
h...@google.com>
> But the language prevents people from modifying array literals, right? It
> just allocates a new array every time a literal is used. When I say "work
> exactly like a literal" I mean exactly. Let const allocate a new array like
> if it were a C macro with an array literal inside.
Go team has several considerations.
One is the following: if it's built in to the language, it has to be
fast. If it's not fast, it has to be not built in.
This is why they have left more important things out - not one, but
many. Were they all built in, you couldn't write anything fast in Go
because of a lot of learning first, what is fast and what is slow.
Because const is supposed to be fastest variable type in a language -
it's usually doing all kinds of precalculations and other speed
optimizations - it shouldn't contain anything before they have figured
out how to make it really fast. Thus, to make it sure you can see if
variable is slow or fast, they have implemented it that way. And "work
exactly like a literal" is syntax error -
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/EWD667.html
...usually statements work like statements and they have a lot of
reasoning behind them, not just a need to make them look like
something they aren't. When you created an engine for something, you
would get the job done as easily and with the same quality as if const
did look like a literal, thus it's not an important feature right now.
Also, const is not a C macro, thus there is no need to follow C
specification.
Which all doesn't mean that I wouldnt like to have some slower and
more convenient things myself, but in this case I dont see the reason,
it's just wanting-because-of-wanting case.