Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, it DOES. Syntax matters. Small improvements in a few places add up.

For example, let's say you've got a string like 4|1|45|343|22. You want to return a string with the last three numbers, but seperated by a comma and a space.

In PHP:

    $arr = explode('|',$str);
    $last_three = array_slice($arr, -3);
    return implode(", ",$last_three);
In Python:

    return ', '.join(str.split('|')[-3:])
Small conciseness improvements snowball as the codebase gets larger. In fact, being unable to chain functions in PHP is actually my biggest beef with the language. If you could do

    return implode(', ',array_slice(explode('|',$str),-3)); 
that'd be a lot less annoying. Still not as good as the python, but a lot closer.


> In fact, being unable to chain functions in PHP is actually my biggest beef with the language.

That's just a lie or at least a horrible misconception, depending on your intentions. Furthermore, the example line you used to illustrate this entirely made-up inability of PHP does in fact work. You can do

  return implode(', ',array_slice(explode('|',$str),-3)); 
it's valid code and it works just as expected!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: