5 ms·
Why doesn't PHP remove the horrid $ symbol for variables and the -> symbol for calling methods? I think those alone would do a lot more for its perception and
by lordofgibbons 1y ago
Why doesn't PHP remove the horrid $ symbol for variables and the -> symbol for calling methods? I think those alone would do a lot more for its perception and adoption than adding the pipe operator.
- phatskat 1y agoI actually don’t mind them, and I’ve been out of daily PHP work for a few years now. When I see people denote internal variables with _ or elements with $ in JS, it rubs me the wrong way, but in PHP the $ is kind of nice. I also prefer the look of ->, it’s _cool_
- kijin 1y agoOther languages have all sorts of oversized arrows, like ==> and >>>. -> in PHP and C++ looks clean by comparison. I'll never forgive them for the brain fart they made of the namespace separator, though.
- LeonM 1y ago> I'll never forgive them for the brain fart they made of the namespace separator, though. You mean the backslash? What's wrong with that?
- account42 1y agoTo someone not already familiar with PHP it looks like you are trying to escape something.
- kijin 1y agoThe backslash is universally reserved as an escape character. It was decided almost 20 years ago so I'm totally used to it and there's no point arguing about it anymore. But the decision to reuse the backslash as a namespace separator still causes inconvenience from time to time. For example, when you write PSR-4 configuration in composer.json, all the backslashes need to be doubled, including (and especially!) the trailing backslash.
- esskay 1y agoWhat would the alternative for a namespace separator be? The backslashes work well with PSR-4 to give a logical visual of the expected directory structure.
- account42 1y agoSince PHP takes a lot of syntax from C-like languages, the C++ namespace separator :: would be the obvious choice. Not sure if this conflicted with something in PHP though.
- jimktrains2 1y agohttps://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php https://www.php.net/manual/en/language.oop5.paamayim-nekudot... scope resolution operator
- ahofmann 1y agoI honestly don't understand this. The syntax is one of the most boring parts of a programming language. It is solved by the IDE (and now LLMs). I don't care about syntax, I care about what I can build. Since the beginning of time people argue about things like tabs vs. spaces, or the dollar sign and I honestly don't understand why that is. It just doesn't matter. Just to be clear: consistency does very much matter. The mental load of reading totally different styles of code is awful and a waste of energy.
- Timwi 1y agoReadability (and hence, maintainability) is definitely a factor in decisions like this. In the particular case of the pipe operator though, the article does mention something it lets you do that you couldn't do before: in a context where only an expression is allowed (such as match), you can now do things that previously would not have worked because it would have required temporary variables.
- throw_m239339 1y ago> Why doesn't PHP remove the horrid $ symbol for variables and the -> symbol for calling methods? I think those alone would do a lot more for its perception and adoption than adding the pipe operator. Because it simply can't do that in a retro-compatible way. -> isn't so bad, C/C++ uses that as well. as for $ I guess it came from Perl. The point is already used for string concatenation, where other languages would overload the + operator.
- jeroenhd 1y agoSame reason C doesn't introduce classes and C++ doesn't remove pointers: it's a) part of the core language and b) extremely inconsequential for any serious developer. I actually like the clarity these dollar signs add in a code base. Makes it easier to recognise (dynamic) functions, and makes it harder to accidentally shadow methods. Other languages will let you do `const Math = {}` and nuke the entire math library, or write stuff like `int fopen = 0;` to make the fopen method call inaccessible in that scope. With PHP, you don't need to restrict your variable name to "something that hopefully won't conflict with an obscure method". The -> is a leftover from an older programming language that I'd rather have replaced by a ., but not at the cost of breaking existing code (which it surely would).
- asddubs 1y agoI do also appreciate that php has an explicit string concat operator rather than overloading +. Though of course it could just use another symbol for that to get rid of -> if we're talking about time travel. As it stands, you can't really do $obj.method(), because method() could be a function returning a string as well, so it's ambiguous
- account42 1y ago> The -> is a leftover from an older programming language that I'd rather have replaced by a ., but not at the cost of breaking existing code (which it surely would). Isn't it because . was already used for string concatenation in PHP. I mean the -> syntax wasn't invented by PHP but it didn't just inherit it without thought either.
- int_19h 1y agoIndeed. And the reason why PHP used . for string concatenation is because Perl did.
- nolok 1y agoBecause back compat' is a very strong feature of the language, same reason "match" was created instead of replacing switch. As a result, taking a php 5.2 script and moving it up to 8.5 is super easy, and taking a PHP 4 one is barely harder only longer (since it probably uses the horrors that were register_globals and co). Ultimately, I prefer this than a fragmented ecosystem impossible to resolve.
- guskel 1y agoThe $ symbol gave me RSI as a dev just starting out. I will never forgive PHP for that. Such an unergonomic syntax.
- pkkm 1y agoPHP has its significant flaws, but superficial syntactic differences aren't among them. In my experience, it takes two weeks to get used to pretty much any syntax.