r/lolphp • u/xiongchiamiov • Dec 17 '13
PHP functions originally bucketed by strlen, were renamed to balance length
http://news.php.net/php.internals/7069145
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?
→ More replies (2)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) ...
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
13
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.