If c
is hidden, why not +
? I don’t think I’d go for this, because there isn’t any ambiguity or confusion about what + c
means in that context. I like the issues I linked because they resolve common ambiguities and mistakes.
Because +
is a global, or module level, identifier. I said “outer local scopes”. If you have defined something like ⊕ in a local scope, or have your own local +
it would not be visible.
The actually important characteristic there is +
is const
. Variables that can’t get reassigned are safe to share, no reason to stop that. On the other hand, if you have a non-const
global variable, you get the same problem when you make an edit without thinking it through. However, a variable assignment in a local scope defaults to not borrowing from a global scope because a global scope can be scattered across multiple files, which is too annoying to be aware of all at once.
With this in mind, your c
example is actually a significantly different proposal from the tmp
example. c
is not reassigned, so in normal Julia nothing stops the scope from automatically borrowing c
. tmp
is assigned, so it only automatically borrows outer local tmp
. Again, I’ve mulled over these before with many very patient commenters, and no tweaks make anything generally easier. You really should know what variables are inside the entire function when you’re making edits. If your function is too big to do that, split it.
I agree to that. My idea was just to suggest an extension which e.g. could be part of coding style guidelines in particular projects to minimize such risks. In some contexts certain variable names end up being all over the place, reused for almost the same purpose. I can see that there is a certain amount of work implementing this extension, which I’m capable of doing myself, but I can’t see any particular downsides. It could be it’s not of much use for the occasional user, or the typical scientist, or the newcomer to julia. But for larger projects stretching over time with different developers, such mechanisms for avoiding mess might be useful. Or, maybe not.