Hacker News new | past | comments | ask | show | jobs | submit login

Are you saying that developing an API in PHP is insane?



No, I'm saying that the stuff built into PHP is weird and inconsistent. I should change it to "sane default library" from "sane API".

My current favorite example of this (ignoring the naming scheme for string functions entirely) is that in_array and strpos are functions that perform (almost) the same task, on two different types. They take their arguments in the opposite order. strpos($haystack, $needle) vs in_array($needle, $haystack).


> No, I'm saying that the stuff built into PHP is weird and inconsistent.

You never asked yourself WHY. See, that's the important question, isn't it. WHY.

I'll tell you WHY. Because two different dudes implemented it. At different times. Probably, from different continents. They didn't notice it at the time.

But, eventually, someone noticed it. And then they did something really crazy. They didn't fix it. Because that would break the software already using those functions.

It's impossible to write a perfect language from the start. Hell, it's not possible to write a good language from the start. Things that you didn't see crop up and you have to add functionality. And sometimes, the way you added it isn't right ... at that point, you have two choices.

You can fuck your existing user-base up the ass, refactor your code, change the interface, and do it "right" ... or you can do everything you can to mitigate the damage, while keeping the interface the same.

I can pull up software I wrote 10 years ago and it'll still work. Perfectly. You can only say that about languages that do it right.

And guess what? Those languages, they always have lots of warts. Because someone made the hard choice and kept something that's ugly, instead of fucking over a shitload of people to make it pretty.

I'll take function over form any day.


You're ascribing things to me that aren't present in the text.

I had a pretty good idea why that's how it is. I even completely agree with not changing it now. Backwards compatibility is important, no argument there.

That doesn't change that it's the sort of niggling annoyance that drives people to dislike the language.


But it can (and should be) fixed. It's not that difficult.

Choose a convention (ie: always $haystack before $needle), find the methods that don't conform, and print deprecation messages for them, add their replacements.

Then in the next major release, remove the deprecated methods. Hell, you could even put the deprecations in in a module so that those who can't/won't update their code won't have to be left behind.

It may be impossible to write a good language from the start, but that shouldn't deter from fixing those mistakes.


The problem is not that "two different dudes implemented it. At different times. Probably, from different continents. They didn't notice it at the time". Is is that it was allowed to be added to the core library without it being questioned and fixed before it was too late to fix for compatibility reasons. That is the ultimate problem. I would rather a language or framework or library move slowly and correctly than add things haphazardly.


You're not getting what I'm saying. Even if you are super careful, mistakes will be made. What's important is how you deal will them once they're there.

PHP chooses to be ugly, over shafting its user-base by deprecating shit left and right. I like that. It tells me I can use it in a production setting.


I do understand what you are saying though for the same reason, it makes me not want to use PHP in a production setting. The fact that the core developers are willing to add things without thinking them through forcing the users to deal with problems that can't be fixed so as to not break existing sites concerns me.


The thing is, these functions were added a long time ago when the language and the project itself was in it's infancy. It's purpose and audience was different. I doubt anyone developing at the time expected it to last this long and be used by this many people. The goal was to put in as much functionality as possible to be useful. It was web scripting for C programmers.

The problem with a language that moves slowly is that if there's an opportunity, it might just miss it. I was working in PHP in the early days and every release brought features you wanted to use yesterday. Perhaps if PHP didn't have the huge rate of change it did then maybe it would have never caught on. Python is several years older than PHP and yet it didn't come to web until long after.


If the inconsistencies really bother you, write:

function my_in_array($haystack, $needle) { return in_array($needle, $haystack); }

or whatever, and be done with it...


So now there are some functions you have to prefix with my_, and others you don't?

You're not really helping your cause here.




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

Search: