Live data from Hacker News

John Resig: JavaScript as a First Language

ejohn.org

91–100 of 228 posts

Re: John Resig: JavaScript as a First Language

#91

All decent suggestions. I quibble with this, though: // Don't do this: function getData() { } // Do this instead: var getData = function() { }; The assignment is righteous, but by omitting the function’s name, you make stack traces more difficult to follow. Better this instead: var getData = function getData() { };

Yeah, I didn't get this either. What's wrong with:

    function getData() {}
    var getData = new getData();

Re: John Resig: JavaScript as a First Language

#92

Javascript is an absolutely horrible language to use for such purposes. There are far too many gotchas. See the following for numerous examples: http://stackoverflow.com/questions/1995113/strangest-languag...

Whenever I see a post about what to use as a first language I always think about how I learned, and am learning, how to program. Warning: long-ish story/rant ahead. My first class in high school was the basic Java 101. The teacher did not know anything more than how to draw UML diagrams and tell us to use for loops. He had been teaching the class for years and had no industry experience. I imagine 10 years ago he fig…

Yes, yes, a hundred times yes. My first language was Apple BASIC. Looking back now it is a horrible language (no while loops, only 2 character variable names, line numbers with GOTO as the main way of controlling program flow), but it was easy enough to get my hands wet and get the feel for programming. And more importantly, I got stuff done.

I certainly didn't learn any best practices or good programming style from BASIC, but I learned something far more important: That I loved programming.

Re: John Resig: JavaScript as a First Language

#93

Earlier quoted context omitted.

I struggle with this mindset. It probably makes sense for Khan Academy, but this industry (software development) needs fewer people who refuse to learn anything unless all obstacles are removed and the information is spoon fed.

Well, I grew up in a day when it was even easier. * Buy home computer (ZX81) * Turn on * 10 Print "Hello world" * run I don't think the instant gratification and ease of use did me any harm.

Right the technical stack has become daunting to the point that many cannot get the feedback so needed early on. Now days you either advanced with the technology, or you spent a significant investment of time to learn the trade with the intent of entering the field. The days of the hobbyist programmer have seen their peek until that changes.

Re: John Resig: JavaScript as a First Language

#95

Javascript is an absolutely horrible language to use for such purposes. There are far too many gotchas. See the following for numerous examples: http://stackoverflow.com/questions/1995113/strangest-languag...

Disagree... for example from the link: In JavaScript: '5' + 3 gives '53' Whereas '5' - 3 gives 2 That's just logical and obvious, since "+" is both numerical addition, and string concatenation, but "-" is only numerical subtraction, and the '5' starts out as a string. Every language has 'gotchas'. Doesn't really matter which you pick to learn first at all. The more important thing is that you don't give up. possibly…

I hate behavior myself, though it's probably because I learned Perl first, where there's a separate string concatenation operator ("." in perl5, "_" in perl6). I do wish javascript had that same separation so that "+" was always addition and not sometimes string concatenation.

Re: John Resig: JavaScript as a First Language

#96

Earlier quoted context omitted.

You may have a different perspective, but if I wanted to teach OOP to new programmers, Java would be the last language I would consider, not the first. It’s a fine language in a vocational setting where the objective is to graduate people for employment as Java programmers, of course. Scheme is elegant and small, and a traditional choice for teaching programming where functions are first-class objects. If you conside…

Agree with your opinion on Java/OOP. There do seem to be better places to start IMHO. If you had to pick one language to teach people who had never programmed before and you wanted to be able to demonstrate the basics of OOP, FP and other styles, then Python would be a good choice. (Disclaimer: I like Python quite a lot.)

I think Python is actually a pretty bad choice for function programming. It does ostensibly support it, but in practice I don't think anybody uses anything resembling purely functional style. For example, I don't think I've seen a single fold in the wild in Python where I see them in Haskell and Scheme all the time.

Could you imagine only introducing mutation halfway through the semester of a Python course? That's what my intro CS course did with Scheme, and it was perfectly natural and effective. Scheme also makes it very easy to see mutation as something different from definition--it has both define and set! which do different things. Python doesn't even differentiate between the two because it has a weird scoping model.

Of course, Scheme itself isn't a perfect functional language either. I found that pattern matching is extremely important--Haskell, mostly thanks to pattern matching, helped me internalize recursion much more than Scheme when I was learning the two concurrently.

Scheme is also a good language to teach about OOP because it divorces the OO part from the language itself. When I had learned about it in Java, I had assumed that an object system was inherent in a language. Scheme showed me that a very expressive OO system could be written on top of a language without the language supporting it in syntax.

Finally, it is very easy to adapt Scheme syntax to other paradigms. Could you reasonably write a logic programming language that looked like Python? I honestly don't know. On the other hand, making one like Scheme is trivial. Not only did we use a language like that in the same intro course, but we actually went over how to implement it.

Ultimately, I think Python is too complicated. Not in terms of being difficult to use, but in terms of just being a ton of different features put together. They may look similar, but they are still discrete ideas that do not naturally come from each other. Scheme, on the other hand, has a few core ideas and everything else is built from those. Just compare the grammars of the two languages to see what I mean.

Re: John Resig: JavaScript as a First Language

#97

Earlier quoted context omitted.

But, but, but, Dijkstra ! In all honestly, I started out learning BASIC on Apple IIe's, and have managed to become an okay programmer. I would support it as a learning language. That said, I don't know that BASIC's syntax is that much easier for beginners than javascript. I mean, there's no braces or semicolons, but a lot of the control structures are basically the same.

Dijkstra could be an asshat sometimes. BASIC is great because it teaches you that a computer can be made to do neat things by following a series of tiny instructions. It gives you that without you having to understand lexical scope, which is, I think, pretty hard to grasp for new users. Sure, every user will outgrow it, but that's fine . Tricycles are a shitty way to drive to work, but that doesn't mean you should ju…

The problem is deeply technical people will put for the effort to learn deeper languages so that leaves a majority of the candidates as being people who want to learn programming because they want to scratch an itch. That being said, BASIC is usually not the language or platform they want to scratch that itch on, more and more the web and mobile are where they want to deliver to. That being said, JavaScript becomes the better investment of time, due to the fact that it directly parallels their goals in learning programming in the first place.

More and more I am starting to think Objective-C and IOS may be a contender, while, Objective-C is technically more difficultly to get started in, the technology stack is a lot simpler, to be effective on the web, one needs to know HTML, CSS and JavaScript and then really and truly they need to know a back end language or Node.js to deliver a back end. Whereas Objective-C and IOS is a visual editor and code. The feedback loop is faster for IOS development than JavaScript development and I believe the feedback loop is very important to a certain population of would be developers. I have never tried to teach a non-programmer Objective-C and IOS dev so the above statement is loaded with assumptions. Please read it as such, but I am leaning towards trying it next time someone approaches me and wants to learn.

Re: John Resig: JavaScript as a First Language

#98
post #40

Interesting Idea. I know for me the way I learnt programming made me quite flexible and happy. Working the entire scale from functional to OO languages gave me a really good perspective for anything I face. I've learnt all the web stuff I use today completely on my own, but I use the foundation I learnt below. The "classic" academic programming languages I've learnt happened in this order. Basic -> VB -> Pascal (High…

I'm curious: which of the languages you listed do you consider "functional"?

Re: John Resig: JavaScript as a First Language

#99
post #34

I want to take this further still. Most JavaScript programmers already use a subset of the language and I believe that there is quite a broad union of those subsets that should resonate with the majority of us. Excluding certain parts of the language will lead to more robust code that is easier to reason about (and more fun to write), I claim. My attempt to formalize it is called "restrict mode for JavaScript" http:/…

I think Resig means to use JSLint throughout, which does something similar. Additionally, browsers already support "use strict" which is also a restricted mode. In short, plenty of people share your views on the matter (me included). The whole thesis of JavaScript: The Good Parts was basically that, and the book is one of the best on the language.

Re: John Resig: JavaScript as a First Language

#100

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 (…

I don't understand the (anti) hype about type coercion and the '==' operator. I get a faintly cargo-culty vibe from people when they talk about '===' vs '==', since the examples are usually very strange things that I never see in production. I'm not an expert in JavaScript but I've written a fair amount and a couple largish programs and I've never been bitten by a type-coercion bug involving '=='.

The weird subtle bugs I see are usually associated with me using "for (i in a)" for arrays instead of the more ugly C style for loop, which results in "i" being a string (which usually doesn't matter except when using "+" which is sometimes addition and sometime string concatenation).

So, is '==' really that bad? Has anyone seen (otherwise) well-written production code fail because of '==' vs '==='?

Post reply on HN