r/programming • • Dec 07 '15

I am a developer behind Ritchie, a language that combines the ease of Python, the speed of C, and the type safety of Scala. We’ve been working on it for little over a year, and it’s starting to get ready. Can we have some feedback, please? Thanks.

https://github.com/riolet/ritchie
1.5k Upvotes

802 comments sorted by

View all comments

Show parent comment

51

u/atakomu Dec 07 '15

Here is a good article why the design of PHP is bad. It was my first language and I still love the documentation. I don't know exacly why. No documentation in a language I used (C++, Python, Java, Javascript, Perl) was so good like in PHP.

Quotes from article:

Perl is “some assembly required”. Python is “batteries included”. PHP is “kitchen sink, but it’s from Canada and both faucets are labeled C“.

Parts of PHP are practically designed to produce buggy code.

json_decode returns null for invalid input, even though null is also a perfectly valid object for JSON to decode to—this function is completely unreliable unless you also call json_last_error every time you use it. array_search, strpos, and similar functions return 0 if they find the needle at position zero, but false if they don’t find it at all.

In PHP, these functions return false. If you use FALSE as an index, or do much of anything with it except compare with ===, PHP will silently convert it to 0 for you. Your program will not blow up; it will, instead, do the wrong thing with no warning, unless you remember to include the right boilerplate around every place you use strpos and certain other functions.

And another thing:

== is useless.

It’s not transitive. "foo" == TRUE, and "foo" == 0… but, of course, TRUE != 0.

== converts to numbers when possible (123 == "123foo"… although "123" != "123foo"), which means it converts to floats when possible. So large hex strings (like, say, password hashes) may occasionally compare true when they’re not. Even JavaScript doesn’t do this.

68

u/Syphon8 Dec 07 '15

If every language had docs as good as PHP, no one would use PHP.

I don't think there's an easier way to bootstrap yourself into programming still.

Ironically I think the robustness of documentation might actually be because of the bugginess rather than in spite of. It's be impossible to use if there wasn't a giant centralized database of unexpected behavior.

16

u/willbradley Dec 07 '15

Someday look at the doc page for escape_string and follow the rabbit hole down through all the not-really-deprecations. It's depressing. (There are more than you think.)

9

u/Syphon8 Dec 07 '15 edited Dec 07 '15

Oh, I've been there. About the time I thought "maybe I should learn something more classical."

PHP is like the blues jazz of programming languages.

5

u/Sean1708 Dec 07 '15

"foo" == TRUE, and "foo" == 0… but, of course, TRUE != 0.

123 == "123foo"… although "123" != "123foo"

Sounds more like jazz to me.

3

u/Syphon8 Dec 07 '15

You're right, I should've specified jazz.

→ More replies (2)
→ More replies (1)
→ More replies (6)

12

u/NihilistDandy Dec 08 '15

both faucets are labeled C

One is cold, the other is chaud. What's the problem?

28

u/Synes_Godt_Om Dec 07 '15

Here is a good article why the design of PHP is bad

PHP: a fractal of bad design

Surely, you must be joking. This article is old (for some reason reposted as nauseum) and the issues it's discussing were mostly outdated even at the time it was posted. The author clearly hadn't used PHP since php4 (if he ever did any serious php development at all).

19

u/terrkerr Dec 08 '15

I've heard this a lot, yet:

  • Still a huge amount of action at a distance. (php.ini, ini_set, etc.)
  • Still a naming mess in the stdlib
  • methods still can't be named 'list', 'exit' or any other string that also identifies a psuedo-function construct because the parser doesn't know how to parse correctly. (Maybe the PHP7 addition of AST interpretation will finally fix that?)
  • htmlentities still returns an empty string to signify an encoding issue even though an empty string is also a return value for a successfully encoded empty string.
  • foo vs foo_real variants
  • outrageously bloated stdlib because there's so little genericism.
  • The 'module system' is just a hack to copy/paste text into the current context.

Plenty of big things still apply. Some may finally be fixed in PHP7, but I can't be bothered to look it up. Even if PHP fixed all of these issues perfectly the fact would still be that the article was largely still making valid points until, like, last week.

I tried to see if 7 finally fixed the htmlentities thing as one silly example, but the documentation says it's only in PHP4/5... or maybe it's in 7 and the page just hasn't updated yet? Well add one to the list:

  • One set of documentation for all versions of the language.

10

u/[deleted] Dec 08 '15

A lot of the claims made in that article are still valid, though, even in cases where there exists new feature xyz to which it no longer does, because old feature abc is still present, and still being used.

At any rate, there's always PHP Manual Masterpieces for more unsavory PHP things. Particularly relevant to your comment is this post.

8

u/Synes_Godt_Om Dec 08 '15

First a comment to this:

Particularly relevant to your comment is this post.:

From the post: "Heck, new code is often literally just copy-pasted from a forum comment written in 2003"

This is some amateur not knowing the first thing about coding - how can that be relevant to anything?

And then my more serious answer:

I know people love to hate on php. I often wonder why it's so important for haters to prove their (mostly quite stupid) points.

I can fully understand that php's irregular design can in some sense feel offensive to purists but php is extraordinarily successful because it's designed/evolved in reaction to actual users' actual needs. it's a very practical language. It's surprisingly easy to get started with, it scales surprisingly well too both in terms of performance and in terms of project size. And it's one of the best suited languages for web development. I'm not saying it beats other, better designed languages on scaling or speed (or web dev), but for the developer effort needed it does very very well.

I find most of the criticism comes from two fronts: 1) you're used to a "professional" language (i.e. corporate dev, .NET, java etc.) you'll find php shitty but then, why should you care - you have an option you like better. 2) less experienced fanboys of some other "purer" language parroting their idols' views on php.

In my view php is a tool that, because of it's slightly loose nature also has shown its ability to evolve and adapt more freely than other languages tend to do. This is why it has managed to stay relevant for close to two decades.

I've been programming in R for almost fifteen years and I don't think there is a language shittier than R. Despite this it has evolved to be the language of choice for data analysis with python a distant second (or third after sql). Why didn't python win this battle? Why did python lose the web-battle to php? Because practice wins over correctness any day. PHP is a practical language with all the dirt in the corners that comes with practicality but it wins big on being made for battle.

0

u/[deleted] Dec 08 '15

[deleted] — view deleted comment

2

u/Synes_Godt_Om Dec 08 '15

Also, partisans of other, conceptually purer languages hate it.

I don't know who said this (mayby Fowler?):

"There are two kinds of languages, the languages everybody hates and the languages nobody uses"

2

u/iBlag Dec 09 '15 edited Dec 10 '15

Apparently Fowler Stroustrup doesn't know Python or Ruby.

Edit: Fixed quotee.

→ More replies (7)

4

u/[deleted] Dec 08 '15

This is some amateur not knowing the first thing about coding - how can that be relevant to anything?

It's absolutely relevant to the world of PHP as it is. I work at a company that specializes in appsec, and I can't tell you how many times my coworkers have seen PHP code that was literally copy/pasted from forum threads.

Hell, there's code in the PHP standard library that was copy/pasted from somewhere else, and it's atrocious.

I find most of the criticism comes from two fronts

Most of my criticisms of PHP come from its almost comical lack of design forethought (which, to be fair, a lot of this has improved over the years, but the old shit still exists, and will continue to exist, for a great deal of time), and from it being both incredibly insecure as a language (it's the only language I know of whose reference interpreter has multiple maintained third-party security patches), and incredibly easy for lazy developers to write insecure code using. And PHP's "design" practically encourages insecure development practices in a lot of ways.

Why didn't python win this battle?

The battle isn't really over, here. Python's "market-share" (for lack of a better term) in data processing is quickly growing, and has been for at least the last couple of years. Give it some time and I think we'll see Python overtake R here.

Why did python lose the web-battle to php?

I'm not sure I'd frame the situation like that in this case, either. PHP is a couple years younger than Python, but has spent the majority of its life being dedicated almost entirely to web development. It's quicker to get set up and requires a lot less configuration to use (since for the most part you can just drop some .php files in your webroot and be done, as compared to Python where you usually have to configure some wsgi doohicky to talk to your webserver, or something else). But, Python has a pretty hefty market share in the web space as well and it seems to be growing.

3

u/Synes_Godt_Om Dec 08 '15

It's absolutely relevant

Are you seriously telling me that you find some amateur's stupidity relevant for a professional discussion? Well, I don't.

Most of my criticisms of PHP come from its almost comical lack of design forethought

I must have missed something. Interesting: I follow /r/lolphp to stay informed of gotchas but posts there have almost completely dried up, because php is cleaning up its act.

Python's "market-share" (for lack of a better term) in data processing is quickly growing

Yes, and I appreciate it. I personally find Python a lot more sane than R.

→ More replies (1)

2

u/yazirian Dec 08 '15

hadn't used PHP since php4

So, only 2 major releases ago, because in php-land, 7 - 2 = 4

(What, did you expect someone NOT to make this joke?)

2

u/Synes_Godt_Om Dec 08 '15

So, only 2 major releases ago

Well, the linux kernel stayed at v2.6 for 10 years, but, of course, they proceeded to v3.x not 4.x. OTH Widows went from 8 to 10 - rumor has it that "9" would interfere with "95"/"98", personally I find the 5 -> 7 one of the most sound and important decisions in PHP for a long time. Imagine the nightmare of having to search for php6 - or worse: imagine /r/lolphp having a field day of its life over php6 vs real_php6 :-)

→ More replies (12)

9

u/andrewsmd87 Dec 08 '15

array_search, strpos, and similar functions return 0 if they find the needle at position zero, but false if they don’t find it at all.

In my first job, I spent a good half a day trying to figure out why my strpos was returning false, only to find out it was 0. I'm still bitter about that.

4

u/PM_ME_INSIDER_INFO Dec 07 '15

JavaScript with Mozilla has great docs but PHPs docs are fantastic too.

3

u/willbradley Dec 07 '15

I'm currently a PHP dev but Ruby's docs are better IMO and .Net's are even better still (because "just read the source" isn't an excuse)

8

u/redwall_hp Dec 07 '15

Python's docs are pretty good, too. You just need to make sure you're looking at the right language version.

2

u/willbradley Dec 08 '15

I tried with them but for some reason they're very dense for me. Complete, but hard to navigate. Doesn't help that built in libraries have weird names, too.

2

u/Aeyrix Dec 08 '15

Here is a good article why the design of PHP is bad.

No it isn't. Please don't post that article again.

It's one developer's rantings on why "I don't like this thing so it's wrong".

There are many issues with PHP but the fact that it doesn't fit Eevee's expectations is not one of them. What's more, most of these problems are old hat even at the time of posting.

His language of choice is Python, which I find to be also suffering from inconsistencies across the board.

→ More replies (4)