4 ms·
This has been discussed before, and the tl;dr is that it's unlikely to happen. The discussion here[1] gives a sample of the implications and thought processes b
by sundarurfriend 5y ago
This has been discussed before, and the tl;dr is that it's unlikely to happen. The discussion here[1] gives a sample of the implications and thought processes behind it, considering what it would mean to have := in different contexts, but the conclusion was:
> It’s just an interesting thought experiment — we can’t practically do this even in a 2.0 release. It would be a massively breaking change: we would need to disallow implicit declaration of locals by assignment, which breaks all Julia code everywhere. I also think that what we do now is good and less annoying for new users since they will be accustomed to just assigning to initialize and declare new locals if they are coming from Python, R, Matlab or Ruby (to mention just a few).
(What isn't mentioned explicitly is that this would also break a lot of macro code which accepts assignment-like syntax, which would have to deal with this new type of node in the AST and make decisions about how to handle it.)
The good news is that, as Stefan mentions in a thread linked from there, you can already do `local mylongvarname = 5` as an explicit variable creation syntax; and Julia has good enough tooling to parse it (and is getting even better ones as we speak) that you can disallow assignment to any variable that you haven't seen before with a `local` declaration, with a linter-like step. So the linter will error on a later `mylngvarname = 42`.
It's not the language itself adding it as a feature - so code inherited from elsewhere likely won't have it, and you might have to get buy-in from your team - but it's probably as close as you can get to what you want.
[1] https://discourse.julialang.org/t/why-no-operator-for-initializing-variables/62949 https://discourse.julialang.org/t/why-no-operator-for-initia...