PHP is inconsistent: strpos, str_rot13

Continuing on our path to a better article to show PHP in a true light. Let’s talk about consistency in PHP. Eevee said this.

A language must be consistent. Similar things should look similar, different things different. Knowing part of the language should aid in learning and understanding the rest.

And then makes this statement:

PHP is inconsistent: strpos, str_rot13

I think I know the issue here. It’s probably the naming conventions of the two functions. strpos should be str_pos. Correct me if I am wrong.

Is that really such a problem with consistency?

Also on consistency. There are the results we get back from forms of code. Does PHP handle itself inconsistently, if you follow the laid down rules of the language? In other words, if you do the same thing twice, will you get two different results ever? I don’t think so. But, I’ll leave the answer to you, the PHP Sitepoint community.

Where or how or why is PHP inconsistent?

Scott

because in the early days it borrowed a lot of things from a variety of different languages.

On the subject of naming conventions, someone pointed out this RFC to me.

https://wiki.php.net/rfc/consistent_function_names

That would be the answer to the naming convention issues, wouldn’t it?

Scott

Agreed. So, for someone coming from one of those languages, PHP could seem inconsistent. However, it’s a matter of knowledge inconsistency with that person and not language inconsistency. Someone with no clue about any other language wouldn’t see this inconsistency at all. Right?

Edit: Or is there a usage issue with this too? Is this the core to the mixed box of funky tools?

Scott

I agree. If all the inconsistently named functions are given consistently named aliases then the consistent naming will be able to be used in new code without breaking any old code.

Does anyone know how to find the conversation around the RFC I mentioned above? Is there any attention being put on it? Is getting it done a goal or will it be?

Scott

I’d like to also make a note that if PHP was really so badly inconsistent, it wouldn’t be useful in terms of expressiveness. I found an interesting article on languages, which takes a sort of different look at them. PHP doesn’t come out last for sure. And certainly, it doesn’t come out first. We know it won’t. However, it is in the strong “middle field”. So, it is expressive enough and obviously consistent enough.

Programming languages ranked by expressiveness

That article is also 3 years old!

Scott

the scalar objects mentioned in the RFC somehow remind me of JavaScript … (as do the already existing closures). so it’s just a matter of time until we get the spread operator, too?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.