Skip to content

scoping issues, part 1 #423

@thomie

Description

@thomie

Hello Julia developers,

congratulations with your great new language. I was singing 'O Julia' out loud all day yesterday.

But now my bug report. Notwithstanding the let, global and local keywords, it seems there is not always a clear distinction in Julia between variable declaration and assignment. This breaks encapsulation and can lead to hard to find bugs.

function some_scope()
    ...
    ... many lines of code
    ...
    f = () -> x = 42  # Not clear if this declares a local variable or assigns to one from the enclosing scope.
end

Matlab's scoping rules we don't even need to discuss [1], Coffeescript is a disaster [2], please don't copy Ruby on this one [3], Perl and Javascript are ok as long as you don't forget your my's and var's (or use strict), Python fixed it in version 3 [4], and one could say Scheme got it right the first time in 1970 [5].

What is the reasoning behind Julia's intricate scoping rules?

[1] http://www.mathworks.nl/help/techdoc/matlab_prog/f4-39683.html#f4-73993
[2] jashkenas/coffeescript#712
[3] http://www.rubyist.net/~matz/slides/rc2003/mgp00010.html
[4] http://www.python.org/dev/peps/pep-3104/
[5] http://news.ycombinator.com/item?id=3379962

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingThis change will break codeneeds decisionA decision on this change is neededspeculativeWhether the change will be implemented is speculative

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions