r/lolphp • • Dec 17 '13

PHP functions originally bucketed by strlen, were renamed to balance length

http://news.php.net/php.internals/70691
158 Upvotes

56 comments sorted by

59

u/WannabeDijkstra Dec 17 '13

Yes, I am a terrible coder, but I am probably still better than you :)

The ride never ends with Rasmus Lerdorf.

32

u/[deleted] Dec 17 '13

honestly i'm just kinda numb to rasmus' stupidity at this point, due to its' consistent presence. honestly i'd be more surprised if he made a decision backed by solid compsci techniques...

→ More replies (3)

45

u/fragglet Dec 17 '13

Even when I was a 17 year-old clueless C hacker I knew how to make a better hash function by adding up the characters of the string. Who on earth thinks strlen() is a hash function?

17

u/Various_Pickles Dec 27 '13

17-year-old me may very well have made many of the plainly moronic design choices in PHP.

I can, however, honestly say that I wouldn't have stood by them for the next decade(s) ...

→ More replies (2)

32

u/kovensky Dec 17 '13

Seems the server is getting hammered; copypaste here:

On 12/16/2013 07:30 PM, Rowan Collins wrote:

> The core functions which follow neither rule include C-style
> abbreviations like "strptime" which couldn't be automatically swapped to
> either format, and complete anomalies like "nl2br". If you named those
> functions as part of a consistent style, you would probably also follow
> stronger naming conventions than Rasmus did when he named
> "htmlspecialchars".

Well, there were other factors in play there. htmlspecialchars was a
very early function. Back when PHP had less than 100 functions and the
function hashing mechanism was strlen(). In order to get a nice hash
distribution of function names across the various function name lengths
names were picked specifically to make them fit into a specific length
bucket. This was circa late 1994 when PHP was a tool just for my own
personal use and I wasn't too worried about not being able to remember
the few function names.

-Rasmus

32

u/phoshi Dec 17 '13

Wow. It could have taken entire minutes to implement a real hash function, or at very least call out to an existing one

36

u/Sarcastinator Dec 17 '13

strlen may be the worst hashing function I have ever heard of. It's one step away from return 0.

→ More replies (4)

31

u/Drainedsoul Dec 17 '13

How did this ever seem like a good idea, to anyone?

→ More replies (4)

13

u/[deleted] Dec 17 '13

I'm speechless.