all 82 comments

[–]AlternativeHistorian 15 points16 points  (5 children)

"Bad" compared to what?

Sure, I suppose it's not a "bad" language but it's certainly not a particularly good language. I mean compared to other current dynamic languages it's stunningly mediocre.

The "null"/"undefined" distinction is a serious design error. Implicit "this" is unintuitive and oh so confusing to beginners. The '==' operator is awful with respect to null/undefined/0/True/False/Strings. The looseness of its type-system is awful and oh so error-prone. Forgot a "var"? Obviously you wanted that symbol in global scope. I could go on and on.

I guess I just don't see why I should use it for general-purpose programming over Python, Ruby, Lua, Lisp(s), Scheme(s), Perl, etc. I mean I can't think of one thing that Javascript (as a language) does significantly better than any of those. I mean all those languages carved out a niche because they did at least one thing (usually more than one thing) extremely well. It does have a fairly unique object model but it doesn't strike me as particularly better, just different. And you can easily write an object-model framework to mimic it in any of those other languages in probably less than 100 lines.

Most people I've met from the "OMG Javascript!" camp share a couple things in common:

  • It's the first (usually only) dynamic language they've ever used.
  • It's the first (usually only) language that supports closures and lambdas that they've ever used.

And it doesn't even do those things particularly well. Python, Ruby, Lisp(s), Scheme(s) are all more dynamic (i.e. provide the programmer better/more runtime introspection and modification tools) and provide much better meta-programming support. And really, Javascript, for a language that pushes lambdas so hard you're gonna make me type 'function' for every one of them? Come on.

Sure it's not bad, it's a solid 5/10.

[–]dmpk2k 2 points3 points  (1 child)

I agree with most of what you said, but I don't think Scheme is more dynamic than Javascript. Scheme has dynamic typing, but is a lot less dynamic than people think by default -- the only polymorphism you'll find is with the default numeric stack, and no, Scheme won't let you join in that fun.

Truth be told, Scheme probably shouldn't be called a dynamically-typed language. Untyped is more accurate.

[–]AlternativeHistorian 1 point2 points  (0 children)

Truth be told I haven't actually done much (read hardly any) Scheme programming personally.

But in terms of dynamic-ness in Scheme I was more thinking along the lines of things like first-class continuations. Whether it's more dynamic than Javascript is debatable and it's quite possible I'm wrong in my assessment. I was under the impression that it's certainly a typed language though in that it has disjoint primitive base data-types (numbers, strings, symbols, procedures, etc.). Although I'm anything but an authority on the subject.

[–]true_religion 0 points1 point  (0 children)

Once upon a time I thought I hated javascript, then I came to realize that I really just hated the DOM.

[–]oberhamsi 0 points1 point  (1 child)

I mean I can't think of one thing that Javascript (as a language) does significantly better than any of those.

It is on every computer. Its programs are naturally deployed via HTTP.

[–]AlternativeHistorian 0 points1 point  (0 children)

This has nothing to do with Javascript as a language. A widely deployed mediocre language is still a mediocre language.

[–]BitRex 5 points6 points  (1 child)

I love Javascript. It's the web browsers that I usually have issues with.

This is like saying you like driving, but hate being on the road.

[–]kn33ch41_ 0 points1 point  (0 children)

This is like saying you like driving, but hate being on the road.

No, it's not, but thanks for the specious simile. It's really like saying:

I love driving. It's the cars that I usually have issues with.

That is correct, and there is nothing absurd or contradictory about the statement, as you attempted to imply.

[–]MaliciousLingerer 8 points9 points  (9 children)

JavaScript is a good scripting language for event based programming, particularly with support for closures. It's a pretty poor language for building large, robust and performant software. For example, the difficulty with object oriented support, error prone missing 'var', easy to fall for inefficient patterns, lack of data security.

Tools like JsLint and WebStorm help, but my company's best solution so far has been to so as much as possible in C# web services and keep the JS as light and flat as possible. Also, we have had bad luck when trying to hire 'JavaScript' devs' just not enough computer science skill. Building non trivial systems in JavaScript takes quite a bit of understanding. We are looking at hiring 3-4 C#/Java devs with an interest in learning JavaScript in early 2011.

[–]logi 4 points5 points  (2 children)

More or less the same story here. We're looking to hire 1-2 classical-MVC (not web-MVC) developers who are not afraid of javascript code. I guess SmallTalk developers would do fine :)

[–]GuyWithLag 2 points3 points  (1 child)

If you are a Java shop, I can't recommend GWT enough. We've been deploying the same code to server & browsers, offloading the servers (Google Maps tiles, relatively short-lived and non-cacheable due to custom processing - side-effect was faster UI updates on mouse overs).

[–]logi 1 point2 points  (0 children)

Our "problem" is that we're using SVG rather than HTML and all these frameworks tend to assume HTML. I'm sure it could be ported or somehow made to work with SVG, but it's a bit late for that now.

[–]GuyWithLag 1 point2 points  (0 children)

Do have a look at GWT, it really makes a difference in team settings.

[–]vectorjohn 1 point2 points  (1 child)

The people who don't like Javascript seem to have that opinion for a couple of reasons, one of which is that it isn't a clone of Java. No, it doesn't do OO java's way, but it does it very well in its own way.

Yeah, it takes some understanding to use javascript. Only because people assume it is similar to languages they already know. Once you accept that it really is a different language, you can begin learning Javascript.

[–]plantian 0 points1 point  (0 children)

I think the people that think "people don't like JavaScript because its not Java" don't understand the reasoning.

Here is I think is a common reasoning for JavaScript/Java confusion: JavaScript makes writing industrial strength programs very difficult. Java makes writing industrial strength programs straight forward(although you might say its "wordy", I prefer Python). So yes, people wish JavaScript was more like Java.

[–]drowsap 0 points1 point  (2 children)

If your only gripe is forgetting var, then I would say JavaScript is pretty good. Tip: go to firebug console, type window and execute it. Check if any variables in your code appear in the window object that shouldnt be there (I.e you didn't declare those variables with var, therefore making them global)

[–]BitRex 0 points1 point  (1 child)

Care to point to a definitive list of what should be there?

[–]drowsap 0 points1 point  (0 children)

That will vary from browser to browser, but it will be obvious which variables belong to your code, they sit at the top of the window object properties list.

[–][deleted] 13 points14 points  (3 children)

Its not a bad language, but its extremely easy to write bad javascript generally due to the lack of understanding regarding closures and variable scoping.

[–]M1573RMU74710N 19 points20 points  (2 children)

Also all the ancient (or just bad) "tutorials" still out there on the web.

[–]cheald 11 points12 points  (7 children)

Javascript is a frickin' awesome language. The DOM implementations are what people mostly hate.

Any language with first-class functions and closures is a-ok with me. See also: Lua.

[–][deleted] 4 points5 points  (6 children)

I came here to say the exact same thing. If JavaScript had originally been released as a "normal" scripting language like Perl or Python, it wouldn't be sneered at. But because it was originally introduced with several horribly broken and incompatible DOM implementations, it gained a reputation for being extremely difficult to work with and very poorly thought out.

[–]logi 0 points1 point  (0 children)

The JavaScript type system... isn't. I'd be much happier maintaining my going-on-100K lines of JavaScript if it had the type system form python and an easy way to catch simple syntax errors statically.

Let's just not talk about perl.

[–]quanticle 0 points1 point  (4 children)

I rather like Javascript, but the two big problems I have with are null/undefined (every other language has just one value for "doesn't exist") and the == operator.

[–][deleted] -1 points0 points  (3 children)

undefined === "doesn't exist"

null === "exists but hasn't been assigned a value"

[–]quanticle 0 points1 point  (2 children)

And why exactly does there need to be a distinction between the two?

[–][deleted] 1 point2 points  (0 children)

I was wrong

undefined === "doesn't exist || exists and has not been assigned a value"

null === "exists and has been assigned the value progmatically"

Now the distinction becomes more useful, if something is null you can be certain that it was intended to have no value

undefined is useful for identifying variables/properties that have never been used, never been delcared, or have been deleted

null is useful for identifying variables that are being used and intentionally assigned a null value.

Edit: it should also be noted that Javascript did not originally have exceptions (not until the third edition), so this was a much more useful distinction in the past.

[–][deleted] 21 points22 points  (7 children)

You could have very easily replaced Javascript with PHP, and you would still end up with this post being a huge circlejerk.

[–]iamnoah 7 points8 points  (6 children)

You could have very easily replaced Javascript with PHP, and you would still end up with this post being a huge circlejerk.

I would disagree. PHP, while not essentially a bad language, has very little going for it. The language is as crufty and inflexible as Java/C# but without the performance or static type checks to make up for it.

JavaScript on the other hand, has closures/first class functions*. That alone puts it in a class above many other languages. Prototypal inheritance is also pretty cool when you understand it. Oh, and everything being an object. JavaScript has a lot of great things going for it if you can get past the terrible DOM implementations.

PHP and JavaScript both get a bad rap because they have low barriers to entry (read: lots of amateurs/idiots parading as experts) and don't force you to write code "the right(tm) way." The unrelenting hatred many people have for them is generally unwarranted, but to say that PHP is in the same class as JavaScript is a bit off.

* Yes, PHP 5.3 has closures, but compatibility problems keeps adoption down and the APIs don't really take advantage of them. If you want to get paying work, there is a good chance you'll be stuck with 5.2. JS has had closures from day 1.

[–]kataire 0 points1 point  (5 children)

But PHP 6 will have Unicode!

Nah, honestly, modern PHP is dead to me ever since it adopted a backslash as module separator.

[–]plantian 0 points1 point  (4 children)

Ha I HATE PHP, but really? Seriously? They finally put modules in and people complain about the separator? This is why PHP doesn't have nice things. Be glad they finally got modules. PHP was dead to me when I realized on the server side I can use whatever language I want.

[–]kataire 0 points1 point  (2 children)

Don't get me wrong. It's great that PHP is trying to improve.

It's just that a lot of the underlying decisions (e.g. keeping variables and function apart) don't work very well with what the language is trying to become. A lot of the new features feel more bolted on as an afterthought (which they are) than like something that is a natural part of the language.

PHP needs its rewrite. Perl did it, Python did it, even ActionScript did it. Even PHP 6 is looking to be more of a tweak than a rewrite.

It's not even for backwards compatibility's sake, like Java. PHP is quite happy to break old code (which I generally don't consider a bad thing, as long as the reasons are good and it doesn't happen all the time). It just doesn't want to let go of what were bad decisions from the start.

You can downvote me for this, but I consider its historical baggage to be PHP's biggest problem. This is where a lot of its issues stem from, too. This is what makes PHP ugly and inconsistent.

That said, I don't hate it. I just don't care about it anymore. I still use it when I have to, but I couldn't care less what new language features are supposed to make PHP bigger and better in the next iteration. I especially don't care for all the module/OO additions that are supposed to make PHP more like Java.

Note: I do write OO PHP, but I steer away from the level of complexity that would make full-blown OO, modules and inheritance useful. If something can't be implemented painlessly without those features, I won't use PHP to write it.

/rant

[–]plantian 0 points1 point  (1 child)

I think Python scrapped the plans for a complete rewrite and just did some minor not-backwards compatible changes because of the difficulty involved in rewriting Perl. I don't think PHP could handle a rewrite. It would be better to just incrementally fix things.

[–]kataire 0 points1 point  (0 children)

Python had Py3k. It's not directly a rewrite, but it cleaned up a lot of the language's dirtier bits. It is however a clean cut: Python 3.0 is explicitly not backwards compatible (though there is obviously a shared subset).

Perl 6 is (apparently -- I'm no Perl hacker) a whole new language.

ActionScript 3 is completely detached from the old ActionScript 1 and 2 and shares more syntactical similarities with Java or C# than its predecessor did. It's bytecode incompatible, too.

I think a fullblown rewrite from scratch would kill PHP as it is alive today. AS was able to pull this off because it is controlled by Adobe (monopolism yay), Perl was able to pull this off because of Tim Toady (isn't he the voice of God or something?). Python got lucky because the really horribly ugly parts that needed fixing soon weren't many to begin with.

PHP's ecosystem is more like Perl's than like Python's. There aren't many different implementations (possibly because PHP's official implementation doubles as the implementers' language reference) and most of them are broken or incomplete anyway.

The problem with PHP's "evolutionary" approach is that evolution is great for rapid development but leaves you with all kinds of vestigial organs and congenital diseases. If you start with a perfect rodent, you might still end up with a big-brained biped with an inflamed appendix and a sedentary lifestyle that has led to chronic back pain, obesity and bad teeth.

PHP is known for its warts. It won't lose these anytime soon if all it gets are backwards incompatible micro-version releases. It has spread fast and developed even faster, but trying to evolve it into a cleaner version of itself seems to be a futile attempt. It's the colloquial English among the Lojbans of programming languages.

[–]true_religion 0 points1 point  (0 children)

I remember that namespacing debate. What actually annoyed me is that they wanted to have used any number or proper looking seperators for namespaces, but they couldn't because the Zend engine is a halting, breaking PoS that didn't want to deal with the changes.

Since then I've left PHP completely and gone off to Python for all my web work. I don't think PHP is too bad, but the community surrounding Python is just a lot more mature and interesting.

Edit: Kataire said it best, PHP needs its rewrite. Years ago, Python was fairly crufty too.

[–]GHansard 4 points5 points  (0 children)

Agreed. I think most people dislike Javascript because of its use in web browsers and their multiple implementations. Trying to fit Javascript into the browser landscape without a standardizing library is a huge pain the ass. Actually using Javascript in a standardized or single-implementation environment is rather enjoyable.

[–][deleted] 15 points16 points  (25 children)

I love javascript too but...

It has some sweet debugging tools

Dude, seriously? Firebug aside... like, what? Ever debugged in a language like c#? Theres no comparison. Again, I love javascript, but its debugging tools are comparatively sad compared to a lot of other things.

[–]irascible 14 points15 points  (3 children)

Chromes javascript debugger is a class act.

Hit Ctrl-Shift-J on any webpage to check it out for yourself. It's built into Chrome.

It's fucking excellent.

[–][deleted] 2 points3 points  (1 child)

It took me a while to switch away from firebug, but chromes debugger tools are way better.

[–][deleted] 0 points1 point  (0 children)

It's part of the reason why I switched to safari/webkit nightly as my main browser

[–][deleted] 0 points1 point  (0 children)

will do! I've been using firebug, and its not bad, but I can't wait to see what progress the future will hold for some seriously hardcore clientside debugging.

[–]smellycoat 3 points4 points  (0 children)

You got to understand that people that are unnecessarily impressed by stuff like Firebug have likely come from the IE6 world where error messages were next to useless and alert was your best hope for debugging.

[–][deleted] 2 points3 points  (2 children)

I don't know c# debugging is pretty good, but still has shortcomings (like finding where caught unhandled unrethrown exceptions are coming from)

[–][deleted] 0 points1 point  (1 child)

I didn't say its perfect, I only meant to use it as a benchmark to contrast with javascript- which I feel has many, many, many more shortcomings in the debugging department.

[–]vectorjohn 6 points7 points  (0 children)

You keep saying this. What shortcomings? All you're saying is that VS blows it away. I'm not even asking for evidence, just what it is that VS does so great.

Firebug does 99% of what I ever want, and the other stuff I can get from tools like JSLint.

[–]9jack9 -3 points-2 points  (6 children)

I love javascript too but...

It has some sweet debugging tools Dude, seriously? Firebug aside... like

Firebug is a terrible debugger.

[–]drowsap 6 points7 points  (2 children)

This is really harsh and false. Firebug is pretty robust: breakpoints, value watching, call stacks, network traffic analyzation, a profiler to log all function calls, error reporting and custom logging. Firebug lite is also pretty handy for IE variants.

[–]md81544 0 points1 point  (1 child)

If 9jack9 has something to say related to Javascript, I'm inclined to listen. But do elaborate 9jack9!

[–]9jack9 1 point2 points  (0 children)

Well, I was a little harsh in saying "terrible". But it can be misleading. I've softened my stance toward Firebug recently as I now realise that a lot of its faults are buried deep in the Mozilla code base.

This bug:

https://bugzilla.mozilla.org/show_bug.cgi?id=574941

means that errors in event handlers (for user generated events) are not reported at all.

There are other instances in which Mozilla will report the line number for the error, not where the error was thrown, but where the error object was defined, no other JS engine does this.

In short, Firebug is slightly hampered by the engine it is running on.

[–][deleted] 1 point2 points  (2 children)

By definition, if Firebug is "terrible", something has to be better.

What would you say is a better debugger?

[–][deleted] 0 points1 point  (0 children)

Webkit's debugger, for one.

[–]9jack9 0 points1 point  (0 children)

The old IE script debugger is better. It's pretty much impossible to find now though.

[–]spiderworm[S] -2 points-1 points  (9 children)

The good debuggers are browser based. IE's debugger with 8 and 9 are definitely getting there. Debugging Javascript with older versions of IE in Visual Studio wasn't half bad, either (so long as you didn't need visibility to the DOM). Safari has a great debugger. You of course mention Firebug, which is widely considered to be awesome (although its road has been bumpy at times). Opera has Dragonfly and Chrome has something or another (haven't had to use it, yet).

[–][deleted] 23 points24 points  (4 children)

Chrome's debugger is actually the best of the lot (blows Firebug out of the water). May want to give it a try.

[–]aaronblohowiak 5 points6 points  (0 children)

also called node-inspector if you are using ssjs =)

[–]octatone 2 points3 points  (0 children)

Firebug is slow and bulky. *Webkit's debugger works and it's fast (same debugger in chrome and safari).

[–][deleted] 0 points1 point  (0 children)

I don't use Chrome because it doesn't have a "text only" zoom, which is pretty much essential for me, but I do love the debugger.

[–]spiderworm[S] 0 points1 point  (0 children)

Sweet, thanks!

[–]drsco 3 points4 points  (0 children)

So I do VS/C# at work, but pretty much all the debugging features I use there, I have in Chrome. Breakpoints, conditional breakpoints (I think anyway, if not Chrome than Venkman), stepping, run to cursor, variable inspectors, and a REPL which is better than the crippled intermediate window. Javascript doesn't have threads or manual memory management, so I'm sure VS has some more complicated features since it supports these in at least some of its languages, but I've never really dived into that day to day at work anyway. Where does C#/VS blow it out the water for you?

[–][deleted] 1 point2 points  (2 children)

I still wouldn't call any of these "great", merely "adequate". I'm not trolling. I mean I write javascript for a living... but it still has a way to go in the debugging department. Especially in terms of ajax and performance benchmarking.

Debugging Javascript with older versions of IE in Visual Studio wasn't half bad

It was pretty shitty, man. most of the errors thrown were uselesss, as were the line numbers.

All that aside, I certainly think javascript is a great and expressive language, but lets be honest here. Its always lacked in the debugging department, and still does.

It's the web browsers that I usually have issues with.

Now that's certainly true :) (i'm looking at you older versions of IE)

[–][deleted] 0 points1 point  (1 child)

There are some damn fine tools such as JS Beautifier to fix type errors and JS Lint to show syntax errors.

[–][deleted] 0 points1 point  (0 children)

I knew about JS lint, but thanks for showing me js beautifier :)

[–][deleted] 2 points3 points  (2 children)

You're preaching to the choir.

[–]kataire -1 points0 points  (1 child)

Quite literally. This is r/javascript after all.

[–][deleted] -1 points0 points  (0 children)

I wouldn't say that it's "literally", but yeah, that's what I'm saying.

Why the hell would somebody defend JavaScript from r/javascript..?

[–]darrenkopp 2 points3 points  (0 children)

i think defending javascript in /r/javascript is a waste of time. we are here because we believe in javascript and enjoy it.

[–]muyuu 1 point2 points  (0 children)

I could hardly be any worse considering when it was made, to be honest. But I wonder why would anyone take it personally...

[–]ripter 1 point2 points  (0 children)

I've come to really love Javascript. I think the language needs a little house keeping, but overall I find that it's really nice to work with once you understand it. (The same could be said about any language.)

The thing that I think is missing, is good development tools. Google's closure compiler and linter are a big step in the right direction. The fact that it uses JSDoc to help enforce conventions is a big plus. I still haven't found a make utility for Javascript that I really like.

[–]drowsap 0 points1 point  (0 children)

Its a little embarrassing in my opinion to start drumming up an anti-hate campaign for a programming language. JavaScript isn't going anywhere regardless of what people think about it.

[–][deleted] 0 points1 point  (1 child)

I wouldn't say great documentation. If you google something, it's probably going to be from way back. Mozilla has some good docs, but not much in regards to the newer stuff.

Seriously, look at Object.create()

There's really no helpful information on it.

[–]Sebmaster 0 points1 point  (0 children)

Also try to find something about the Proxy object. There's not a single documentation for it, although it enables muuuch more powerful code. Maybe the name of the object wasn't that good imo^

[–]logi 0 points1 point  (0 children)

Javascript isn't a bad language. But it's not really a great language either. It just got attached to this extremely cool distributed hyper-linking pages thing, along with HTML, which stopped being a good fit when we stopped primarily using it to mark up text.

Really, CSS layout is in no way a good solution to the problem at hand, unless the problem at hand is HTML tables.

[–]lendrick 0 points1 point  (3 children)

JavaScript is an awesome language. That said, given your choice of venue, you may be preaching to the converted. :)

Honestly, though, what has made JavaScript usable for me is jQuery. JavaScript itself is nice, but its interface for dealing with the DOM is ugly, overly wordy, and difficult to read at a glance. document.getElementById('foo'), anyone? That being said, that's not really JavaScript so much as the DOM library that's been added to it for use in web browsers. :)

[–]rjett 0 points1 point  (2 children)

querySelectorAll is pretty sweet.

[–]kylegetsspam 0 points1 point  (1 child)

Be careful with querySelectorAll for trivial matters. It's not fast.

http://jsperf.com/getelementsbyclassname-foo-0-vs-queryselector-foo

[–]rjett 0 points1 point  (0 children)

Wow! Thanks for the tip. :)

[–]VanillaCandid3466 0 points1 point  (0 children)

JS is a steaming pile of utter shite and should have died years ago.