Hacker News new | ask | show | jobs
by mikey_p 5369 days ago
I won't argue that PHP is getting long in the tooth, has a somewhat unclear future, and some of the standard lib is hella inconsistent, but these points:

then what PHP is lacking is lambdas and method chaining.

Does the author know anything about PHP at all? As far as I can tell method chaining has been available as long as PHP supported OOP and Anonymous functions have been supported for several years since PHP 5.3 was released.

This makes it really hard to take the author and the article seriously.

1 comments

>>Does the author know anything about PHP at all?

The author doesn't know about any other languages either, it seems.

I stopped reading when he argued that PHP's assocative arrays was an advantage; hashes/dictionaries are in all the scripting languages. (Afaik, they come from AWK by the way of Perl, anyway -- they were created many years before PHP existed.)

When I read

>> the critical thing Perl was lacking was PHP's wonderfully flexible "associative arrays"

I grabbed my copy of "Learning Perl" from 1997. Chapter 5's topic? Hashes.

Perl hashes don't preserve order. PHP's almost always do. i.e., the order you insert keys is the order in which you will receive them back when you iterate over the array. It's similar to a LinkedHashMap in Java.

CS types might recoil at the mixture of behaviors that are baked into PHP's workhorse data structure, but most of them turn out to be quite useful. (And it makes it easier for the beginner programmer to decide what data structure to use: you have keyed data? a list of data? a set of values? doesn't matter, just use an array!)

Perl hashes don't preserve order. PHP's almost always do.

This is the point at which serious students of language design point out that, if you look at it from a certain angle, PHP doesn't have arrays built into the language. As it turns out, treating two distinctly different data structures with different semantics and performance characteristics as the same thing multiplies edge cases and bugs.

There is CPAN for that. (iirc, this is solved with a module in the Perl Cookbook. I don't have that book where I am writing this.)

Edit: For a beginner that wants a Visual Basic for web, sure. By now I have different needs, to enjoy using my tools. (And for the record, if I need to keep order of a hash/dict/etc in some language, I generally use a "traditional" array in addition. That is probably too complex for a beginner? :-) )

Edit 2: I'm not dumping on PHP, it is a useful tool for many people. I just wish the development of the language had been handled a bit more carefully.

Exactly, it's not a native part of the language, which reinforces my point that the beginner doesn't need to think as much about data structures with PHP. The built-in array() usually can handle the task well enough. They never are left muttering "this would be perfect for a linked hashmap but where is my drat PHP cookbook?"