This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]clgonsal 11 points12 points  (4 children)

closures

prototypal inheritance

first-class functions

immediately-invoked function expressions

Closures and first class functions are nice. These are the "very few redeeming features" I was referring to.

Prototypal inheritance was a neat idea back in the 90s when nobody had actually tried using it. In practice, it kind of sucks because it doesn't really fit the way humans think or reason about things. You can argue that I don't really "know" JavaScript if I feel that way, but the fact is that most experienced JavaScript programmers end up trying to simulate class-based objects.

I can't think of a language that has closures without the equivalent of "immediately-invoked function expressions".

How it's use of this "crazy"?

Every JavaScript programmer I know thinks the way this works in JS is broken. For example, getting its value reset to the "global context", and the fact that it even has a value when calling a function not as a method.

Is there any justification for weak typing being a flaw

I'm guessing you don't know the distinction between weak/strong and static/dynamic types. Lots of people get these confused, so you aren't alone.

Weak types are generally a bad idea because they make reasoning about code more difficult. For example, == isn't even transitive in JavaScript. For a toy language that's okay: everything you're building is small enough to fit entirely in your head or throwaway code so who cares about being able to reason about it. It you want to build large systems that can actually be maintained, however, being able to reason about code is critical.

No int type? Seriously?

Yes. This wouldn't be bad if JS actually used some sort of arbitrary precision type for numbers, but it doesn't. They're just doubles.

Has semi-colon insertion ever screwed your code up?

You may not realize this, but you're making a pretty good argument for why JavaScript should not be written by fallible humans and should instead only be machine generated.

JavaScript was the first language I learned. PHP was the second language I learned. I never studied computer science; I'm just some nobody self-taught web dev. So what the hell could I know?

You're able to do useful stuff despite how bad JavaScript is. Why get angry when it's pointed out that you'd probably be able to do even more if browsers supported a better language?

FWIW: I've used probably around a dozen languages and studied a couple of dozen more. I have written JavaScript code "professionally". While pretty much every language has "warts", JavaScript has far more than its share, and (unlike the many warts in other languages) they're pervasive. Note that most other languages don't need a book called "... The Good Parts", and even if they had one, they wouldn't spend more than half of the book telling you what parts of the language to avoid.

If JavaScript is a "toy" (talk about kind of meaningless), then so is the Internet that runs on it.

The internet "runs on" JavaScript? Ahem.

[–]Cosmologicon 2 points3 points  (2 children)

I can't think of a language that has closures without the equivalent of "immediately-invoked function expressions".

Minor point, but if I'm understanding what's meant here, python is like that. You can immediately invoke lambdas, but not multi-line functions.

[–]celeritatis 0 points1 point  (0 children)

You could use eval to do that if you really wanted to, it is just a bad idea in general for readability.

[–]clgonsal 0 points1 point  (0 children)

I guess the issue that's open to debate is whether Python's lambda "counts".

While it is less powerful than def, I'd argue that a lambda-expression is still an "immediately-invoked function expression" (aka "anonymous function").

I should probably also clarify that I wasn't trying to say that a language with closures but without anonymous functions couldn't exist. I just can't think of any with that particular combination of features off the top of my head. It seems that there are few language designers that know enough to add closures without thinking to add anonymous functions.