FAQ

On 02/19/2013 10:03 PM, Johann Höchtl wrote:
See it this way. I can carry a gun in my hand aiming towards a target. I
pull the trigger and hit the target. Everything happens exactly the whay
it is expected to happen.

Suddenly an inner block jumps in ... the instructor. Me, a gun in my
hand, the instructor in between and on the other side the target. I pull
the trigger.

Still ... everything happens exactly the way it is told to behave. Which
still makes the end results not a desirable result. Adding an "inner
block", which by itself is behaving in a fully specified way, influences
the whole.

Somewhat odd I admit, but you may get what I mean?
I don't to see a connection between your metaphorical example and the
code you've pasted. In your code, nothing jumps unexpectedly. If you
declare a new variable then you will get a new variable. If a variable
is declared within a block, it will hide any variable which shares its
identifier. When the variable's scope ends then any variable which has
been hidden will cease to be. It's quite straight forward.

The only problem with your code is that you wrote something (a variable
declaration) while you meant something entirely different (an
assignment). It's far simpler to acknowledge that a variable
declaration isn't an assignment than to perpetuate that misconception
and expect that the programming language should be bent to fit it.


Rui Maciel

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2021 Grokbase