Live data from Hacker News

PHP: A fractal of bad design

me.veekun.com

311–320 of 514 posts

Re: PHP: A fractal of bad design

#311
post #264

If this one thing that annoys me on HN it's the pervasive anti-PHP snobbery. A selection from the OP: > Because of the @, the warning about the non-existent file won’t be printed. So your complaint is that when you use @ to suppress an error it... suppresses the error? > The language is full of global and implicit state. "Global" is one of those dogmatic points. Nothing is truly "global" in PHP. The "global" in PHP j…

From the very (very) long article you picked somewhat weird collection to defend.

> So your complaint is that when you use @ to suppress an error it... suppresses the error?

This was one bullet-point from a 7-item list. Also it didn't say that @ is bad in any way (perhaps its use is), it was there only to demonstrate error configuration which is clear by the bullets after it.

> > There is no threading support whatsoever.

> That's a good thing.

You are right that for many tasks not even thinking about threads is a good idea, but there are cases where threads are very appropriate. Having the feature wouldn't hurt, would it? (Considering how tied the php is to C)

> So, it's a problem that array_search returns 0 when something is at... position 0? And returning false is just a sentinel value, much like functions in other languages might return -1. So what?

He explained the "so what" in the next few lines. I'll cite it for you: "If you use FALSE as an index, ..., 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"

Having a try statement is same as having to check for the value to be FALSE/-1/whatever, we can agree on that. But letting users write code that appears to work (yet it does not) is not a good property of a language.

> Much like Java/C/C++. PHP has array_slice() if you want it.

PHP's arrays are very different (uniform types) from those of C/C++/(Java?). So why compare them? Other than that, I agree, having slice function is enough. The author could've left this one out.

So two of your points were taken out of context, one was your opinion (two if we count your preference of if over try when checking for errors), and only two were probably justified. Rather strange choice considering you had dozens of options.

Re: PHP: A fractal of bad design

#312

Earlier quoted context omitted.

The effort required to learn something better than PHP is not equivalent to learning everything about automobile engineering, its more like reading a maintenance manual. Sooner or later, the guy who fixes his car in the middle of the road without knowing anything is going to replace his brake-pads with bits of wood he found on the sidewalk (Not really his fault, someone on a PHP forum has already labeled all the bits…

A better analog than fixing a literal car might be changing the tire of a car which doesn't have any tires when it is parked but which instantiates some with the help of an instance of ITireFactory. Obviously it makes no sense for a car to use a tire factory instead of just having tires. That is exactly how everyone who prefers PHP feels about everything.

There are far better solutions to this ITireFactory problem than PHP, which puts the tires directly onto the car, but forces you to buy a new car as soon every time you get a flat.

Also, the tires are likely to explode every 16 left turns unless you know about the secret tire fixing button under the dash.

It is true that PHP may save people a few hours in the beginning, but at what expense? How longer does it really take to get a noob running a Sinatra, web.py, dancer or something similar?

Re: PHP: A fractal of bad design

#313
post #302

Earlier quoted context omitted.

Name one. I can't think of any that aren't better served by other constructs. eval does have one huge, honking problem though: it permits text to be interpreted as code. This is just asking for code injection attacks. If you really need incremental/multi-stage evaluation, see MetaOCaml ( http://www.metaocaml.org/ ) for the proper way to do it (without exposing yourself to injection vulnerabilities). It's a consequenc…

"Name one. I can't think of any that aren't better served by other constructs." User input of code. It's hard to implement a REPL without it. Even if you do implement without it there's still an "exec" implementation hiding in there somewhere. Also, on rare occasions, it is actually an optimization when used carefully, like the Python nametuple example mentioned nearby. I'm just answering your challenge. I totally ag…

Even in the case of a REPL, what you want isn't "interpret this string as code in the language in which this program is written and apply it to the state of the currently executing program". What you're really looking for is "interpret this string as code in language X and apply it to the state of the given sandbox".

The problem with using eval for a REPL is that you want an interpreter, but eval gives you unprincipled incremental compilation.

Javascript (and I'm sure other languages) is moving in the right direction with sandboxed evals, but those are very difficult to get right in an imperative language, where a lot of code relies on global state (e.g. the DOM). Purely functional languages solve this problem well by disallowing side-effects. Of course there remain the issue of unconstrained resource usage but this is much easier to solve.

Re: PHP: A fractal of bad design

#314
post #223

The one thing that really bothers me about these "PHP sucks" articles is that the author implies that it's inevitable that anything written in PHP will be complete junk. Yes, it has flaws, but PHP is associated with spaghetti code 100% of the time regardless of who's writing the code. I've seen some very well structured PHP; Yes, it does exist. I'll admit that I am new to web app development and learned how to progra…

Most PHP frameworks are very well written -- their code is out there, on github, for all to see. There is a lot of well written PHP code. But there is also a lot more PHP code written, in general, than other languages especially by non-programmers.

Re: PHP: A fractal of bad design

#315
post #264

If this one thing that annoys me on HN it's the pervasive anti-PHP snobbery. A selection from the OP: > Because of the @, the warning about the non-existent file won’t be printed. So your complaint is that when you use @ to suppress an error it... suppresses the error? > The language is full of global and implicit state. "Global" is one of those dogmatic points. Nothing is truly "global" in PHP. The "global" in PHP j…

> Some like to argue that PHP is a beginner's language. I disagree. I think PHP is a fine language for just throwing something together... if you know what you're doing. Otherwise it's just a recipe for SQL injection and XSS vulnerabilities.

I could not agree with you more. Advising beginner programmers to use PHP is like handing out guns in a playground, someone is going to get hurt, and it will probably be the users.

Re: PHP: A fractal of bad design

#316
post #298

Earlier quoted context omitted.

It seems that many people disregard the fact that PHP is a very accessible language to a programming newcomer. You can quickly and easily install LAMP or MAMP and in minutes have a working, dynamic web page (albeit local) along with a plethora of examples and tutorials. This is huge. This shows the newcomer that this mysterious code stuff is actually accessible; that they can create something that works. That's a nic…

I agree with the general point but this seems more of an indictment of other languages than a plus for PHP: with PHP, it's easy to get started with the most simple features - and then it takes years to learn how to cope with the language quirks and inconsistencies, deal with outright bugs, and learn a number of non-obvious ways in which your “working” site might be hacked due to a hidden language feature. There are t…

Yes, that would be great. An alternative intro would be most welcome. It should, though:

- Be able to start and serve in minutes, across most platforms

- Allow for portable code e.g. the code you create locally should be able to be ported over to an actual webhost with only [S]FTP.

- Not require the command line to "work". At all.

I tried to learn django ~a year ago, and it was an experience wrought with frustration and pitfalls. The documentation was so-so, and limited in resources (or I couldn't find it). The main trouble was getting all the packages/dependencies correct. I am quite comfortable with linux and terminal (again thanks to PHP), and though I eventually got it working, I was turned off enough by the whole process that I didn't do anything with it. My accomplishment was that I got it to work, which for me was certainly still worthwhile as I was still learning, but a newcomer would likely have gone back to Facebooking long before that...

What is dangerous about the PHP bashing in my eyes (speaking with some current experience as a newb), is when someone decides to try and learn programming and they google some stuff about PHP and read endless diatribes on how horrible it is. So they go off and try django or RoR, are met with tough situations with little to no documentation; can't get anything to work, and give up all together.

Whether or not PHP is pretty, it is accessible. The divide that is created by language ideology only serves to hurt the community as a whole, IMO.

Re: PHP: A fractal of bad design

#317

Earlier quoted context omitted.

The effort required to learn something better than PHP is not equivalent to learning everything about automobile engineering, its more like reading a maintenance manual. Sooner or later, the guy who fixes his car in the middle of the road without knowing anything is going to replace his brake-pads with bits of wood he found on the sidewalk (Not really his fault, someone on a PHP forum has already labeled all the bits…

A better analog than fixing a literal car might be changing the tire of a car which doesn't have any tires when it is parked but which instantiates some with the help of an instance of ITireFactory. Obviously it makes no sense for a car to use a tire factory instead of just having tires. That is exactly how everyone who prefers PHP feels about everything.

"Everything else" does not resolve to "Java" or "C++"

Re: PHP: A fractal of bad design

#318

Earlier quoted context omitted.

PHP is not a good tool for quickly getting a minimum viable product. Despite its flaws it is a good weapon for fighting 'the last war' - that is to say, it makes it quick and easy to make what are essentially the CGI pages of 1996 - but if you're doing anything more complex than that (for instance interacting in any way with a database), and I would suggest that even relatively non-technical people looking to use com…

What would you recommend as a starting language to build a MVP? The extent of my experience is html/css, manipulating wordpress php files, and a weekend hacking together a couple of learning projects (a PHP blogging platform and a "rank this list of items by number of upvotes/this number" website). Given my past experience I was planning to use PHP as it is the only language I have any experience with and while the f…

I'd say that using Ruby with Sinatra is really easy to pick up - the documentation of Ruby itself is great and Sinatra is also documented really well, not that i think it's particularly complicated. Use an easy template-engine or stick with the default (erb) and (at least for the beginning) the sqlite-gem.

Of course, that was my impression given my prior knowledge, which of course influenced my start with that environment. But i found it to be great almost instantly.

Re: PHP: A fractal of bad design

#319

I've been to some conference lately and next to me was a guy sitting excited about the high traffic system he's building—I asked about the language he is using: He (playing with his iPad 3): PHP Me: I thought PHP devs died out for years?? He (angry): PHP is still the most used language for the web and it's fast. Me: Do you guys still mix front-end and back-end code? He (still angry): Of course not. Back home I starte…

> it's fast.

People honestly still believe PHP is fast? Wow. Even Ruby (1.9, YARV) is as fast as PHP nowadays, and it's one of the slowest mainstream scripting languages you can use right now...

http://shootout.alioth.debian.org/u64q/which-programming-lan...

Re: PHP: A fractal of bad design

#320
>>Despite the craziness above, and the explicit rejection of Perl’s pairs of string and numeric operators, PHP does not overload +. + is always addition, and . is always concatenation.

I like the fact that + is for addition and . is for concat.

It's kind of up in the air if you do "1" + 1, does it become a string? Or an integer?

Post reply on HN