Live data from Hacker News

Why Developers Hate PHP

jesuisundev.com

81–90 of 114 posts

Re: Why Developers Hate PHP

#82
post #28

There was a tech talk I saw on Youtube a few years ago that I really liked that argued that Facebook succeeded because of PHP, not despite it. IIRC, the main argument was that despite its flaws, PHP has one killer feature, which is that it lets you have really tight iteration loops for web development. This made developing in PHP extremely productive. I searched around for the video, but couldn't find it.

The type of developers FB wanted were already using PHP and that made it good fit

Re: Why Developers Hate PHP

#83

https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ is a classic of this genre.

pick a random language, ruby, python, javascript etc etc and you'll find similar rants/complaints. Yet I think right now it's cool to shoot on PHP therefore everyone is more vocal

> I think right now it's cool to shoot on PHP

That article is from 2012. If a "fad" lasts 7 years, is it still a fad?

Re: Why Developers Hate PHP

#84
Did anyone here start learning PHP in 2020? How were you introduced to PHP? Are there any good resources to start with?

When I was introduced to PHP everything was still in a single file, PHP, HTML, JS, CSS.

Re: Why Developers Hate PHP

#85
post #69

Earlier quoted context omitted.

Did PHP ever decide whether NULL < -1 or NULL == 0? I want to hire people who care about correctness, and insanity like that really should bother them.

null == 0 is true. null === 0 is false. false == 0 is true. false === 0 is false. null == false is true. null === false is false. null < -1 is true.

Like in JavaScript, just don't use ==. It's broken but you don't have to use it.

In C you can write i[t] instead of t[i], but don't do it.

I guess it's true for many languages. These funny features don't prevent you from writing good code, especially if you enforce some coding styles that will catch any unintended use of these features.

Blame PHP for what you can't do with it, or for things you don't like but are forced to do. For instance I like PHP but I cannot type things the way I'd like. It's getting better though.

I don't like the inconsistencies in the function names of the standard library but the functions are often straightforward and very simple to use. And, above all, the doc is good. These aspects mean I don't waste time figuring out how to do simple things because of a complex interface involving many classes, despite the inconsistencies.

I also don't like the dollar notation for variables but that's a matter of taste, nor the syntax for namespaces, nor the implicit declaration of variables (like in Python by the way).

Re: Why Developers Hate PHP

#86
post #39

Earlier quoted context omitted.

When someone gives you a long list of reasons why they hate something, why do you conclude they only hate it because it's trendy to hate it?

because this kind of rants are pointless, they are not bringing any value. Every language comes with their own inconsistencies or oddity. Most of those points raised are just added to a laundry list for its own sake, it's not something you come along every single day. You might have a WTF moment once in a while but that's something that happens with every language. I'm still not able to understand why everyone hate P…

Not every language comes with the same amount of inconsistencies and oddities.

As an illustration, compare the amount and severity of WTF moments found in Ruby vs. Javascript in this presentation: https://www.destroyallsoftware.com/talks/wat

Re: Why Developers Hate PHP

#87
post #14

Earlier quoted context omitted.

I'm using it at a fresh start up. Having used node, internal Google frameworks, python, and dart previously, I would highly recommend PHP for new projects. Laravel is what makes it worth it imo.

Laravel is pretty sweet, I recently scoped it out (been in Flask land and itching to try some Elixir/Phoenix) and it's got everything, exploring the queues now. I really like the helpers for accessing array elements through dot notation. Example: $data = [ 'more' => [ 'complex' => ['my value'] ] ]; if (array_key_exists('more', $data) && array_key_exists('complex', $data['more']) && array_key_exists(0, $data['more']['…

Arr::get($data, 'more.complex.0'); is much nicer, I agree.

I do think better languages do it better, for example in Elixir I can extract multiple elements out of an object at the same time.

  object = %{nested: ["my value"], other: "some element"}

  %{nested: [first | _], other: other} = object
first now equals "my value" and other now equals "some element".

PHP sucks because of the legacy it pulls with it that keeps it from being simple and elegant. It also fails pretty hard when you use it outside of it's niche, and a multi-purpose language > single purpose language.

Re: Why Developers Hate PHP

#88
post #72

Earlier quoted context omitted.

php > $array = [1,2,3,4]; php > var_dump(array_filter($array, function($x) { return $x %2 === 0; })); php shell code:1: array(2) { [1] => int(2) [3] => int(4) } what's the problem with array_filter then? That keys are not reindexed?

Yeah, an array essentially becomes an associative array. For example in another language I could do something like: if (!empty($filteredArray)) { print($filteredArray[0] } But in PHP I need to remember that after every array_filter, after every unset etc. I need to reindex the array, because [0] element might not be there

It was an associative array all along, PHP just hides that from you. The Array is such a quirky data structure, it takes int or string keys, but numeric string keys ("1", etc.) are silently converted to int. It's never a real array, the implementation under the hood is a hash table.

Re: Why Developers Hate PHP

#89
I haven't used PHP since 2012 so I don't know if any of the stuff that made me hate it still applies. A lot has probably changed since, but I don't know to what extent.

Surprisingly, the technical inconsistencies isn't what I hated most about it. It's rather the fact that questionable practice was rampant and largely left unchecked in its many communities. The only way to realize this is to join another community where peer review is severe enough and bullshit detection high enough that mediocrity is rarely given the opportunity to infect your practice for long and fester. A proper community is supposed to nurture you into becoming a better programmer, so that you can take those lessons and carry them with you wherever you decide to go next. By contrast, my experience with PHP over the 6 years or so that I used it was that you learn 3 things today and you'll have to unlearn 2 tomorrow. Eventually I got fed up of the cyclical learning pattern and I moved on.

Some years after my move away from it, I decided to take a look back at some of the code that I had written with PHP. I was freshly appraising the sum of my past experience. I remember thinking that the language seemed to have a crisis of identity. It was dynamically and weakly typed, but with serious Java envy and so some of the less desirable aspects of Java were basically just cargoculted in, but in a shitty incomplete way. Private, protected, public class members, what a joke. If you're a PHP programmer, did you ever ask yourself why would Python or Ruby programmers somehow be able to get by without this shit and not you? Do you know that because of the way its interpreter works there are some technical benefits for Java to have these besides the fallacious architectural "advantages" of hiding access from the programmer? Does the same thing apply to PHP? Interfaces and inheritance, without the possibility to overload methods, which can cause a lot of grief when a zealous and inexperienced library designer hasn't properly thought things through (which happened more than I'd like to remember in PHP projects). That was just at the language level, but many of the big frameworks followed suit with the Java obsession, by implementing a slew of circuitous patterns aimed at convincing programmers that they were now coding "Enterprise Style". Front Controller, Action Controller, Dispatcher, and a whole other lot straight out of pattern catalogs. When you think about it, most of those efforts were fallacious in PHP. If the problems that you were trying to solve were beyond the constraints of what PHP is typically good for, namely cms-type admin web apps, then you were probably better off with another language. On the other hand, if they applied, why bother with all the enterprisey bullcrap? But, but, but Facebook... Ah, shut up! Even Facebook had to invent a whole other language to fix that mistake. The other projects that didn't buy into this sort of architectural zeal went the other extreme, with their own experimentations and idiosyncrasies. Bastardizations of concepts that someone had seen somewhere else, but only half-understood, was common. Lots of Rails envy and no shortage of fame-driven wannabes that had failed to make a name for themselves in other communities, but somehow always found a way to shine in PHP. Ensued just more bullshit.

Anyways, that was a long time ago. I hope things have changed. I'm not sure I'd be back if they did, in hindsight what PHP has for it is one of the easiest "hello world" tutorials, but you end up paying for years the half-hour you saved to see these two words on a web page. And for what it's worth there are worse languages, but there are better ones too.

Re: Why Developers Hate PHP

#90
post #87

Earlier quoted context omitted.

Laravel is pretty sweet, I recently scoped it out (been in Flask land and itching to try some Elixir/Phoenix) and it's got everything, exploring the queues now. I really like the helpers for accessing array elements through dot notation. Example: $data = [ 'more' => [ 'complex' => ['my value'] ] ]; if (array_key_exists('more', $data) && array_key_exists('complex', $data['more']) && array_key_exists(0, $data['more']['…

Arr::get($data, 'more.complex.0'); is much nicer, I agree. I do think better languages do it better, for example in Elixir I can extract multiple elements out of an object at the same time. object = %{nested: ["my value"], other: "some element"} %{nested: [first | _], other: other} = object first now equals "my value" and other now equals "some element". PHP sucks because of the legacy it pulls with it that keeps it…

Yeah, still just checking it out, getting an auth system working with oAuth in about 15 mins via Socialite was fun. I want to test out the Lambda deployment which seems sweet. I use Serverless for that ATM with JS and Python. Elixir pattern matching is fantastic and I miss being able to call functions by arity. I don't know which deployment process I prefer, yet. They all suck.
Post reply on HN