Live data from Hacker News

Coding Horror: The PHP Singularity

codinghorror.com

231–240 of 341 posts

Re: Coding Horror: The PHP Singularity

#231

Earlier quoted context omitted.

Can you give an example?

Any major websites done on Lisp, Smalltalk or Haskell? Besides Viaweb? Now count > 1m visits per day websites done in PHP.

You're measuring the success of a website in terms of traffic.

The number of hits a website receives isn't the product of the language it's written in, but primarily a function of its marketing (and other factors that appeal to its users).

There are also more websites with their foundations in PHP, so it's reasonable to expect a higher number of successes. You can't therefore logically conclude that the language influences success. It's like comparing the number of millionaires in the US with the number of millionaires in Canada; the US has a bigger population compared to Canada, and all things being more or less equal, it's reasonable to expect that the US would have more millionaires simply because of its shear size.

Re: Coding Horror: The PHP Singularity

#232
post #48

I seriously groaned when I saw this post (title). I was expecting an elitist diatribe about PHP (because this is perennially popular amongst particular programmers) but that's not what this post is intended to be. Interestingly Jeff does take the usual potshots at PHP almost like he thinks he'll lose street cred if he doesn't but the basic message I agree with: if you want someone to stop doing something you consider…

His post irritated the hell out of me. For 90% of it, he rips on PHP, then at the end he says, "how about bloggers stop ripping on PHP?"

Hey guys, Jeff said his piece about PHP, everyone else shut up about it now.

Re: Coding Horror: The PHP Singularity

#233

Earlier quoted context omitted.

What other languages besides PHP have you used? I think a lot of us dislike PHP because we're putting it in the context of better designed languages.

Way to talk down to people. I use PHP as my main language for web development, but also am a frequent C user. I have done projects in C# and Python. While I like C# and Python - actually for scripting I tend to go for Python rather than PHP, prefer the CLI modules of Python- , I found that in context of web dev PHP still get the job done faster and in a maintainable manner. As for C, I use it for writing PHP extensio…

I'm not talking down to anybody.

Based on experience I asserted that many programmers feel that PHP is an inferior language because they've experienced "cleaner" languages such as Ruby. It's not wholly unreasonable that chez17 had only programmed using PHP, as PHP is commonly a programmer's first language. I therefore wanted to find out if chez17 had used other languages and to see what their thoughts are on PHP vs those other languages.

I also don't go around "constantly mocking" other languages. Why did you make that assumption?

Re: Coding Horror: The PHP Singularity

#234

I'm a long-time PHP programmer and have been programming with Lua (for gaming) for the past year and Python for command-line (NumPy) based scripts for the past two years. Obviously, in comparison, the syntax in Lua and Python are a thing of beauty as are the data structures (Lua tables FTW), but I always fall back to PHP for web projects since I haven't had the chance to completely grok the Python deployment process.…

Better: Deploy a Lua-based stack. [1][2]

I've tried to get a Python stack to build and it's huge, complicated to set up and get running well, and so slow compared to LuaJIT as to be pathetic. A friend was at PyCon surrounding by a bunch of Python hackers who spent more than an hour trying to get Django installed on his server an they failed. If the so-called experts have a hard time with it, then I don't feel so bad for finding it hard myself -- and I wouldn't recommend it to anyone.

Both Lua solutions I linked are easy and fast to install and configure (if you've got a shell, at least), and the Lua stacks are like Node.JS done right. You get coroutines so you get non-blocking code without having to code everything as an awkward callback. And of course you get the awesomeness of Lua instead of having to deal with the mess that is JavaScript.

[1] http://tir.mongrel2.org/

[2] http://openresty.org/

Re: Coding Horror: The PHP Singularity

#235
post #114
post #85

Earlier quoted context omitted.

> > default to HTML escaping on output > ??? Is that a joke? Don't do that! That's just as bad as magic quotes. Microsoft's Razor and Python's Django templates have both shown that HTML-escaping-by-default can be cleanly done in a way that is not magical and that is highly reliable. I'm not honestly sure what you're protesting here.

If I make a string: ' ' . $var . ' ' - does it know to encode the variable, and not the entire string? What if I assign that string in a variable, and then output it later? I'm not convinced this can be done well. Maybe if all you do is make some templates and fill them in you could do it. But I do a lot more than that, I output dynamically built html all the time. Just give people a very easy and shortly named funct…

Perhaps what we need is a language/platform that has built in strings that track not just the code page type encoding, but some kind of "intent assertion" as well -- is the string intended to be encoded for a particular output? Combining an "unknown" string with an HTML (or SQL, or PostScript, or JSON/JavaScript, ...) string would produce an exception.

Such a mechanism would have to include encoding functions (and assertion override functions), of course.

It seems this would help alleviate many types of fill-in-the-blank injection problems as well.

Re: Coding Horror: The PHP Singularity

#236

Earlier quoted context omitted.

> If you don't like PHP then use another language or build a better one ... Everyone that invents a language ... But he said nothing about "inventing" a language. In fact said very clearly that he wanted to take an existing language and add to it - particularly the things that PHP does do well. from TFA: > "to buff up a open source language ecosystem such that it can truly compete with PHP in ease of installation and…

If an existing language already has potential to replace PHP then I don't see why it wouldn't have already. What would/could you tweak that would get you there without fundamentally changing the language capabilities and syntax?

Setup costs - PHP has a low barrier to entry in the sense that Apache's mod_php5 is a simple "a2enmod php5" command away. Even PHP-FPM with Nginx is only a few well-documented configuration options away from working.

Currently, no other language can match that. They either require a VM running (Java, Ruby, etc.) or at least have a compile/build step (Python).

UWSGI has a lot of promise, but until it's as easy to get configured as PHP-FPM, PHP is still way easier than everything else.

Re: Coding Horror: The PHP Singularity

#237
post #124

Earlier quoted context omitted.

Hey. I work on Facebook's PHP toolchain, HipHop, which these days includes a debugger, interpreter, JIT compiler, and the ahead-of-time compiler. The fact that the AoT compiler uses C++ as a target doesn't change the input language, which really is PHP. E.g., $i = 0; $a[$i] = $i++; makes a different array than $i = 0; $a[$i + 0] = $i++;. We have to get all the nooks and crannies right because we use significant open…

I have to ask, because it's really been getting at me for a while honestly. How do your developers react to that? I mean, you guys are known for going after the best and the brightest. People who have worked hard to perfect their craft. These people tend to have strong opinions when it comes to language design. How do you get them from that point to "ok, now write some php code" ?

The aspects of PHP that are bad (and there are more than a few) are easily tooled around. We have a review-time tool that parses your PHP, symbolically executes it, and looks for dubious idioms, flagging them for you and your reviewer.

Meanwhile, PHP gets a number of things very right. For instance:

* State: there is none across requests. Oh sure, there's APC, and the filesystem, and databases, etc., but those are all accessed via libraries. There is no PHP-level state that survives a request, which provides natural fault isolation: a request which goes wrong doesn't take the server down with it, or live on to corrupt other requests.

* Concurrency: PHP's concurrency model is the web request. If you want to run some code in parallel, curl to localhost. If you wrap an appropriate library around this, it looks just like Erlang's actors. This is shared-nothing concurrency, which turns out to be a compelling local maximum.

* Interactivity: The development workflow PHP provides is very productive. You save and load the page. You don't save, optionally recompile, restart the server, wait for it to initialize, forget what's different from the last three times you tried this because this has all taken three minutes and you forgot to write it down, etc.

These three things turn out to be among the most important parts of a server-side language, and PHP gets them very, very right. The rightness was accidental, not by design, but this doesn't make it any less right.

Also, the language itself can be improved. In the HipHop toolchain, -v Eval.EnableHipHopSyntax=true turns on a bunch of (backwards-compatible) features we've added to our PHP dialect, the most notable of which are XHP (syntax for using XML literals as PHP expressions) and generators (inspired by Python's, using similar 'yield' syntax). I put up some sample code for a talk just the other day, if you're curious: https://github.com/kmafb/hiphop-samples

Re: Coding Horror: The PHP Singularity

#238
post #125
post #114

Earlier quoted context omitted.

If I make a string: ' ' . $var . ' ' - does it know to encode the variable, and not the entire string? What if I assign that string in a variable, and then output it later? I'm not convinced this can be done well. Maybe if all you do is make some templates and fill them in you could do it. But I do a lot more than that, I output dynamically built html all the time. Just give people a very easy and shortly named funct…

Just needs a bit of type system magic. Don't use the same type for escaped and unespaced strings. (And don't use the same type for user generated input before and after it's scrubbed / escaped of any nastiness.) Ask any Haskell weeny for details. Also in your example, you'd probably be better of, if your language knew about the HTML structure, e.g. something like P($var), instead of putting the tags in as strings.

I agree, the language runtime should support this somehow.

http://roboprogs.com/devel/2009.07.html#2009_07_30 (point number 4 in the numbered list)

Of course, I was thinking of a runtime attribute, rather than static typing, but the idea is similar.

Re: Coding Horror: The PHP Singularity

#239
post #179

Earlier quoted context omitted.

> ... 'we write code anywhere and deploy it anywhere'. There's an additional build step in between the developers and the final product, rather than just straight up serving PHP as is which is one of the biggest PHP recommendations. According to him there's no explicit build step the devs have to perform and they're just writing PHP and using open source packages--meaning they are in fact making use of the "write onc…

Hm, I possibly need to clarify it up a bit. Now, as far as I understand it the Zend backend takes the PHP code, creates opcodes and executes it in a VM, whereas HipHop takes the code, compiles it down to C++, compiles it again with G++ then runs the resulting C++ binary instead. To me at that stage HipHop is no longer a backend, but an entire build system transforming the language away from PHP. Like I said, I'm not…

I'm still curious why the target is C++ and not LLVM or a direct ISA. AoT seems very useful, using PHP as a language and not a runtime at least in deployment.

Re: Coding Horror: The PHP Singularity

#240
post #48

I seriously groaned when I saw this post (title). I was expecting an elitist diatribe about PHP (because this is perennially popular amongst particular programmers) but that's not what this post is intended to be. Interestingly Jeff does take the usual potshots at PHP almost like he thinks he'll lose street cred if he doesn't but the basic message I agree with: if you want someone to stop doing something you consider…

His post irritated the hell out of me. For 90% of it, he rips on PHP, then at the end he says, "how about bloggers stop ripping on PHP?" Hey guys, Jeff said his piece about PHP, everyone else shut up about it now.

You do have a point, this seems to be a fairly common way to vent yet still appear 'objective'. I do it myself sometimes, and occasionally pick myself up on it... mainly when I get away with it. :)

I sense this is probably done quite a lot in journalism, so you can write 'interesting' articles without coming off like a completely biased douche.

Post reply on HN