The situation in Perl and Lua is rather different than in Julia. In Perl, the default scopes for unqualified variables is global, which is really bad. You have to declare a variable using `my` in order to get lexical scoping; with `use strict`, you have to declare a global variable with `our` to avoid getting complaints – this is so that strict mode knows that you meant for it to be a global variable and didn't just do it by accident. Lua has the same deal – the default scope is global.
In Julia, this problem doesn't exist: the default scope of assigned variables is local. You explicitly have to declare any variable that is assigned global if you want to create or alter a global variable; otherwise the assignment creates or modifies a local variable. Since the default scope is local, Julia is effectively always in strict mode – you have to explicitly ask for the dangerous global scope behavior that is the default in Perl and Lua. One could write a checker that requires all local variables to be declared with `local`, but that seems a little pointless when `local` is the default anyway. You definitely don't want to have to declare every global variable since functions are globals, so you'd have to declare every function you call, which would be immensely annoying. On Fri, Feb 27, 2015 at 3:14 PM, Stéphane Goujet <[email protected] > wrote: > On Fri, 27 Feb 2015, Steven G. Johnson wrote: > > As I understand it, you are asking whether there is a Julia option (e.g. >> a runtime flag) that will cause Julia to throw an error if you try to parse >> code where local variables are not explicitly declared, analogous to "use >> strict" in Perl or "implicit none" in Fortran. >> > > You understood well. > > > There is no such thing in Julia, and I don't recall seeing any >> discussion of the possibility. (Requiring the programmer to explicitly >> declare all her variables is a little alien to the Julian style, so I'm >> guessing there might be some reluctance to implement this in the core >> language. >> > > I can undertand this, but I have been bitten severely by this kind of > problems in Perl (when I was a young fool not using "use strict;") and in > Lua (and a few others). It is nice not to have to worry about declarations > when you do one-liners or programs of a few dozens lines, but when programs > get longer (or have to be maintained after long periods of abandon) the > time lost debugging is much bigger than the time lost declaring. > Perl and Fortran introduced these options after a while and it is now > the first line of any program everyone types in these languages, for good > reasons. (It even became the default in Perl 6). > > Forgive me if I give the impression of the newcomer (which is what I am) > teaching lessons to regular users and seasoned developers, but this is an > important point to me, if I want to consider Julia *for my use*. I > understand that others may not care about my use, my style, my habits, my > troubles, there is no problem with that, my purpose is not to start a > revolution in the first thread I open after having written just 2 mini > Julia programs :-) > > > You could easily implement a Lint-like package to check for this >> requirement, though.) >> > > I trust you, that *someone* could *easily* do it, but that *I* could do > it easily is another story :-) > > > Goodbye, > Stéphane.
