7 ms·
It's hard for me to imagine learning Javascript as your first programming language. It's always felt kind of crazy and bizarre to me (especially when you try to
by powrtoch 14y ago
It's hard for me to imagine learning Javascript as your first programming language. It's always felt kind of crazy and bizarre to me (especially when you try to do anything requiring more than 20 lines of code), but I think a lot of that is just failure on my part to shake off the paradigms I'm used to. A generation of coders who are actually trained from the start to think in Javascript... almost scary honestly, but in a good way. We need more John Resigs pushing the web forward :-)
- majormajor 14y agoJavascript has its oddities for sure, but most of that lies in areas that you wouldn't need to touch while learning programming basics. Compared to my high school experience of learning in a C/C++ mismash with a teacher who insisted on introducing pointers very early, before ever presenting me with anything interesting to do which would make me want to figure out the details like that (and which scared me off programming for four years), I think it sounds like a dream.
- slurgfest 14y agoAlthough I like Javascript and its tools have improved dramatically in the last few years, a number of cases (like [] + {} vs. {} + []) are decisively non-ideal for teaching people who are not somewhat versed in programming languages. It's this kind of thing which gave Javascript a reputation as a kind of client side PHP. I would be very happy if these kinds of irrationalities could be ironed out in a future version of the language, even if it meant backward incompatibility. If the language is thoroughly rationalized and there is a simple, beautiful API for graphics then I think it becomes the beginner's language to end all (since client-side web is such a nice platform to target). But for now, it isn't there... I'd be happy to hear that it was a priority. Perhaps something like Dart will pick up that quest.
- hnherer 14y agoperfect!
- Me1000 14y agoI think for the purpose of teaching people the basics of programming it's perfectly acceptable to leave them with a basic understanding of "You can only add numbers and strings." Then allow them to revisit the oddities much later after they have a much better understanding of what objects are. Honestly, I think it might be acceptable to just ask the student to explain to you how "object addition" would work. There are various ambiguous problems you could run into (concatenating two objects with the same property name but different values). I think this basic understanding is enough that even a novice would accept. I think things like dynamic "this" in javascript will be more confusing for newcomers. But, once you start talking about "this", you should probably already have the basics down. Edit: With all that said, I'm not saying Javascript is a great language to learn programming with. But I don't honestly know of a single language that I would be perfectly comfortable telling people to learn with. Most languages have their own quirks.
- esrauch 14y agoTangent: to be clear, there is no difference between []+{} and {}+[] in javascript. var a = {} + []; var b = [] + {}; var c = String({}) + String([]) All three are equal. The order does matter in general because its doing string concatenation which obviously matters ([1] + [2] == "12"), but the fact that js always does string coercion and concatenation anytime you have + without numbers on both side isn't really that crazy.
- ghusbands 14y agoThere is a slight difference between []+{} and {}+[], in fact, but you're unlikely to see it outside of a console. At a console, {}+[] gives you 0, which is different to the result you get above. That's because it's an empty block followed by +[].
- ehsanu1 14y agoType coercion is crazy, if for no reason other than making the behavior of certain code harder to predict. That said, I don't think it's a major stumbling block, and once you learn to avoid relying on it there's no problem. There are plenty of parts of JavaScript like that, but these gotchas are just red herrings. The core language is great.
- krschultz 14y agoAgreed. I personally started in QBasic, so I guess where you start doesn't limit you for life, but these days I typically recommend Python as a first language.
- rabidsnail 14y agoI learned javascript as my first language, and when I first saw recursion my reaction was "There's a name for that?". If you learn from good tutorials it can be as good as learning with scheme.
- natural219 14y agoI can't emphasize how much I disagree with you. You can do an incredible amount with Javascript with very few symbols to learn up front. If your goal is to get people interested in programming, there is nothing more discouraging than having to trudge through learning the intricacies of a relatively "safe" language with rigid types, inheritance models, and dozens of enigmatic exceptions. Notice that I'm not saying these things are bad, but they are certainly more than a beginner needs to learn basic syntax and become familiar with control flow.
- lubutu 14y agoLikewise the emphasis! Although you're right that a lot of languages are bureaucratic with enigmatic exceptions and so on, I think that a well-typed language is better to learn to begin with than one which basically accepts whatever nonsense you throw at it. I'm not sure the perfect beginner's language exists, but I personally believe that if it did it would be statically typed.
- powrtoch 14y ago> I can't emphasize how much I disagree with you. I don't think you disagree with me at all... I said that javascript feels strange to me because I didn't start with it. I think it's a fine language to start people on, just an uncommon one that should yield interesting results. I certainly wouldn't suggest teaching with more "rigid" languages. I was trained on Java, and looking back I can see what a terrible way of doing things that is. FWIW though, it's been my experience that for all but the most trivial tasks in Javascript, you quickly find yourself getting into somewhat advanced territory with e.g. scoping, closures, and anonymous functions. Again, I think these concepts are mostly weird to me just because they're different than what I personally was trained on, but they're certainly not as easy to grok as e.g. variable assignment and conditionals.
- natural219 14y agoYou know, my mistake -- I somehow just skipped over the last line of your paragraph ("it's scary to me..."). In that way, I certainly see what you're saying. It'll be interesting to see what new problems emerge if this continues as a paradigm for teaching how to program.
- newobj 14y agoNot sure it matters really, since programming will "speak" to some people and not to others regardless of the language. But in terms of JavaScript specifically, I think first timers could do without being exposed to lexical scoping and truthiness. I like that Javascript gives you encapsulation without necessarily object orientation, which is probably a good place for beginning programmers to start.
- adrusi 14y agoI learned javascript as my first language (well, I half learned Pascal first). It's not that bad.
- cs702 14y agoBetter Javascript on the browser with a simple, integrated, interactive canvas than Java, C#, or (god forbid) VB.Net on a complicated IDE!
- pm90 14y agoI actually did my first programming project in VB.net using Visual Studio. Although it didn't 'spark my interest in programming', I could get the job done; and at that time I had no prior programming experience...
- ConstantineXVI 14y agoSo many people learned (a dialect of) BASIC despite it's faults because it was the one language available on nearly every home computer on the market, and typically accessible directly from the main UI of the computer. Considering how the browser may as well be "the computer" for many people, JS is in the same position.
- tagawa 14y agoThere are lots of unsung John Resigs pushing the web forward.
- JVIDEL 14y agoIf you ask me this has more to do with JS becoming the lingua franca of web development and less to do with making programming as easy as possible. Case in point, recently some chick from highschool asked me where she could learn to code, so I pointed her to some Scheme tuts, nothing too complex since she requested something as easy as possible. ....then she writes back asking if "this is what jquery uses". I say "no", she gets upset and ask me "what the hell is this for then?" Long story short: for a lot of people out there is not about learning how to code but learn-X-to-do-Y no more no less...
- cshesse 14y agoIf you're not learning how to code to do something useful with it, why learn to code?
- hackinthebochs 14y agoThere's some of us out there who enjoy coding for its own sake. Coding is a pure form of problem-solving. It doesn't necessarily matter what the problem is you're solving, just that you get a certain intellectual satisfaction out of the process. I must be one of the few that coded linked-lists and string containers in high school instead of silly text games :)
- jason3 14y agoFuck you.
- i_cannot_hack 14y agoWhy did you send her Scheme tutorials if she asked for something as simple as possible? Lisp is generally thought of as a very unintuitive language. I think Python would have been a much better choice, considering what she asked for.
- e12e 14y agoThat, and that Self (which javascript pretty much is a version of) -- is a step up from Smalltalk. Add to that the fact that it is actually available every where (unlike, python, lisp, smalltalk...) -- and I think it makes perfect sense. If you're going to ask people to download something, I still think Smalltalk is a nice alternative -- and it has been for a while: http://www.atariarchives.org/bcc1/showpage.php?page=61 http://www.atariarchives.org/bcc1/showpage.php?page=61
- richcollins 14y agoespecially when you try to do anything requiring more than 20 lines of code It's simpler than most OO languages. Not sure why you think it doesn't scale as well.
- SideburnsOfDoom 14y ago> Not sure why you think it doesn't scale as well. The reasons why JavaScript is thought not to scale well are very-well known. They include: Minor syntax issues: - Deeply indented callbacks, passing a function to a function to a function and the resulting complexity of flow control. - Issues with "this" become more likely with larger codebases. I know that JavaScript's "this" WTF is very old news, but it's the gift that keeps on giving. Major design issues: - JavaScript is not an OO language, it is a language that provides an OO construction kit. The OO patterns are layered on top of the language, the best idioms (e.g. self-invoking anonymous function, revealing prototype pattern) are not obvious and took a while to become common, and since none of them are mandatory, they can be ignored, mixed and matched or just gotten wrong. This is not a prescription for trouble-free scaling of the code. - Lack of a built-in packaging/module or linking system. Requirejs is filling this gap, but for a long time most JavaScript code just wasn't partitioned, it was put all in one file. It is unreasonably hard to build large systems this way.
- richcollins 14y agoI don't have any of these problems when I use js. I mostly use delegates and notifications instead of callbacks. I always use this to refer to the called object. The inheritance model is very simple and better than many other oo languages like Ruby. I agree that the method for cloning an object is a bit obtuse but it is easily corrected so you can just call clone on any object. The lack of forward is a small but significant problem but it doesn't significantly hamper design of complex software. It isn't ideal that you that you can't import modules but again it doesn't prevent you from building well designed complex software.
- icefox 14y agoI think you are forgetting what it is like to first learn how to program. For me and many of my friends the programming class was something you did so you could make games! If you finished your assignment early you didn't make yet another linked list class or implement a shortest path algorithm, you made anything graphical even if at that skill level meant a "full screen" text based tic-tac-toe. Granted the stuff you made was nothing like the 3D shooter you played in the evening, but it was something _you_ made that made it really cool. JavaScript works really really well in that regard in that you can easily make stuff appear on the screen with very little effort with html (and move onto canvas / webgl) and they don't look half bad. Unlike other programing languages graphics are "built in". Python is great, but compare drawing on the screen in C++/Python/Java v.s. JavaScript and you get my point. As a first language it is a perfect choice as it is something you can get excited about.