1. 41
  1.  

  2. 13

    Nice to read some positive stuff about a maligned language.

    1. 2

      Is Facebook still using its own version of PHP?

      1. 3

        Yes, they are still using Hack.

      2. 1

        As I understand it, “maligned” is usually intended as “spreading bullshit/FUD” (Merriam-Webster: “spoken about in an injurious way : harshly or unfairly criticized”). Is this what you intended? Or did you merely intend “criticized”?

        1. 4

          If there’s one programming language since Basic that’s literally been maligned, it’s PHP. So yes, I meant it in the M-W sense. We see an example of it in this very thread!

          Edit note that I am not doing the maligning. I’m neutral on PHP

          1. 9

            While I’m sure a lot of the criticism pointed towards PHP is indeed unfair, a lot of it is totally valid. PHP has a lot of extremely strange warts that just don’t really make sense. My favourite example is that the ternary operator (i.e. cond ? true_expr : false_expr) associates left to right instead of right to left (see example four https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary).
            This is purely a mistake in the grammar and has been left in for YEARS due to lots of code already being written and relying on this.

            This is just one issue out of a whole lot. There are a lot of benefits to using PHP I’m sure, but it wasn’t a masterclass in programming language design by any stretch.

            1. 3

              This is purely a mistake in the grammar and has been left in for YEARS due to lots of code already being written and relying on this.

              Indeed; this has been an explicit design goal of PHP (maintain backwards compatibility, even if it means leaving warts in place). This is part of what has contributed to PHP’s runaway success: you can run PHP4 code on PHP7 with minimal-if-any changes. I know, because I do.

              Adam Harvey’s talk What PHP learned from Python made this explicit for me, but honestly it makes sense. It turns out most of these warts are minimally invasive; in general I find reliance on operator associativity or priority makes for hard-to-read code anyway. Focus has instead been on making the language fast and powerful, with optional additions to improve large codebases (like types).

              I may be biased, because the first language I learned was PHP (more or less), but I keep coming back to it fifteen years later. It’s a fast-to-develop, batteries-included, does-what-you want language. It’s very similar to python in many ways.

              1. 6

                There is a loooot of programming languages taking back ward compatibility as a must (out of my head java, python 2, python 3, C, C++, javascript). None of them has wart as PHP. PHP was simply not designed at all.

              2. 3

                This will actually be addressed in the next versions of PHP: https://wiki.php.net/rfc/ternary_associativity

                1. 1

                  In 15+ years of php I’ve never nested ternary calls … Thats just ugly :D

                  I do typically use 1 ternary call to return nicely from a function or method …

                  return (count($f)) ? $f : $bar;
                  
                  1. 1

                    In PHP an empty array returns FALSE, so you can shorten that to:

                    return $f ? $f : $bar;
                    

                    Furthermore, that can be shortened to:

                    return $f ?: $bar;
                    
            2. -1

              dude, seriously?

          2. 11

            Apologies for the excessively cynical response, but I was expecting to get to the part of the article where it would talk about how the security bugs in the comparison operators have been fixed, the C-based APIs are being tidied up into modern libraries, etc. Instead it’s stuff about performance and new features/frameworks.

            A badly-designed pile of crap that’s fast and has some interesting new gizmos is still, at core, a badly-designed pile of crap. And I don’t see anything being done about that.

            1. 6

              PHP gets a lot of crap from the people I currently work with, but I really never had a problem with it. I’m more of a sysadmin type, not a strong coder. I don’t pick up languages easily but I always found PHP to be pretty straightforward to work with. There was an MVC framework for PHP called CodeIgniter that was excellent… even someone with my limited ability was able to set up a functional CRUD app within about 30 minutes of sitting down with it.

              I’m convinced that 99% of PHPs poor rep comes from the sheer amount of bad code written with it, simply because it lowered the barrier to web programming so dramatically. Believe me, I’ve had my share of seeing (and supporting) crappy PHP. But I’ve also seen some very elegant frameworks and libraries written with it.

              1. 3

                Personally, I dislike the weird syntactical things and inconsistencies more than anything. Concat with a .? Instance calls with instance->method()? Static methods with Class::method()? camelCase() or snake_case() in the standard library. explode() and implode() instead of split() and join()? And what is up with the use Something\SomethingElse syntax? I just don’t get it.

                1. 3

                  The . operator for concatenation and the -> method calls are Perl legacy and Perl got that from C/C++.

                  1. 1

                    I know where they come from, but it doesn’t make it any better

                    1. 1

                      It doesn’t matter, it honestly doesn’t. I always see a ton of bike shedding among holier-than-thou developers against PHP and it always gives me a bad impression of them. It’s like watching people making fun of fat people at a gym.

                      1. 2

                        For one, that analogy makes no sense at all. Having an opinion on the syntax (saying I don’t like them) doesn’t mean you have to agree with me. It also has nothing to do with making fun of anyone or anything. It’s a personal preference.

                        1. 1

                          Looks like I replied to the wrong thread. We all have our preferences and that’s fine. What I was referring to in my comment is the disgusting way the developer community dog-piles on a language largely out of personal preference; I have personally witnessed it alienate good people and I have had enough.

                  2. 3

                    I don’t mind the things when PHP is inconsistent with other languages. I hate when it’s inconsistent with itself. Why array_map, count, and strlen? Why is stdClass spelled like that, when DateTime is spelled like that?

                    1. 1

                      That’s more of what I was getting at in the camelCase vs snake_case thing. It really makes no sense, there’s no rhyme or reason about why things are the way they are. I would think at some point, they’d look at their standard library and say “let’s actually put the standard in this.” It would be backwards incompatible, sure, but they could alias and deprecate for a few versions to make it easier on slow pokes. It’s just disappointing that it’s still a cluster.

                      I built my NHL94 stat tracking site with PHP because I had buddies who said they’d help and it’s all they knew (spoiler: they didn’t help), but that was the last major thing I did with it (2013). I pretty much refuse to use it for anything if I have a choice in the matter. There are langs that do everything it does and more that are put together better.

                2. 6

                  PHP is still not a good language, but that’s not what I want to point out. Instead, I want to talk about the trappings of a good language, what programming languages should do, and how people can talk past each other. But I will have to talk about PHP’s badness to do this.

                  Disclaimer: Eevee is among my peers.

                  First, what is it that makes PHP valuable? Brent lists five tenets: active core development, performance, active ecosystem development, new features, and tooling. Eevee also lists five tenets: predictability, consistency, concision, reliability, and debuggability. Brent derives value from PHP by using PHP to solve problems for clients; PHP is a tool. However, Eevee considers PHP as an expressive medium, similar to natural languages or bytestrings, and asks how we might improve our ability to understand utterances of PHP.

                  Each of those tenets is manifest in other listings of practical PHP problems, like PHP Sadness, which is meant to be more of an effective bug list. Some 35% of these problems are no longer problems, which is to the credit of the PHP core development team. However, these problems were not fixed evenly. The listing for “Outright Bugs” has been cut in half, but “Inconsistency” and “Misleading/Confusing Topics” are barely touched, and “Useless Error Reporting” is totally unchanged. I find it interesting that Brent mentions error-handling only once, in passing, in the context of static analysis tools. How does Brent think about errors? How do they debug their PHP code?

                  I found this paragraph to be a deep insight into how Brent views the language-as-medium ideals:

                  Spoiler: some things still suck today, just like almost every programming language has its quirks. Many core functions still have their inconsistent method signatures, there are still confusing configuration settings, there are still many developers out there writing crappy code — because they have to, or because they don’t know better.

                  Which languages don’t have quirks? More importantly, blame has been assigned to “crappy code”; it comes from developers who “don’t know better” or “have to”. This is a harsh crab-statement. We should not have to blame each other for the existence of bad code; we should be able to move past the emotional crisis of bad code’s existence and work towards better code. PHP is difficult to write correctly and I’ll quote Eevee here:

                  Do not tell me that “good developers can write good code in any language”, or bad developers blah blah. That doesn’t mean anything. A good carpenter can drive in a nail with either a rock or a hammer, but how many carpenters do you see bashing stuff with rocks? Part of what makes a good developer is the ability to choose the tools that work best.

                  Is PHP a good tool? Here Eevee directly tackles Brent’s argument in advance by questioning whether we can indeed compare languages by features or by expressive power, and then asking whether those comparisons could be used to selectively prefer some languages over others based on the desire to not have to cope with certain infelicities.

                  As an anecdote, I had to fix a fence with nails, and then with screws; first with a hammer, and then with a drill. Tool selection matters.

                  Eevee continues:

                  Do not tell me that it’s the developer’s responsibility to memorize a thousand strange exceptions and surprising behaviors. Yes, this is necessary in any system, because computers suck. That doesn’t mean there’s no upper limit for how much zaniness is acceptable in a system. PHP is nothing but exceptions, and it is not okay when wrestling the language takes more effort than actually writing your program. My tools should not create net positive work for me to do.

                  Computers will be alien to us for a long time. An implicit goal of creating a programming language is to tame that alien nature and allow for the creation of our own personal ontologies and models. Further, we should be careful to avoid the memes of business; we do not need to be constantly busy in order to be good programmers.

                  There are several programming language design anti-patterns manifest in PHP. Eevee points out each of them, while Brent ignores them. I want to highlight the patterns that I find interestingly bad. Quoting Eevee:

                  PHP is built to keep chugging along at all costs. When faced with either doing something nonsensical or aborting with an error, it will do something nonsensical. Anything is better than nothing.

                  This is Keep It Working, an infamous anti-pattern. While it usually manifests in big systems, PHP has this pattern built into every invocation of its runtime.

                  The language is full of global and implicit state. mbstring uses a global character set. func_get_arg and friends look like regular functions, but operate on the currently-executing function. Error/exception handling have global defaults. register_tick_function sets a global function to run every tick—what?!

                  Another anti-pattern, Ambient Authority. Even worse, there is a pattern that we are still trying to understand, for which Time Protection may be the only cure. I hope that we come to call this pattern “Spectre”, as it is not a bad name, but “Time Unsafety” may be the more pragmatic choice.

                  Your program will not blow up; it will, instead, do the wrong thing with no warning, unless you remember to include the right boilerplate around every place you use strpos and certain other functions.

                  I don’t know the name of this anti-pattern! I know terms from other fields for it, like “insignificant ritual”, and it’s very close to what’s called “cargo-cult programming”, but “unpleasant design” might be the closest. PHP demands a token ritual be conducted upon every strpos, every array_search, every json_decode, or else invisible incorrectness will seep into the supplicant’s program.

                  PS: In talking about PHP, it is difficult to not see it as an embarrassment to our trade precisely because it exemplifies that which is disappointing about programming. There is a half-hour philosophy video on the topic, using video-game culture as a context for the embarrassment of video-game-themed comics.

                  Last word goes to Eevee:

                  PHP is an embarrassment, a blight upon my craft. It’s so broken, but so lauded by every empowered amateur who’s yet to learn anything else, as to be maddening. It has paltry few redeeming qualities and I would prefer to forget it exists at all.

                  But I’ve got to get this out of my system.

                  1. 5

                    I like PHP. It is very mature, well understood, and easy to deploy. One of the things I like a lot is that is is possible to write PHP code that works on PHP 5.4 (CentOS) up to PHP 7.3 with minimal difficulty. Add a few polyfills for the old version and you are good to go, e.g. libsodium works on PHP 5.4.

                    Even on old systems you can get decent performance with PHP, e.g. on CentOS 7 with some tweaks. Using the tools mentioned, especially the static code analysis tools, it is possible to write high quality software.

                    An additional benefit is that most webshit hipster are located elsewhere, so you can just focus and get stuff done :)

                    1. 1

                      Missing Semantic Merge in the tooling section:

                      http://blog.semanticmerge.com/2019/02/semanticmerge-now-supports-php.html

                      1. 1

                        I recently had an opportunity to do a limited, small-ish implementation in PHP at my current job. I took it, having heard a bit about how PHP has improved over the years. I did everything I could to adopt current best practices, and spent hours upon hours digging out the new ways to do things.

                        It’s better than 10 years ago, sure. But that’s not a very high bar. In the end, I was disappointed by the lack of progress and while it was a valuable experience, I would not do anything new in PHP now.

                        1. -2

                          PHP’s biggest problem is the user base it attracted, and I think that’s non-fixable:

                          • Especially in the beginning of a language, people write libraries/ecosystem/tooling largely for themselves.
                          • This means that they are mostly attracting like-minded people.
                          • So if you have a language that starts out with people doing low-quality work, that’s going to be the core audience of the language going forward.

                          This is pretty much the reason why I have some blanket bans on using software purely based on the language it’s written in, which includes PHP, JavaScript, Go, Ruby, and (usually) Python.

                          1. 16

                            Exactly! That’s why I ban Haskell, Rust, and Scala from production.

                            1. 1

                              I don’t get your comment

                              1. 5

                                I wanted to point out the absurdity of parent’s comment to have blanket bans based on a language.

                                We’re engineers and our job is to solve problems using available building blocks, under given constraints and requirements. If there is a solution that addresses all the requirements we have, banning it solely on the language grounds is ludicrous as we would either end up with a worse solution or spend precious time re-implementing existing solutions, which is just a waste (and introduces bugs that might have been addressed in existing solution).

                                tl;dr There are great systems written in every language, as there are horrible systems written in every language.

                                However, there is some half truth in what I wrote in the previous comment – no matter how lovable they are, some language ecosystems are not ready for production. Not because of the languages itself, but the tooling that comes (or doesn’t) with them. I don’t doubt they will mature, but all these processes take time.

                                1. 1

                                  Yeah I agree that comment was ridiculous

                                2. -1

                                  Reword: Haskell, Rust, and Scala’s biggest problems is the user base they attract.

                                  Myself, I’m waiting for Rust and their user base to mature.

                                  1. 2

                                    How is that the case though? Seriously, I wouldn’t know for Scala, but Haskell and Rust communities seem to be wonderful, communicative, and on the edge of best coding practices and theory. Granted I don’t know much about the PHP userbase but you can hardly say it’s a language that attracts people interested in good languages.

                                    1. 1

                                      Scala’s biggest problem is often not the code quality (except the standard lib), but how contributors are treated, which also has a direct influence on which people stay and which leave the language.

                                3. 1

                                  Absolutely!

                                  Different people value different things, and I’m all for people coming up with their own quality requirements and acting upon them, instead of accepting whatever they are being fed.

                                4. 7

                                  do you have data to back any of this up? I’m very skeptical of any argument that pushes blame for issues with a language onto engineers. also:

                                  This is pretty much the reason why I have some blanket bans on using software purely based on the language it’s written in, which includes PHP, JavaScript, Go, Ruby, and (usually) Python.

                                  that’s every popular language. are you saying all programmers except for those programming in the languages you happen to be a fan of do low quality work? that smacks of tech hipster-ism.

                                  1. 2

                                    Still leaves Java and C#. That’s the opposite of hipster!

                                    1. 2

                                      d’oh, great point! but now I’m wondering what would cause someone to see the JS, Go, Ruby and Python ecosystems to be lacking in quality when compared to Java and C#…

                                    2. 1

                                      My decision is based on having read lots of code, and while I always try to keep an open mind, in some ecosystems things are so consistently poor that hoping to find good code would be a waste of open-mindedness.

                                      I’m not saying that other languages have no issues, but in most other languages I’m only banning specific authors, because the language has some other good developers.

                                    3. 3

                                      PHP and JavaScript ok - but Go Ruby and Python? whats left C?

                                      1. 5

                                        perl, baby

                                      2. 2

                                        I actually literally got fired once for this kind of philosophical blanket banning. Every rose has its thorns, but some thorns have roses.