Live data from Hacker News

John Resig: JavaScript as a First Language

ejohn.org

151–160 of 228 posts

Re: John Resig: JavaScript as a First Language

#151

Earlier quoted context omitted.

It's 2011. We love significant whitespace now, get on with the times...

Assume you've never programmed before. Would you want to debug a program that has a significant whitespace bug? It's much easier for the average person to spot an unbalanced parenthesis that an incorrectly sized whitespace. Getting stuck and being frustrated hurts motivation a lot. Now curly brackets and syntax may be seen by a person as an irritation or inconvenience compared to whitespace, but I'd say it's better t…

""" It's much easier for the average person to spot an unbalanced parenthesis that an incorrectly sized whitespace."""

Is it? Assuming you use a fixed-width font, any incorrect/inconsistent indentation should stand out like a sore thumb. More so than counting { }s in nested blocks. (Of course, decent editors help with both cases, so I think it's essentially a non-issue.)

Re: John Resig: JavaScript as a First Language

#152

Earlier quoted context omitted.

Unfortunately I think that class-based inheritence is more general in concept. That is, people who understand class-based inheritence have a very small leap to get prototypal inheritence. You can pretty much just say, "Inheritence works on the instances/objects, not on the class." Explaining class based inheritence to people who only know prototypal seems trickier. You have to explain the concept of classes and then…

In Io you can add as many objects as you like to the protos list of an object: http://www.iolanguage.com/scm/io/docs/IoGuide.html#Objects-I...

Nice. Thanks. How is it that I've never looked at the IO language before? Some reading for tonight.

Re: John Resig: JavaScript as a First Language

#153

If you want to teach computer science to people then a good first language for them to learn is C, because it will help them think about and understand what the computer is actually doing.

That's an argument for learning C, but not for learning C as a first language. Studying assembler or chip design or even particle physics will also help you understand what the computer is 'actually doing', but it doesn't mean that's the best place to start learning how to program.

Re: John Resig: JavaScript as a First Language

#154

Earlier quoted context omitted.

That's definitely not obvious. Some people think in patterns or generalizations. String [binary_operator] Number = String String [binary_operator] Number = Number That's just begging for further explanation. Explaining JavaScript is probably more challenging than say Java. Java has many keywords and usages, but when it comes to explaining the concept of those keywords/semantics to students, it may be a little bit les…

OK here's plain english simple explain... Left hand side is a string, and "+" is string concatenation as well as addition. So '5' + 3 = '53' (String concatenation). Just as "Hello" + 1 would equal "Hello1". The right hand side is converted to a string. Left hand side is a string, but "-" is subtraction for numbers. JS converts the '5' to a number, then subtracts. So '5' - 3 = 2 (Numerical subtraction). That's the exp…

The issue isn't explaining it. The issue is it needing an explanation at all.

Re: John Resig: JavaScript as a First Language

#155

For the interested (and with the caveat that I definitely would not suggest it for the Khan Academy's purposes), CoffeeScript does try to address all of the issues that John raises in his post. Type Coercion: There is no `==` in CoffeeScript. You usually write `if x is y` in order to be particularly clear, but if you're in the mode of most other scripting languages, and you write `if x == y`, it will compile to `if (…

CoffeeScript is a subset of JavaScript with bindings to an alternate syntax (CoffeeScript). John's suggestion is an enforced subset of JavaScript, with the advantage that (some) JavaScript in the wild is understandable; error messages are in terms of the source language (very helpful, more so for beginners); and yields a skill with greater marketability (so far).

Why not use the same subset as CoffeeScript? In some cases, this simply forbids some constructs; in other cases it allows a construct, but only in certain contexts.

A mathematically precise but implementation-unfriendly definition is: only allow the subset of JavaScript that is the compilation of some CoffeeScript program.

Re: John Resig: JavaScript as a First Language

#157

For the interested (and with the caveat that I definitely would not suggest it for the Khan Academy's purposes), CoffeeScript does try to address all of the issues that John raises in his post. Type Coercion: There is no `==` in CoffeeScript. You usually write `if x is y` in order to be particularly clear, but if you're in the mode of most other scripting languages, and you write `if x == y`, it will compile to `if (…

These are all reasons why I've adopted CoffeeScript over JS. Sure, you can accomplish the same exact things in JS, but they are far more natural with CS and with far less typing. Less typing is less chance for mistakes and bugs and makes an easier learning experience. One other line item is the encapsulation of classes in CS. Doing that in CS is natural and easy to explain to a first year programmer. Accomplishing th…

Seeing as how one of the arguments for teaching JavaScript first is that it lets you teach about prototypical inheritance before the students get used to class-based inheritance, the complexity of simulating a class in JavaScript is probably not the best objection to using it instead of CoffeeScript. If you teach them CoffeeScript, then you will teach them class-based inheritance just like everywhere else, and miss out on the prototype paradigm.

Re: John Resig: JavaScript as a First Language

#158
post #120
post #90

Earlier quoted context omitted.

Java isn't really simple in comparison to Haskell--Java is full of warts and inconsistencies while Haskell is simple, consistent and elegant. The reason Haskell is viewed as hard is that it takes basically nothing from languages you already know. If you don't know any languages, it's actually a great starting point.

> The reason Haskell is viewed as hard is that it takes basically nothing from languages you already know. If you don't know any languages, it's actually a great starting point. At my undergrad program, Haskell was used for the second CS course after the basic intro course. It was a nightmare and drove people away from the major in droves. They just did a curriculum overhaul and one of the changes the CS faculty are…

Funny that http://www.lambdassociates.org/blog/decline.htm should be on the front page at the same time.

Re: John Resig: JavaScript as a First Language

#159

Earlier quoted context omitted.

These are all reasons why I've adopted CoffeeScript over JS. Sure, you can accomplish the same exact things in JS, but they are far more natural with CS and with far less typing. Less typing is less chance for mistakes and bugs and makes an easier learning experience. One other line item is the encapsulation of classes in CS. Doing that in CS is natural and easy to explain to a first year programmer. Accomplishing th…

Seeing as how one of the arguments for teaching JavaScript first is that it lets you teach about prototypical inheritance before the students get used to class-based inheritance, the complexity of simulating a class in JavaScript is probably not the best objection to using it instead of CoffeeScript. If you teach them CoffeeScript, then you will teach them class-based inheritance just like everywhere else, and miss o…

I'm ok with missing out on the prototype paradigm. To me, it is a wart for JavaScript. There has been a ton of discussion on why libraries like DateJS, which pollute the Date prototype, are bad.

http://stackoverflow.com/questions/4823682/javascript-namesp...

Re: John Resig: JavaScript as a First Language

#160
Here is my blog article I wrote on this travesty. (Available here: http://blogkinnetic.blogspot.com/2011/12/on-civic-decay-of-u...) I am not a pugilist for the sake of it, but when I see abominations like this, well, somebody has to take a stand for whatever real programmers are actually left out there. :-) =================================================== When I saw the above article I could only be reminded of H.P. Lovecraft's description of the Massachusetts seaport town of Innsmouth, a great fishing community before the American Revolution, but which by the early 1900's had become a classic case of civic decay, with bootleg liquor becoming its primary occupation, and the general cultural or educational status descending to the level of the primitive. This is because the approach the article advocates for teaching computer science can only end in one place: the primitive, and by that I do not mean the C primitive variable types of char, float, double, and int, but I mean primitive as in stone-age. :-)

I learned programming a bit ass-backwards. I got a "teach yourself Java" kind of book, went through that, and generally learned things "on the fly" as it were, and, in so doing, in time, eventually was comfortable with the "Java world" of Java SDK (basic Java), XML, XSLT, and some DOS / UNIX scripting skills as well. Still to this day, Java is a language I feel very "at home" in, and would choose if I had to build something up really fast. It is my "GOTO" or "default" language if you will.

Later, though, I started to study C++ and C, first for a job that required me to write unit tests using CPPUnit (the C++ port of Java's JUnit) and just sort of "learning on the fly" began to be able to understand and edit C++ code, though I was not then (or now) as proficient there as in Java. Still later, I studied C proper and read Kernighan and Richie's classic book, "The C programming Language". I think it was then, and only then, that I really understood the fundamentals of programming, by which I mean the principles of it, not just memorizing syntax to get stuff done, but rather having a deep understanding of things like memory allocation, processes, stacks, etc.

The thrill of creating dynamic (re-sizable) arrays using C-style pointers is something that still gives me a bit of a high, because there are many situations in which resizable arrays are needed or desirable, and doing this via C-style pointers is the most efficient way of doing it.

I can say that while today I still would choose Java if I were doing a personal project of some size or complexity just for expediancy's sake, I love C the most, for it is the most efficient (fast, using less memory, etc.).

To make a comparison to poetry: Java is Ginsberg and C is Eliot. Both of whom I love, but they are different styles. Ginsberg is the Jazz musician of poetry - creating crazy yet haunting melodies by going "off the map" if one wills in terms of traditional styles. Eliot is the baroque musician of poetry - using the fewest notes to create the greatest effect - precision is the key word here - no room for an off-note here or there but every note having a purpose. Both have their place. I love Jazz. But in terms of aesthetic efficiency, baroque has something to be said for it. Ginsberg is poetry's Jazz - wild, haunting, all over-the-place in a good way. Eliot is poetry's baroque - precise, haunting as well if more in a subtle way, and always having a precise direction or purpose.

Well, Java is the Ginsberg / Jazz of this analogy. It is easier / quicker to mess around and improvise and come up with a Jazz tune. It takes longer and it is more painstaking to come up with a baroque melody. Both are great and have their place. However, while I would use the quicker thing to come up with something on a deadline (Java / Jazz) there is a certain satisfaction to be had with taking longer and having to put more effort in order to produce precise, efficient, parsimonious code, and by parsimonious I mean not wasting any memory or CPU cycles, but having each bit of memory serve a purpose, just like each note of a baroque piece or each line of an Eliot poem has a precise purpose and taking one line out or one note out would ruin the whole thing.

So, while I still would use Java probably the most, I find a certain nobility in C, much as while I might probably listen to Jazz (or its descendants) the most, I find a certain nobility in baroque, and whereas I love and relate very much to Ginsberg, there is a certain appeal in Eliot's ability to say so much with so little that will always hold an attraction for me.

This is why the above article I came across, in which a computer science professor is talking about using, not even Java, but JavaScript for goodness sake, as the first language to teach students, is so tragic. Like I intimated before, if I had to do it all over again, I would have studied C before I even got into Java. That would have taught me correct principles and just a better "philosophy" of programming. As it was though, I was lucky. I worked with a math PhD who was a C++ whiz, a guy named Dr. Mark T. Lane, Chief Scientist at what is now mobi (mobicorp.com) who imparted to me the basic concepts of efficiency and attention to detail that I could never have gotten from the Java world, so, although it was later that I seriously began to study C, even early on I had some of those benefits, for which I will always count myself lucky and grateful.

But not everyone is going to luck out like me and get to work with such brilliant folks. I can only feel sorry for those aspiring computer scientists who go to a computer science program and get freaking JavaScript as the opening silo in their introduction to the world of programming, and I can only feel contempt for those professors who would advocate such a fool's errand.

When I was a kid, I loved this old 1950's teen sci-fi novel called "The Forgotten Star" featuring a character named Digby Allen who travels to the 50's version of a moon base and a Mars base, and eventually lands on Eros, an asteroid. Turns out in the book the asteroid is a space ship and inside are people from another planet (from a "forgotten star") who long ago have forgotten the knowledge that propelled them into space in the first place. The interior of the ship has a simulated earth-like environment, with a sky, fields, etc., and these people live like primitive savages, in huts, etc. not knowing there is a world outside the interior of their space ship, not even knowing, for that matter, what a space ship even is. They have a cool contraption which can convert atoms into anything asked for, so they get their food from that. The contraption (as near as I can recall) would basically take atoms from space and convert them into the molecules for whatever the user requested, so I could say ask it for bread and it would give me bread. To these inhabitants it was like a magic thing, for they had lost the knowledge that went into producing that contraption to begin with. And I suppose the young space adventurer Digby Allen saves the day and brings them into the modern age, though now I forget just how that ended. But I will never forget the impression which the book had upon me - the concept, the very sad concept, of a people once-advanced who through laziness had allowed themselves to descend into ignorance and dependency upon technologies they could no longer understand.

I was reminded of this tragedy when I saw the above article. Already I had read essays about computer science professors lamenting that C / C++ is no longer at some schools taught, Java being the preferred language. And now, it seems we are descending yet another rung, with JavaScript now being the preferred language. What is next? HTML? How about just forget about teaching kids how to write code and teach them how to use point-and-click tools like say WordPress which does not require any code skills at all to at least be able to use the basics thereof.

If we go down this road enough, we will be in the "Forgotten Star" situation - able to use tools built in the past but not having the knowledge anymore to build those tools again. Because you can only create great Jazz if you also know how to play baroque. You can create mediocre jazz I am sure - hell, a chimpanzee, given enough time, also could. But you cannot play great jazz without the underlying principles that led to it. Neither can we expect great code to be developed without the understanding of the underlying principles which led to our current languages (like JavaScript) in the first place.

Oh, and one more thing, subverting a function into an "object" has its purposes in terms of being able to code things up faster, more easily understanding the architecture, etc., but here is a dirty secret that apparently contemporary self-styled computer science professors won't tell you: a mathematical function is not an "object", sweetheart. Because "objects" belong to "sets" which may describe computational functions, but are not the functions themselves.

Deal with it, Java cultists. :-)

Post reply on HN