Hacker News new | ask | show | jobs
by UnoriginalGuy 4862 days ago
Cannot decide which is a worse language, Javascript or PHP.

It is quite amazing how much effort people putting in to designing the "perfect" language, and yet we continue to see highly flawed languages get popular.

I wonder if we'll ever see a replacement for JS in the browser? Maybe just a JS-strict with all the gunk and strangeness removed (and maybe the libraries cleaned up a LOT).

4 comments

> Cannot decide which is a worse language, Javascript or PHP.

If you discovered that the answer was one or the other, would it make you a better developer in any way? Would it help solve any problems the world has?

Perhaps you should look more into why the "Gresham's Law of Programming Languages" exists. Maybe the have better documentation, a more friendly user community. Maybe they fix more real-world problems and spend less time mentally masturbating over programmer porn.

Discussion on HN about bad choices in a language? Check

Someone bringing up PHP when it's fairly unrelated? Check

Maybe focusing on the issue at hand would be something to keep in mind?

PHP by a long shot. For the record, I think JS is a decent language with easily encountered flaws that don't really affect me day to day. The few people I've encountered who think it's the best are...wrong. It has problems and here's the list:

http://bonsaiden.github.com/JavaScript-Garden/

It's long but not THAT long. There is a strict set of JS with some of the gunk removed. I don't think they went far enough but such is life. I'm not expecting a replacement for JS in the browser. AFAICT the browser vendors aren't interested in getting a replacement language standardized. I do expect compile-to-js options becoming more popular.

There are a couple other problems that make building web applications hard but are not the fault of the language:

What I generally find is that people who think JS sucks don't actually know JS. They know Java or C# or something and can, without learning anything, put together something that runs and generally does what they want. Their success (no obvious failures) and comfort with the syntax (except for those damn unexplainable JS bugs) causes an overestimation of their capability.

Overestimation is a problem because their experience in programing allows them to write a complex chunk of code that has the wrong abstractions/organization. It's absolutely awful. The worst 20-150k sloc codebases I've run across were ALL written by Java programmers who tell me JS sucks. The problem was that they're doing it wrong. Applying the right patterns has led to a 50%+ line count reduction in all cases. JS is its own language. The architectural patterns that work come from functional languages and not classy languages. Classy patterns can work but you need to go all-in and add type checking a la Google Closure oriented code and that's rare in the wild. Finally, small modules as in the node.js community generally seem to be working.

On the other end, JS suffers (along with PHP) the part timers. This would be fine except that easy but wrong patterns become standard practice. I fought against the jQuery spaghetti pattern for years only to find people migrating to Backbone, which is better but also flawed–events don't provide state isolation and the simple idempotent view.render() falls apart in larger apps and the workarounds are nuanced or complex. Use Ember or Angular. They are NOT more complex than you'll need unless you're only making brochureware sites.

The third problem is that the DOM sucks. The API is bad and has cross browser issues but jQuery basically won that battle. The remaining and more subtle problem is that it's a mutable global variable that you must interact with. There are a variety of mitigation strategies with the most accessible being two way bindings.

I hope to see the day where the web is language agnostic. Why the hell do we have to be tied to one single language?
The worst part is the hype. Pretending it's cool, like there is a choice.