3 ms·
> proper closures That link is laughable. Author angrily tries to persuade me (the reader) that "PHP doesn't have closures!" while essentially showcasing multi
by krick 7y ago
> proper closures
That link is laughable. Author angrily tries to persuade me (the reader) that "PHP doesn't have closures!" while essentially showcasing multiple ways to use them to do everything (and a bit more) that you could with a JS closure. It could be argued that PHP implementation of those is actually better that in JS, since you actually have a choice if you want outer scope variable to be mutable or not and default to the safe option (immutable), but allows you to use reference if you want it to be mutable. It all boils down to the definition of the word "closure", at which point I'm: okay man, PHP doesn't have closures, I won't argue. Now please show me actually important use case where it prevents you from doing FP, because I can list way better reasons why PHP closures are fucked up in my opinion than that.
> generics missing
True. I hope they'll add them eventually. It's not like PHP competition has (or had until very recently), though. And more generally with types: still not there and, furthermore, some relatively recent additions that could fix things, actually are fucked up.
> OOP, but that is terrible in PHP as well
I don't like how people currently tend to use OOP in PHP, because they try to emulate Java, and Java is awful. But actually, its OOP is pretty much fine. The only thing out of my head that actually feels like a problem in this department is absence of polymorphism. Otherwise, especially since traits were added, there isn't too much to complain.
> actually consistent standard library
A myth. Well, TBH, I was often bashing PHP for that as well (and often sardonically joke about that still), but, honestly, the more experience you have, the better you know that, sadly, every PL is fucked up in this regard. In practice, it's not a big problem though. Half of that is handled for you by the IDE, some I solved for myself by basically writing my own "underscore.js" in PHP with a consistent interface. Anyway, these are coder pet peeves, not real technical indications for or against the language (as opposed to real reasons why PHP sucks: i.e. no async/await, parallelism, lots of broken low-level stuff, etc).
> hundreds of PHP open tags
> which you can see in many popular open source PHP projects
This is a strawman. You use people that apparently are not skillful programmers and use the result of them using the language to demonstrate that the language is bad. I mean, Wordepress probably can be used as a demonstration of "success of PHP in the real word", but, personally, I would never use Wordpress, and its plugins are probably the showcase of the worst programming patterns imaginable. No professional programmer that knows what he's doing uses PHP as a template engine in 2020 except for a quick demo, and the ONLY tag he ever needs is <?php to put in the beginning of every file. So, this is not a problem for an actual programmer, who chooses PHP as a language for his project, because, surprisingly, every alternative just sucks.
> any language, that has ...
Uhm, Rust? I'm not sure I'm familiar with that language, because this "any" language you describe surely isn't Python, JS, Java, C++, Go and pretty much everything else people actually use in production. And I wouldn't use Rust for a generic backend for a generic enterprise, at least not yet.
- zelphirkalt 7y agoI agree with some of the points you made and disagree with some of the others. When a language is missing generics _and_ polymorphism, it becomes really cumbersome to implement something like a chain, to which you can add operations and then run the chain. This is only one example, that I recently tried to do and then was surprised at how bad the type system of PHP is. I could not use generics to make operations generic in their return type and also not for the chain. OK, I thought, I can just use Object then. Nope, because the other types are not subtypes of Object. So Object becomes useless as well. Also you cannot write your own super type for this, because what kind of values can that contain? Cannot use generics to express it! All the same problem again. I believe in the end I settled with only using numbers and limiting operations to math calculation. I stopped investigating further how to do it, because I felt, that already enough of my time had been wasted by PHP. At least give me one of these, Generics or Polymorphism. With inconsistent standard library, I mean for example the naming of string procedures: https://www.php.net/manual/en/function.mb-strpos.php https://www.php.net/manual/en/function.mb-strpos.php omg, really?! It simply adds more to all the issues, that give me this sensation of touching something I don't want to touch, when ever having to deal with PHP. Of course I agree, that no matter how inconsistent something is, as long as it works, you can build an interface around it, to make it more consistent. However, we were discussing PHP and not user created libraries. The type systems or at least the existing types of the standard libraries of Python and Java (Haven't used C++ much and JS is .. well, JS.) are much more usable and consistent than anything PHP has to offer in terms of standard types. This is what I am talking about: https://www.php.net/manual/en/language.types.php https://www.php.net/manual/en/language.types.php. Yes, WP plugins might be a strawman argument, but then again it is one of the biggest parts of the ecosystem of PHP, as far as I am aware. On the other hand, what you wrote sounds also like a "true scotchman" argument ;) as in: "Well, that's just those WP plugin developers. A true PHP developer would never do that." -- Which might be correct! I've yet to meet that developer though. It's probably also WP's fault, at least in parts, because of how bad the WP API is. Everything relies on mutation and global state, which you can magically get into your posts by calling a procedure which accesses that global state in the middle of your theme code, instead of making sure to pass things in. It leads people to do many bad hacks instead of fixing actual problems. Is all that shit actually thread safe? With so much global state attached, I'd not be surprised, if it has complex locking logic somewhere internally, slowing everything down, or even no such thing and simply failing in a concurrent scenario. I do agree with the practices you mentioned, using template engine, only ever needing 1 PHP tag etc. because of better ways how to structure the code. If I had to use PHP, I'd definitely do all that. But then again, why should I torture myself by using PHP, when I know how to handle more elegant languages? I'd probably look for another job, if people told me, that I have to work with PHP all day. Fixing a bug here and there, applying knowledge about how to write safer, cleaner code, is fine, occasionally. Perhaps PHP acts as a magnet for a lot of inexperienced developers, who "quickly want to do something on the web" and stick to it, because they do not yet realize how bad PHP is or the code they write in it. Then some of those graduate and realize the mistakes they made and improve upon that. However, their better work is drowned by all the shitty PHP code that's out there. Others never graduate from that level and keep producing shitty code. I agree, that other languages are also fucked up. And at least we seem to agree, that PHP is seriously fucked up too. Perhaps I would say that there are many languages, which are a little less fucked up though. I used to think, that Java's "everything is a class (or interface)" approach forced me to do OOP right, but then I realized it is not true and that patterns like the decorator pattern are needlessly verbose to express, when I saw how it Python its just a decorator. Now I dislike doing anything in Java. Java did not even have a way of passing a procedure as an argument until some time ago. One needed to create at least an extra inner anonymous class plus the corresponding interface. Looked really ugly. I then liked Python a lot. Then I also realized its shortcomings (difficult to manage correct types in big projects or even when you did not look at some code for some time, still the standard "use a class for everything" type system, although at least not as encouraged as in Java, only one expression lambdas, not so convenient way moving of code, because of whitespace sensitivity ...). I am not a Python fanboy. My tolerance for BS in programming languages has decreased over time, having seen some truly elegant and minimalistic programming languages (Scheme and the books SICP + The Little Schemer), as well as more type safe languages like Haskell or Rust and dipped my toes in "Learn you some Erlang for great good". My projects have become more abstract over time as well. I used to create useful (or me at least) tools for natural language learning with Python and GTK+3, but now I am looking at things like "How to implement a thread pool for my machine learning library?" or "How do I write a macro, that defines procedures in different ways, depending on the name of the procedure to define?". PHP or Python or Java don't even have macros. I would not even ask myself any of those questions and I would continue to learn.