12 ms·
John Resig: JavaScript as a First Language
- absconditus 15y agoJavascript 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-language-feature?tab=votes&page=1 http://stackoverflow.com/questions/1995113/strangest-languag...
- maximusprime 15y agoDisagree... 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 there are languages that just make people want to give up, but I'd say perhaps they're not motivated enough to learn if that's the case. I started out on BASIC, and after a while I decided it was a piece of shit language and learnt assembly. But it taught me programming which is what I wanted to learn. I'm really glad I learnt BASIC first... essentially I learnt to swim really fast through syrup, and then switched to swimming in water. The good thing about javascript as a first language is that people can be programming in it immediately, in their browser. They have a built in REPL to help them, as well as a debugger, profiler, etc. They have numerous docs to look at, and if they go to any website they can check the source to see how it works. That's a big win.
- kevingadd 15y agoCalling your example logical and obvious is only logical and obvious if you're completely trapped within the JS mindset. It's the same as how people defend the absurd semantics of Visual Basic and PHP. It's fine if you like it, but to claim that it's objectively okay is just not supported by fact. It's also worth considering that even if every language has 'gotchas', some of them have far worse gotchas than others. It is worthwhile to choose a starting language that teaches the fewest bad habits and the fewest bizarre rules so that people can easily learn new languages.
- maximusprime 15y agoSee my comment below. It's not about being trapped in any mindset. It's about thinking logically. Either '5' - 3 results in an error of some kind, or it evaluates to 2. There is no other logical outcome. Javascript chooses to do the latter. I also disagree that starting language matters. It's like saying you need to have a steinway grand to learn the piano properly. Learning is about learning what not to do just as much, if not more, than what to do. Also if you learn to swim through syrup, imagine how fast you'll be when you try swimming through water...
- kevingadd 15y agoThe time wasted learning the quirky semantics and special rules covering each operator and data type in JavaScript could be better spent learning to reason about algorithms and data structures in a less confusing language. Not all learning is equal, and not all challenges are exactly the same. The claim that by hindering a newbie programmer's attempts to express themselves will make them more effective in a better language is ridiculous. Even if it's true, it's missing the point - your goal when teaching newbie programmers should be to teach them good habits and generally applicable skills, and most importantly, you want them to love programming. Having to memorize arcane minutiae and spend tons of time debugging problems caused by stupid design decisions is not going to make people love programming. JavaScript is tremendously accessible by virtue of its ubiquity, but that does NOT implicitly make it a good language for learning to program. Its numerous flaws and divergent implementations will drive away beginning programmers that might otherwise learn to love programming if presented with a better environment.
- absconditus 15y agoPlease do not downvote maximusprime's comments just because you disagree with them.
- mquander 15y agoYour ideas about what is "logical" are completely arbitrary. Look, I can make up rules too: * '5' - 3 should return '5', since it's the string '5' minus all the instances of the character '3' in it. There is no other logical outcome! * '5' - 3 should return an empty string, since it's the string '5' with the last three characters removed. There is no other logical outcome! * '5' - 3 should return '2' -- since we started with a string, the result should turn back into a string. There is no other logical outcome! * '5' - 3 should return 50, since the only logical way to do math on a character is to take the UTF-8/ASCII value of it and then do the math. There is no other logical outcome! * '5' - 3 should return undefined, since subtracting from a string typically doesn't produce a reasonable result. There is no other logical outcome! You have provided absolutely no rational basis for discriminating between the merits of these choices, so your claim that Javascript's choice is one of exactly two "logical" ones is bizarre. If you think Javascript's choice is better, give a reason why it's better, don't just say that it's better.
- barrkel 15y agoIt's logical and obvious if you already know the language; otherwise, it's perverse. I had to read your comment (the initial edit of it) twice to be sure you weren't being sarcastic.
- maximusprime 15y agoNo it's not. Logically, the only other thing that could happen is for an "error" or "exception" be thrown when you do '5' - 3 There's really only 2 choices. Either convert the '5' to a number and subtract, or throw a hissy fit because it's a string. That's not perverse. It's very logical.
- rprospero 15y agoYou're looking at the wrong side of it. The subtraction does behave in a perfectly logical manner. The problem is that, given the the behavior of the subtraction operator, the addition operator's actions are illogical. Specifically, I'd argue it's perverse because it breaks commutativity: '5' + 3 - 3 != '5' - 3 + 3 The logical approach would be to only assume that '+' is a string concatenation if both operands are strings and otherwise type coerce into numbers. Then: '5' + 3 = 8 '5' - 3 = 2 To someone who doesn't code Javascript for a living, the above seems like a far more consistent and useful behavior.
- maximusprime 15y agoThat would be ridiculous because then what would 'hello' + 1 equal? Everyone would expect it to equal 'hello1'.
- rprospero 15y agoExcept, not "everyone" would expect that. I'd expect "hello" - 1 to return NaN, since you can't perform numerical subtraction on something that isn't a number. That's exactly what Javascript does. In the same way, I'd expect "hello" + 1 to return Nan, since you can't perform string concatenation on something that isn't a string, and you can't perform numerical addition on something that isn't a number. Edited for clarity
- hello_moto 15y agoThat'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 less confusing.
- maximusprime 15y agoOK 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 explanation, and it's not terribly hard to get past.
- barrkel 15y agoThe issue isn't explaining it. The issue is it needing an explanation at all.
- absconditus 15y agoYou picked one of a dozen or more examples from one list of problems with JavaScript. Of course this particular example can be understood by those of us who already have programming experience. JavaScript's type coercion is likely to be a big stumbling block for many beginners and Resig specifically points this out.
- __david__ 15y agoI 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.
- bradleyland 15y agoOne might say the same about the English language, yet it is taught in classrooms all across the United States, despite the fact that the U.S. has no codified national language. English is the de facto national language, but nothing more. So why Javascript as a first language? Probably the best argument is that it has the widest reach of any programming language in use today because Javascript will run in any web browser on any platform. It is the closest thing to a universal programming language you'll find today.
- kevingadd 15y agoIf widest reach is your criteria, Java and C would also be equally good choices. Unless the web browser is special in some particular way that makes it 'more worthy' than other execution environments?
- maximusprime 15y agoEveryone already has a browser, which includes a profiler, debugger, REPL etc. Not everyone has a c compiler or JDK, or wants the hassle of having to set them up just to start learning.
- kevingadd 15y agoThe claim that everyone has a profiler, debugger and REPL is blatantly false. Only a subset of commonly available desktop browsers include those features, and out of those, only recent versions do. Mobile web browsers don't include any development or debugging tools. The cost of installing Visual Studio or Eclipse is pretty small considering that you only have to do it once. Compare that with the cost a newbie programmer pays every time they use the comparison operator or the arithmetic operator and they now have to consult their reference text to figure out what the operator is going to do and whether they're using the right operator. If your goal is to lead someone into a lifetime of programming and help them enjoy it, choosing a language in order to avoid a pesky 15 minute setup cost for a compiler is tremendously short-sighted.
- 15y ago
- bdfh42 15y agoI disagree as well - it is a very capable language with some very friendly features. Also it is very applicable for many new programmers - an all round good choice.
- asktell 15y agoEvery language has its gotchas. Even assignment operators are kind of a gotcha. If you're coming from a basic math background, and have no programming experience, then the expression "a = 15; a = a + 1;" would be confusing in any mutable language, because assigning a value to a variable is not equivalent to stating the equality (identity) of both sides.
- brlewis 15y agoYou're right in that even Scheme, which evolved with teaching in mind, has gotchas. However, the Racket folks made "student languages" that specifically exclude gotchas, so DrRacket is as close as a student can get to a gotcha-free environment.
- maratd 15y agoI have to agree. BASIC is a far better option. It will obviously never be used for anything, but it will teach the student basic concepts like output, input, variables, etc. These are not simple concepts for somebody starting from zero!
- jordan0day 15y agoBut, 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.
- munificent 15y agoDijkstra 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 just put your toddler behind the wheel of your car and let him go.
- kls 15y agoThe 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.
- DrHankPym 15y agoWhatever, Javascript is the easiest language to get started on. No installing a complicated IDE. No configuring a server. Nothing is required except for a browser! If anything, it's the best language for such purposes: getting started.
- showell30 15y agoI don't think Javascript's availability in the browser should be a major driving concern. Browser-based REPLs and editors are getting better and better. Two examples: http://repl.it/ http://repl.it/ and http://cloud9ide.com/ http://cloud9ide.com/.
- phzbOx 15y agoAlso, as stated by John, JSlint will be used. That by itself avoid the big majority of JS' gotchas. And IMO, C++ has way more gotchas than Javascript and that doesn't stop universities to teach it as first language. In fact, I think the first language is not just about giving a strong foundation but also give students the chance to find a good internship. So, with that logic, even though I enjoy hacking with Scheme, I'd feel bad to teach that to students who will try to find an internship and writing on their resumes "Scheme" while other universities students would have "C++/Java". And, please, before your argue that a language can be learned or something else, have in mind how companies recruit and parse resumes.. they often just search for a keyword. Now, one might say that you don't want to work for a company who does that, but then, you have to start somewhere in your first internship. Thus, I like JavaScript as a first language; not because it's the easiest to learn but because I believe it gives a strong foundation but also gives students the ability to find a good internship.
- Stormbringer 15y agoWell, I wanted to know what IDE JSLint was an expansion for, so I did some poking around... it's an online tool. Meh #1. Next up I thought I would take a snippet from the linked stackoverflow discussion and see what JSLint made of it: 127.0.0.1.toInt(); And... it complained So I did this: var = function() { 127.0.0.1.toInt(); } And it complained (yes, there's a typo) var foo = function() { 127.0.0.1.toInt(); } And... it 'compiles' fine, no complaints. So I thought I'd push the syntax tree button to see what was going on and it tells me: Tree: "" Which is less than spectacularly useful. Oh, I went back and hit the JSLint button again and now it givess me lots of errors for the above code. Including, but not limited to complaining that 127 occurs in column 1 instead of column 9. But then I try to enter a tab at the start of the line to achieve proper indentation... and of course it doesn't work because it is in the browser and so tab just goes and selects the next control. Sensational. If I had to enter all my indentation as spaces, by hand, I'd conclude that the Professor teaching this was a colossal idiot.
- malandrew 15y agoWhitespace can be a huge gotcha for novice programmers. Hard spaces? Soft spaces? New lines?
- wwweston 15y agoI suspect Mr. Resig is familiar with the potential gotchas, and maybe even has his reasons for still believing it's still worthwhile. For my own part, as someone who regularly taught high school seniors (and other non-programmers) various programming languages (Pascal, Perl, Prolog, JavaScript, and Java) over a good chunk of the 1990s, I have to say that JavaScript worked out pretty well, possibly even the best of the bunch depending on what your goals were. Prolog had some real strengths. The combination of accessibility for some simple applications with the power and conceptual depth of the logic paradigm tended to put more or less smart people with no previous experience on the same footing with those with some experience. But JavaScript seemed to be the best of the bunch in terms of balancing accessibility, speed from which students could get to doing something with everyday practical use, and available depth. And despite the fact that those of us who were teaching were just learning and coming to grips with some of the "bad parts" ourselves (because how many people really knew JavaScript in the 1990s, right?), everybody got stuff done anyway.
- showell30 15y agoI can see the advantages of JavaScript over Pascal, Perl, Prolog, and Java. Did you ever try Python? What are your thoughts on Logo, Karel, etc.?
- wwweston 15y agoI'm a little down on things like Logo and Karel, partly because I prefer things that are more general, and partly because even in the niche I might use them, my judgment is that Scratch is better. :) I didn't try Python myself until late 2001, and by then, I was already more or less out of education, so I didn't get to try it out on anybody else. But if I were guessing, I think the language itself would probably work pretty well for most students, possibly somewhat better than JS. Not sure how big the advantage would be, though (like I said, we really didn't struggle with JS's warts much), and I think the broad target for JavaScript's use give it something of an advantage too. This would vary by domain, though. If I were trying to teach a number-crunching focused class, for example, Python would probably move way up my list.
- zackzackzack 15y agoWhenever 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 figured out all the questions he was going to ask and learned just enough to explain the really difficult ones. He was not a zen master LISP programmer who had glided down from the plane of Forms to enlighten us. But I started to learn programming because of him. He knew what he knew and he had his presentation down. I didn't know how to program so anything was better than what I was going with. He explained terms and ideas in the most stereotypical of ways. But they made sense. In a way, he passed off his framework of knowledge to those who cared to take it. It was incredibly mind expanding at the time. And so I had this little ball of specific domain knowledge. I wanted to be able to do cool stuff though on my website though. Java wasn't quite there yet, couldn't do all the things I wanted it to do. So I picked up Javascript from W3 schools online. It was terrible, awful Javascript that I have purposefully forgotten. But I could make my pages interactive, I could impress my friends. My little ball of know how was growing and expanding. I kept at it and started seeing how Java "sucked" and why Javascript was the One True Language. New ideas like functions as variables, easy to run scripts, interactive webpages, they all got added on and replaced old less useful ideas from Java. Pretty soon after that I started actively learning Mathematica in college. The whole IDE is just lisp with some mathematical lipstick, but I didn't know that at the time. I started thinking of how to solve problems with lists, how to use IDE's, and reading and writing to files so I wouldn't have to redo everything each time. I had programs that wouldn't run in less than a second which made me really aware of what I was writing and how to optimize things. And the story just keeps going and going on like that. Common lisp with Emacs last winter because of PG. More Mathematica and jQuery during last spring and summer because of an Internship. Node, Haskell, Clojure, Python during this past fall for enlightenment. And now R and, maybe, Ruby/Rails during the winter because I have ideas I want to make happen. I'm by no means a professional, but I know enough to shoot the shit with the CS majors and randomly drop into tech meetups (What up Cinci.rb!) All that sprung from a high school class taught by a standard teacher on a shitty language that I don't ever want to touch again. And so when people talk about first languages and why X will be an absolutely horrible language to use to learn, I zone out. Every language is going to be a horrible first language. All of them. I don't care what arguments you make about js gotchas or Python's batteries included or why scheme is more beautifuller than common. If you don't know how to program, learning how to program is going to suck. Period. Maybe learning C++ first isn't the hottest idea, but at some point you have to grit your teeth and go "Programming is hard." So I applaud Resig's and Khan Academy's use of javascript. Not because I love javascript, but because I know they are going to doing an amazing job presenting the tiny balls of programming knowledge to kids across the world. They could have picked most any mainstream language they want to present these ideas with and I would still be excited by their ideas. All that matters is how they plant the seeds. If they can stir up a kid's desire enough to get over the "ARRAYS SUCK. FOR LOOPS SUCK. WHY WON'T MY PROGRAM COMPILEEEE." and learn the next language or build the next project, then they have done an amazing job and good for the world. tl;dr Programming is hard, every language has it's own use, waffling about the choice of languages isn't going to teach you what you need to know any faster.
- yuvadam 15y agotl;dr - they picked JS due to its "ubiquity, desirability in the larger workforce, lack of prior installation requirements, and ability to create something that's easy to share with friends" I find that explanation disturbing. Why not start from a language that teaches the basics of the common programming paradigms, such as OOP (Java) or FP (Scheme)?
- catshirt 15y agofor new programmers, the entry barrier for those languages is significantly greater than javascript. people don't quit learning programming because they're not learning OOP- they quit because it's inaccessible.
- hello_moto 15y agoWhile that may be true (it's definitely take more steps to get your feet wet in Java), my experience with JS is otherwise until Node.JS arrives. I just don't have time to twiddle with document object (DOM API) just to see results.
- ricardobeat 15y agoSome people dont have time to twiddle with a crapload of OO abstractions/interfaces just to see results either.
- hello_moto 15y agoSome people don't use that at all with Java for a simple academic assignment. Some people don't have time either to deal with scoping or the right way to do prototype in JS. We all should use QBasic...
- rgbrgb 15y agoAgreed. I also think that the reason a lot of us stuck with programming was because we loved the feeling of making something fun that we could play with. This is arguably a lot easier to do from the start with JavaScript than with Java or Python because one of the main applications of JavaScript is visual manipulation. Generally the first Java or Python programs you make are used from the command line. I think that when someone's starting out with something like programming, you want to put fun before "educational value" (correct OOP design principles) to give them that itch. I think using something like d3.js or processing.js would be a good place to start: http://mbostock.github.com/d3/tutorial/circle.html http://mbostock.github.com/d3/tutorial/circle.html That's a FUN tutorial that could easily dovetail into a larger project.
- bdfh42 15y agoOnly thing I am not sure about is the focus on "===" - I think it is a pain and fails in too many instances to do what the programmer would expect.
- OriginalSyn 15y agoStrict Equals Operator (===) does exactly what I expect and that is no funny coercion or guessing, two objects I'm evaluating have a 1 for 1 likeness, no more no less. How is that confusing?
- ryanbraganza 15y agoNaN !== NaN Apart from that, I agree.
- OriginalSyn 15y agoSure but at least the spec is clear that NaN always returns false.
- jQueryIsAwesome 15y agoThat is the reason for the existence of the function isNaN. Plus, NaN returns a generated object, so that result is expected ({}) !== ({})
- tikhonj 15y agoThat's not really language dependent--that's how floating point numbers always work. And with good reason--there are actually a ton of different NaN bit patterns in the floating point standard. I think anything where the exponent is all 1 is an NaN (except maybe for infinity--I don't remember the exact details). The point is that two completely different patterns of bits can be NaN.
- ricardobeat 15y agoThere is nothing unexpected in strict equals behavior, quite the opposite. This is unexpected for most: '[object Object]' == {}
- city41 15y agoOn a similar note, I've been in the process of creating a JavaScript library[0] that is strongly inspired by _why's Shoes. My intent for doing this was to create a DSL where one can whip up webapps very quickly. But I'm also now looking into essentially recreating Hackety Hack on the web, and maybe having a simple way for very young people to get a taste of programming. Sadly JS isn't as DSL friendly as Ruby. [0] https://github.com/city41/Joeys https://github.com/city41/Joeys
- IanMechura 15y agoI have argued JS as an intro language for years. My main argument has been not based on language features which I feel are unimportant in forming a young programmers mind but rather in the complete lack of barriers to getting started. Take for instance python( my personal language). At a minimum you need python installed on the computer. Then you need to deal with issues such as the PATH and PYTHON_PATH. Also you have to understand package naming and import scheme. With JS you only need a .html text file on the desktop. Write code, save, double click, results. It is something that anyone who has even seen a computer can understand. Particularly if the student has not had much experience in computers in general, things like paths, imports, file system knowledge and command line interfaces can be a barrier to learning code. You will eventually need to learn all of the things above to be a programmer but why bore a child or teenager with the details of a file system or command line when you could be showing them how to code animations on a web page. I will admit, that struggling with run time environment, compilers and class path issues made me into better engineer sooner, but I already had a passion for what I was doing.
- pbsd 15y agoIn the particular case of python, I see none of the problems you mention. In pretty much all Linux distros, it already comes installed and ready to use (i.e., just execute it, no need to know paths or anything). The same happens on Windows, once you run the installer; there you can, too, just edit and double click it. All you need is a .py file on the desktop.
- olov 15y agoI 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://restrictmode.org http://restrictmode.org and I laid my case here: http://blog.lassus.se/2011/03/case-for-restrict-mode.html http://blog.lassus.se/2011/03/case-for-restrict-mode.html . Would be curious to hear other thoughts about it.
- tikhonj 15y agoI 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.
- olov 15y agoThe major difference is that JSLint as well as "the good parts" focus on a subset that can be verified statically (before running the program) while restrict mode sanitizes operator semantics that must be verified dynamically (when running the program). I like the few changes strict mode did except for one thing that breaks compatibility in an unfortunate way (this is bound to the primitive, not the boxed number). But we should take all this much further. More important than anything I'd like us to start talking about sane subsets of JS more, and stop limiting ourselves to what one author considers "good" because quite frankly, _that_ subsets still contains a whole lot of awful stuff.
- j45 15y agoInteresting 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 school/first year Uni) --> C --> C++ --> Java Too much code out there rarely exists entirely on the OO or functional end and projects are often heading towards one or the other. Once I had traversed this, I was easily able to pick up .NET, whether any one of the .NET languages was OO or functionally based (Foxpro, or whatever). Javascript was interesting because it extended from Java for me. I really do feel that programming needs to be learnt at the mathematical/computational level of functions for clear process/analytics and then learn the benefits of using functions in an OO world. Be interested to hear what order others learnt
- jashkenas 15y agoFor 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 (x === y) {` in JavaScript. John's note about `x == null` being the only useful application of double equals is quite true, and something that CoffeeScript provides in the existential operator: `if x?` Falsy Values: The existential operator helps you ask the question "Does this value exist?" (Is this value not either null of undefined?) ... which covers many of the use cases for having saner falsy values in JavaScript. For example, instead of JS' `if (string) {` ... where the string may be the empty string, you have `if string?` Function Declarations: JavaScript having function declarations, function expressions, and named function expressions as three functionally different things is indeed a wart on the language. Especially so because JavaScript having a single type of function is one of the beautiful aspects that shines in comparison to languages like Ruby, where you have methods, blocks, procs, lamdas, and unbound methods -- all of which behave in slightly different ways. CoffeeScript only provides JS's function expressions. Block Scope: This is a tricky one, because unfortunately it can't be emulated in a performant way in JavaScript. So all that CoffeeScript can provide is the "do" keyword, which immediately invokes the following function, forwarding arguments. So, if a regular "for" loop looks like this: for item, index in list ... A faux-block-scoped "for" loop would look like this: for item, index in list do (item, index) -> ...
- danmaz74 15y agoAs matter of fact, while I was reading the post the first that came to my mind was how much the recommendations reminded me of the CoffeeScript introductory page...
- latchkey 15y agoThese 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 the same thing in JS is far more boilerplate and much harder to explain why you have to fight the language to accomplish something as simple as a class. Sure, you probably shouldn't learn CS without at least a general understanding of JS, but I definitely think that CS is the next logical step for the second semester.
- njonsson 15y agoAll 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() { };
- apalmblad 15y agoI definitely agree with your point about stack traces - I've used var x = function(){} for some projects, but have found in practice that named functions are very much worthwhile when dealing with stack traces? What's the benefit of var x = function x(){}? Is it just illustration that functions can be assigned to variables?
- lowglow 15y agoYeah, I didn't get this either. What's wrong with: function getData() {} var getData = new getData();
- ludwigvan 15y agoI have to disagree. Part of the reason is that it teaches the concept of anonymous functions. The main reason, though, is the anonymous function case makes it more apparent that the function is an object. Separating the RHS from the LHS is significant. The right side creates the object, the left side binds it to the reference. Much like `var a = 3`. It is the assignment that makes it interesting for people that I teach JavaScript. Consider the following, can you do that in a less function-oriented language like Java easily? var getData = function () {}; var mygetdata = getdata; getData("foo") mygetData("foo")
- edtechdev 15y agoThe language picked doesn't matter as much as what you can (quickly) do with it. But personally, for high schoolers, I would start with Scratch ( http://scratch.mit.edu http://scratch.mit.edu - scratch 2 will work in the browser) and then perhaps Processing.js or a game development site/tool like http://html5.yoyogames.com/ http://html5.yoyogames.com/ http://www.scirra.com/construct2 http://www.scirra.com/construct2 http://www.playmycode.com/ http://www.playmycode.com/ http://pixieengine.com/ http://pixieengine.com/ There is actual research on how to teach kids programming and computer science concepts. http://csunplugged.org/ http://csunplugged.org/ doesn't use any software at all to teach concepts like binary numbers, sorting, etc.
- arctangent 15y agoAny languages which people unfamiliar with programming can get immediate (hopefully positive!) feedback with in under 5 minutes is ideal. Some languages do not pass this test :-)
- agentultra 15y agoI think it'd be more apt to choose something like Racket. It has all the desirable characteristics the author finds attractive in Javascript. It is an integrated environment and includes libraries and extensions for teaching basic programming. Unlike Javascript it isn't married to the browser (and by extension, the DOM) and doesn't suffer from a variety of syntactical discrepancies. It even comes with a free book for teaching the fundamentals of computer programming and computation. http://docs.racket-lang.org/quick/ http://docs.racket-lang.org/quick/ Update: All of the desire-able characteristics except for being a resume-search keyword with a high hit frequency. IMO, learning how to program and getting a job are orthogonal.
- tantalor 15y agoI once considered teaching JavaScript as a first language, but the absence of synchronous user input made me reconsider. For example, there is no way to do this in JavaScript, > var line = read_line(); Of course you could use the prompt() function, but that only works in the browser, and it's an ugly hack.
- danmaz74 15y agoWhy is prompt() ugly? On the contrary, I think that for kids who grew up in GUIs, it is much more familiar and less intimidating than a prompt.
- tantalor 15y agoWith a standard prompt, you can see the previous output from the program and user input. But a popup window has no context, no history. Of course that's just my opinion. If it could help teach kids good programming skills then it should be used used.
- peterbraden 15y agoChrome, Firefox and Safari all have built in REPLs
- tantalor 15y agoREPL is not the same as standard streams (STDIN, STDOUT). You can build a REPL with standard streams, but you can't use a REPL like the WebKit console as standard streams. Where is your STDIN?
- danmaz74 15y agoThat's true - if your program works like a conversation. That's not always the case ;) You can give all the needed context by updating the page when needed.
- ZenPsycho 15y ago"Synchronous I/O Considered Harmful" or "I once considered teaching JavaScript as a first language, but then I found out it has no GOTO statements"
- potch 15y agoThe hopeful part of me loves this because I truly believe the web stack is a truly democratizing technology, and has tremendous accessibility. The cynical side of me also loves this because I like watching PL bikeshedders rage.
- arctangent 15y agoIf 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.
- danenania 15y agoThat'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.
- arctangent 15y agoI didn't claim that C was the best language for learning how to program. John Resig's article above is about "teaching Computer Science" rather than teaching students how to program. These are very different things. That's why I recommended C - because it is very much a language that will teach the theory about how computers work. I agree that there are other languages better suited for learning how to program.
- danenania 15y agoOk, I see your point. But perhaps one can learn Computer Science much more efficiently after already knowing how to program? It doesn't seem likely that you'll be very open to learning data structure design and asymptotic complexity when you're still wrestling with for loop syntax, the difference between assignment and reference, what the hell recursion is, etc. You have to learn to walk before you can learn to run, and while jumping in the deep end may work for some, I'd guess most would find a more programmer-friendly introductory language a quicker path to comprehending basic CS concepts and would subsequently be in a much stronger position to tackle C.
- eonwe 15y agoTo quote Dijkstra: "Computer science is no more about computers than astronomy is about telescopes." While learning how computers work has its place in computer science, I think computation and manipulating information are better teached on a language where you can concentrate on those concepts instead of secondary issues such as memory management.
- deleted 15y ago[deleted]
- angelbob 15y agoI am so looking forward to a huge army of newly-trained programmers who view prototype-based inheritance as the default and classical inheritance as weird. Similarly, I look forward to a whole set of various modules and libraries to graft prototype-based inheritance onto existing languages like Ruby... cackle
- kenjackson 15y agoUnfortunately 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 build from there. BTW, are there any prototypal languages that support multiple inheritence -- you can create an object from a set of an arbitrary number of objects?
- anon1385 15y agoIn 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-Inheritance http://www.iolanguage.com/scm/io/docs/IoGuide.html#Objects-I...
- kenjackson 15y agoNice. Thanks. How is it that I've never looked at the IO language before? Some reading for tonight.
- angelbob 15y agoThat is, people who understand class-based inheritence have a very small leap to get prototypal inheritence. I used to think that, and then I watched a lot of people try. It's harder than you think. I used a networked server used primarily for MUDs called DGD (Dworkin's Generic Driver) for awhile. The most common MUD libraries for that use prototype-based inheritance. I know mine (based on Skotos) supported multiple prototypes. I think Skotos did as well. It was interesting - it was pretty easy to explain the prototype-based inheritance to non-programmers. It was much more difficult (usually) to explain it to programmers. I don't think it's as much "class-based inheritance is good preparation and prototype-based inheritance isn't" as you think.
- laconian 15y agoI'm a fairly experienced programmer and JS still drives me up the wall. The implicit casting and inconsistent operator overloads have led to many unhappy visits to Stack Overflow to see just WTF my browser is doing. I can't imagine the experience being any better for newbie programmers! Even simple things, like bitwise operators, are basically broken unless you take care to ensure that your variables are coerced to whole numbers, because all numerics are f%!#^&ing floating point numbers... Given that the language is such a mess, I think it would induce a new programmer to compartmentalize their JS learnings as a bunch of special case hacks instead of discovering broad language principles that are applied consistently across the language.
- cageface 15y agoPython seems to me like an infinitely better choice. Every language has its warts but bringing up a new generation on a language that even the author admits was a quick and dirty hack takes "worse is better" cynicism way too far.
- showell30 15y agoI like Python too, and the current CS curriculum on Khan is mostly, if not completely, based on Python.
- RyanMcGreal 15y agoThe secret to enjoying Javascript is to stick to the non-brain-damaged subset identified by Crockford in his Javasript:The Good Parts. For example, if you always use the triple-equals comparison operator, you don't have to worry (as much) about implicit type coercion.
- extension 15y agoYeah, JavaScript will break their impressionable young minds. But you know what? Programming in general will break their minds. Programming is fucked up from any perspective. If they learn a good language first, they will go crazy trying to figure out why nobody is using it. Might as well teach them a language that lets them get stuff done in the real world, while preparing them for the ugliness ahead. They can learn the good language later.
- firefoxman1 15y agoBefore I even read the article, I was pretty sure that with a title like that there is going to be lots of debate from the CS people. They do raise some good points, but here's my 2 cents. Besides a little bit of VB in highschool, JavaScript was my first language. I mainly learned through two books: "The Good Parts" which was a nice overview, and "Object-Oriented JavaScript" a really underrated book that covered every little piece of the language, even those weird parts like block scoping and falsy types. Having never learned anything about classes or inheritance, prototypal inheritance was kinda hard to grasp, but I eventually found it pretty amazing. I think a loosely typed language is much better to learn on too. That way you can learn the big pieces of the language then later get into the little things like typing. That's just my experience, but I'm really glad JS was my first language.
- sirchristian 15y agoI support using JavaScript as a first language. If for nothing else there are millions of code snippets just a short "right click -> view source" away. Granted these may not be the most ideal examples, but it enables tinkering. One thing that always frustrated me about the "easy" languages to learn (Python, Ruby, etc) is you still have to figure out how to download something and then the first programs just write out text to a console window. It's hard to see at first how learning one of the "easy" languages translates into building cool stuff. Having access to such a vast array of samples, plus something like Khan Acadamy teaching the "right way" is just awesome to me.
- noelwelsh 15y agoReading this I reminded of the saying "when you have a hammer everything looks like a nail". It's not surprising to see John Resig leaning towards using Javascript. There is a lot of research into teaching introductory programming. It would be nice to see some of that referenced in making the decision. You know, base it at least in part on science rather than just opinion.
- glenjamin 15y agoAm I the only one who thinks that lack of block scope is only confusing for people who are used to it? I don't think it'll affect JS-as-a-first-language people.
- its_so_on 15y agowat. This is like teaching postscript as a first language. almost literally.
- its_so_on 15y agothis was downvoted. Let me make the analogy clear. Javascript is sent by a server to a rendering engine (your web browser), usually a part of displaying a page, though of course also as part of interacting with it. Postscript is sent by a (print) server to a rendering engine (in a printer), as part of typseting a page. It is a Turing-complete programming language, but that's no guarantee it won't make your eyes bleed. The existence of things like jquery "on top of" javascript are really no different form having Microsoft Word or Open Office / Libre Office there to 'print' your postscript file. Like it or not, neither javascript nor postscript are: - Systems languages. - Desktop application languages. (As Java can be). - Low-level language suitable for writing drivers. - Low-level languages suitable for writing network protocols. - High-level languages suitable for prototyping very large, complex data structures and relationships - High-level scripting languages suitable for abstracting away incredible sophistication and power and letting the user program in a very high level mode. - Robust and scalable applications languags, suitable for putting in a version control system and having a team of fifty iterate on it They're niche, domain-specific languages, like a Perl regex. Would you suggest anyone's first language be the regex Perl uses? Obviously not. Appropriate first languages are anything from: * A fake language like Turtle Logo * An almost-fake academic language like Pascale * An "electrical engineer" approach nuts and bolts introduction: assembly. * A low-level systems language, C, or C++ * A high-level scripting language: Ruby, Python, Perl * An interpreted systems language: Java. * A markup language: HTML and CSS * No language. Configuration files for nginx and other things. etc etc. Very, very low on the list would be something like Javascript. This would be akin to editing Adobe Illustrator files in a hex editor. Sure you could end up with an image and an understanding of vector art, but, why in the name of God would you try to learn those concepts in that way?
- leptons 15y agobecause none of those languages can be compiled and run instantly with any web browser, anywhere on the planet. you can write some javascript and run it right now, without even opening text editor. javascript:alert('hello world') in your address bar. It's that simple. Alerting hello world is not much of a first program, but i'm just illustrating how dead simple it is to get someone to write a line of javascript and see results. Most beginners these days aren't really interested in your 'robust and scalable applications'. That is not where beginners need to start. At least if they start with javascript, they can see some value in continuing to learn programming. If that brings them to 'robust and scalable applications' then they'll migrate away from javascript if need be. But to say that javascript is far down on the list of first languages is just an asinine reaction that shows you don't really comprehend the problem of getting people to learn to program.
- deleted 15y ago[deleted]
- tolmasky 15y agoAnyone else taught Karel++? In high school they taught us: Pascal -> Karel++ -> C++ Then the new AP tests came in and the switched to C++ -> Java, which seemed very silly to me (C++ as a first language???)
- showell30 15y agoMy intro CS class in college started with a week of Karel. It was incredibly fun for me, but I can't vouch for it as a first language, since I had already learned Basic and Pascal in high school. (Yep, I'm old). Karel variants are actually very challenging in a way--the syntax is dead simple, but its lack of constructs forces you to be fairly clever.
- jebblue 15y ago>> a function is actually an object and can be manipulated as such A function is an object? I also read down the comments and saw something like '1' + 2 prints '12'. ROFL
- neduma 15y agoIo will do. I do not think this would be optimum for new comers even thought i’m a die hard fan of JavaScript. You can teach ‘Io’ language instead of JavaScript which has all kind advantages you have mentioned and which has few set of parser rules that would be easier for new comers. JavaScript can be a icing on the cake.
- capex 15y agoTo introduce kids to programming, there is nothing better than Javascript. Instant gratification & no installations. It'll be an easy entry into harder concepts. But the way you enter does matter.
- Stormbringer 15y agoI loved this comment: "The policy when I went to school was to start everyone with LISP. That way, if they never got past CompSci 101, they wouldn’t be capable of impersonating a real programmer. " -- Dave Edelhart
- malandrew 15y agoI'm a full-time javascript developer and entrepreneur myself, but I'm wondering why you don't consider Scheme instead, basing the course on the How to Design Programs v2 curriculum? The people behind that book have spent a lot of time thinking about how you teach programs to people. More importantly, they focus on problem decomposition and concepts that provide a great foundation for growing. The reasons I can see for using Javascript first is because everyone has a runtime available at their fingertips (M. Haverbeke's approach of including the console was great.) and because people can immediately see the utility of the language to real world needs. But does Javascript provide the best foundation for future concepts? Does it teach good habits both mental and in practice? Ref: The Structure and Interpretation of the Computer Science Curriculum http://www.ccs.neu.edu/racket/pubs/jfp2004-fffk.pdf http://www.ccs.neu.edu/racket/pubs/jfp2004-fffk.pdf
- mycodebreaks 15y agoWell, I would like to teach kids assembly language first. That's how my generation did it. Second language should be C. That's how you know how your program actually runs on a computer. You know what memory is, and how it is used.
- more_original 15y agoNooooo!
- _THE_PLAGUE 15y agoMy response: http://blogkinnetic.blogspot.com/2011/12/on-civic-decay-of-us-computer-science.html http://blogkinnetic.blogspot.com/2011/12/on-civic-decay-of-u...
- _THE_PLAGUE 15y agoHere is my blog article I wrote on this travesty. (Available here: http://blogkinnetic.blogspot.com/2011/12/on-civic-decay-of-us-computer-science.html 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. :-)
- captainaj 15y agoI parted away with CS to major in biochem thinking it wasn't as fascinating (first course was in C++). This is definitely not a bad idea and also already implemented. Stanford has CS101 in entirely Javascript: http://www.stanford.edu/class/cs101/ http://www.stanford.edu/class/cs101/
- tingletech 15y agoJavaScript was my first language. I made web applications using Netscape Enterprise Server which had server side javascript, and I worked on a signed javascript kiosk application that ran in Netscape and had javascript menus that would side off the screen.
- _THE_PLAGUE 15y agoI have commented (at length) on this earlier, so don't have much to add. But a further thought did occur to me: JavaScript has "loose typing", that is, one is not taught the difference between say, an int, and a double, or even a char, and the fact that there is no such thing (really) as a string - "strings" are just a lazy shorthand for a char array. Loose typing is not just incorrect - on some level, it is immoral, IMO.
- kls 15y agoOne thing that I have not seen covered that is worth mentioning, is that JavaScript for the most part embraces an event based development model. While it is not unique to JavaScript it certainly is heavily reinforced by JavaScript and JavaScript developers. In other languages it can be fairly underrepresented, that being said, it is worth learning JavaScript due to the fact that it helps developers think of execution as events. One can go their whole life in other language and not deal with events, with JavaScript you will be hard pressed to get to intermediate tutorials without fairly good coverage of events and event syndication.
- jhuni 15y agoIts pretty easy to criticise, so instead I will discuss the steps I would take to a student CS principles from my own experiences. I find graphs to be fundamental, so I would start the student out with them. 1. Teach the student basic concepts in graph theory such as nodes, edges, walks, paths, cycles, and structures such as trees, and linked lists. 2. Introduce the student to syntax trees as a means of representing mathematical equations, and the representation of them used in Lisp: (+ (* a x x) (* b x) c). 3. Describe dataflow graphs to the student. For example, loops are cycles in the dataflow graph, and infinite loops occur when the cycle is endless.
- ZenPsycho 15y agoSomeone is teaching JavaScript to other people? This is nothing less than /The Downfall of Civilisation As We Know It!/. Quick everyone, get your pitchforks!
- jaequery 15y agojohn, just teach them jQuery!
- olivier1664 15y agoI've learn programming to create small 2D games: Turtle at 8, TI-82 at 16, Pascal at 18, C with Allegro at 22, android-java at 30. It was some "Snake" or "Tron" or "Bomberman" kind of games. Seems obvious for me that children motivation can be creating game. So, in my opinion, an ideal first language should be a sandbox language that have C syntax style without pointer stuff and can easily: - Read keyboard() - DrawPixel() - DrawImage() - PlaySound() Bonus if there is no install. Bonus if created games can be send by email to friends.