Skip to content

multiple assignment syntax/semantics seem of dubious utility #383

@ghost

Description

Consider code like the following:

a = 1
...do_something_with_a...
...do_something_else_with_a...

Assume in this case that the "do_something..." blocks are large and/or complex pieces of code where the use of "a" isn't necessarily immediately obvious. Now a maintenance programmer, fixing a bug, does the following:

a = 1
...do_something_with_a...
a = :foo
...do_something_else_with_a...

Code is now silently breaking because mutating the variable in-place (semantically, not necessarily physically) has just broken the "...do_something_else_with_a..." block. If this block isn't executed frequently it could be some time before the error is spotted.

Now what is bizarre to me is that to prevent this you'd need to do this instead, if I read the specs right:

a = 1
...do_something_with_a...
^a = :foo
...do_something_else_with_a...

You have to explicitly flag "I don't want to modify this variable", the maintenance programmer would actually have to know that there's another use of "a" later on. But if that's the case, there's no need for the ^ tag because the maintenance programmer wouldn't have changed the variable.

To me it would be most obvious to have non-mutability be the default state and that the ^tag is a way of saying "yes, I know I'm changing a previous value". In this way it's like the ! suffix on mutating Scheme functions and the like. The way it is seems, to my eyes, to have absolutely no use whatsoever.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions