2 ms·
You convinced me generally, I can't agree with this only: > Dollar ($) as prefix to variable names is actually quite good. You know instinctively what is a use
by egeozcan 10y ago
You convinced me generally, I can't agree with this only:
> Dollar ($) as prefix to variable names is actually quite good. You know instinctively what is a user created variable and not a language keyword. Easy to find variables when scanning large chunks of code and easy to use with string replacement to avoid string concatenation or sprintf.
Dollar prefix is hard to type with many keyboard layouts. You can also get the same effect with let/var/def/whatever and without the useless repetition. Also, any text editor with minimal support for your syntax would be able to highlight the definition/usages. The theoretical Utopian syntax would perhaps also allow $ in template strings. Further,
$foo;
is a bit ambiguous because in a REPL, it would output foo, error if foo is not defined; in source code, it would define foo, no-op if already defined. While `def foo;` would only be valid if foo isn't defined and that'd be creating the variable. foo, by itself, would have a consistent meaning.
- piaste 10y ago> no-op if already defined Why shouldn't it be a compile-time error, in the same way as your suggested `def foo;`? I can't think of a legitimate reason for wanting to write an intentional no-op (at least at the level of PHP; obviously assembly etc. is a different ballpark entirely).
- fetbaffe 10y agoThanks! Yes, a good text editor helps a lot, I use PHPStorm, which is the best IDE to use for PHP. But there are times when you just scan code like diffs or what not, then it helps. Or search/grep for that matter. I type on a Swedish QWERTY keyboard layout, then you are used to use ALT-Gr for almost all special characters when coding, but I understand if you are on a US QWERTY then it can be a nuisance. Personally I find And ALT-Gr is easier to use then SHIFT. US https://en.wikipedia.org/wiki/File:KB_United_States-NoAltGr.svg https://en.wikipedia.org/wiki/File:KB_United_States-NoAltGr.... SE https://en.wikipedia.org/wiki/File:KB_Sweden.svg https://en.wikipedia.org/wiki/File:KB_Sweden.svg