JOB: LAMP Artisan

Levi Pearson levipearson at
Fri Feb 21 22:44:35 MST 2014

On Fri, Feb 21, 2014 at 1:20 PM, Matthew Frederico <mfrederico at> wrote:

> Yes - it's not a perfect programming language like node,



Node (and javascript in general) so far from being "a perfect
programming language" that it's not even funny.  I'd probably take
javascript over PHP if I had to, but I actually think it's easier to
write terrible, incomprehensible code for node.

Let me explain myself, because I realize this goes against common
wisdom and hype.

PHP strongly encourages writing very linear control.  You get a fresh
"interpreter state" at the beginning of every request, and the app
follows a route through the code towards the final sending of a
response. And then you're done, aside from whatever changes you made
to the database along the way. If something goes wrong, you can dump a
stack trace or whatever and figure out what it's doing. Sure, the
concerns might not be cleanly separated, there might be SQL queries in
the middle of rendering code, but although the code may be terrible it
is at least *straighforwardly* terrible.

Node, on the other hand, straight up *disallows* linear control flow
for anything but the most straightforward request/response actions.
Everything is callback-based, and there's a popular notion that this
means you don't get concurrency errors. Well, that's just not true.
You've got persistent state in your node process, and every time
control flow passes through a callback, some other request can come
along and change that state. Interleavings are not *arbitrary*, but
they are still *common*.  There are some patterns and idioms that can
restore some semblance of sanity to complex control flow, but you have
to know about them and use them properly.  And when things go wonky,
there's no complete stack trace to help you figure things out, just a
fragment recording the stack frames since the latest callback.

Don't get me wrong-- Node is an excellent tool in the hands of a
competent programmer who's got a firm grasp on managing concurrency.
But then PHP can produce excellent results in the hands of competent
programmers as well. It's actually very fast for straighforward
things. The question is, which one fares better in the hands of
less-comptent programmers? I'm afraid I have to go with PHP here.
Yeah, it's a mess, and incompetent programmers have made lots of
messes with it, but they're straightforward kinds of messes.  The
kinds of messes you can make with Node if you're not really good at it
are the sort that will have you completely scrapping a project.

Node is pretty fast for a system based on a dynamic language like
Javascript.  It's not particularly faster than LuaJIT2, though, and
Lua is a *far* better-designed language if you're intent on dynamic
typing.  Personally, I would lean towards something like Go, D, Scala,
OCaml, Haskell, etc. as the primary language for anything not meant to
be a throwaway prototype, and Lua for scripting. And I certainly
wouldn't call any of them "a perfect programming language" :)


More information about the PLUG mailing list