4 ms·
I have the most shallow but irritating indictment against PHP. I cannot, and probably will never get past the stupid `->` syntax. Not only are those keys not n
by adamtaylor_13 2y ago
I have the most shallow but irritating indictment against PHP. I cannot, and probably will never get past the stupid `->` syntax.
Not only are those keys not nearly as accessible as the humble `.` but there’s literally 100% more keys to type than a simple period.
I know it’s pedantic and stupid but I hate it.
- j45 2y agoSyntax preferences are just that. Sometimes syntax disdain can become prejudice towards the users of that language if left unchecked. I try to remind myself that most customers or end users don’t see or care.
- spiderfarmer 2y agoFortune 500 clients will scold you when they find out your product uses the wrong object operator.
- j45 2y agoHaha, that made me laugh out loud and it was most welcome. Double scoldings for building a vast temple of a stack to ones own veneration.
- VWWHFSfQ 2y agoThey're different operators. . is the string concatenation operator.
- wongarsu 2y agoAnd using a string concatenation operator that's distinct from the addition operator is one of PHP's best design choices. Naively everything passed to your script are strings, `"1"+1` evaluating to 11 instead of 2 would lead to so much wasted time.
- shagie 2y agoThat was a design choice copied from perl. The perl design choice can be seen in https://perlmaven.com/what-are-string-and-numeric-contexts https://perlmaven.com/what-are-string-and-numeric-contexts https://perldoc.perl.org/perlop#Additive-Operators https://perldoc.perl.org/perlop#Additive-Operators Though php doesn't have the numeric vs string contexts (it just is) which can change how perl behaves. --- There is a bug in php with the lack of string vs numeric contexts can be seen in https://ideone.com/UntiCW https://ideone.com/UntiCW where the lack of a numericy vs stringy data difference creates an interesting bug when trying to replicate the magic of perl's ++ auto-increment on strings ( https://perldoc.perl.org/perlop#Auto-increment-and-Auto-decrement https://perldoc.perl.org/perlop#Auto-increment-and-Auto-decr... ) This doesn't exist in perl since "3d7" is a numericy value and "3d7"++ becomes "4". The "d9"++ becoming "e0" only works if it's a stringy value. > The auto-increment operator has a little extra builtin magic to it. If you increment a variable that is numeric, or that has ever been used in a numeric context, you get a normal increment. If, however, the variable has been used in only string contexts since it was set, and has a value that is not the empty string and matches the pattern /^[a-zA-Z][0-9]\z/, the increment is done as a string, preserving each character within its range, with carry ...
- dylan604 2y agoif you wanted a PHP object to use dot notation, then you'd have to change the string concat operator to something else. So you mention the "+" symbol, but then you confuse addition with concat and then you've just introduced JS issues into PHP.
- adamtaylor_13 2y agoI’ve used JS my entire professional career and never once had to worry about whether I was performing string concatenation or addition. Besides, you probably access objects 10x more often than you concatenate strings manually. Way more often that I’m doing some sort of string split, filter, join.
- jt2190 2y ago> I’ve used JS my entire professional career… Doesn’t JS have => ? Isn’t that -> plus an extra key press? (Shift?)
- adamtaylor_13 2y agoYes, used much less than object property access.
- dylan604 2y agocome on, really? you've never done a = '1'; b = '2'; let sum = a + b so that sum is '12'? it happens all the time when reading from the DOM and you fail to parseInt/parseFloat.
- pier25 2y agoIt's petty but I totally agree.
- kstrauser 2y agoFor me, it’s using backslash as a namespace operator. You know how in Rust you’d write somepackage::foo? In PHP that’s somepackage\foo. I can’t stand looking at it. It sets my teeth on edge. There’s nothing objectively wrong it, but subconsciously it screams to me that whoever came up with this was a font of odd decision making. What’s next, & for multiply? (I’m sure they had valid reasons for picking \. I don’t think they’re dumb. But seriously, I’d rather use an emoji or something instead. At least then code wouldn’t look like it’s full of escape sequences.)