3 ms·
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 v
by fetbaffe 10y ago
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.
Opening tag at the beginning of file is not really worth of doing anything about. If you separate concerns in your code, you don't do HTML in your model code, therefore the only tag in a the vast majority of PHP files is the opening tag a the top of the file.
Paradoxically, today you don't use PHP as templating language in modern PHP, because it is clunky. You use a templating language like mustache or twig.
Standard library, yes. That ought to be fixed. My proposal to solve that is to implement function autoloading and support for callable types (parameter and return type signatures to callables). With that you could start implement outside of PHP core and start deprecating old core functions and supply a library shim for those who need it.
And also with those two language features, it will be much easier to do functional programming instead of the now dominating OOP i the PHP community.
PHP since 5.5 is quite good and with this release it is even better. It is flexible but at the same time rigid with very good performance. No built in state, which is perfect for stateless API:s.
- egeozcan 10y agoYou 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