Ask Hackers: How to become the best JavaScript programmer? (q by 12yr old)
I love everything about the web and web 2.0 and I would love to become the best JavaScript programmer ever!
Can you give me hints and tips to become one?
PS. I am 12 years old
60 comments
[ 3.0 ms ] story [ 113 ms ] thread2) Find a good mentor - it could be a prof at a local university, family friend who is a hacker
3) Practice, practice, practice - write javascript to make stuff for fun.
4) Go to websites you like and de-construct their javascript code and figure out what it's doing.
5) Don't be shy to reach out for advice, like you're doing now.
The learning will not come to you, you need to go out and get it. Don't just go to school, attack school, suck the juice out of the fruit, and have fun doing it. Make it fun and hard.
After you've finished reading it, learn what can Javascript libraries like Mootolols or JQuery can offer.
And of course: practice, practice and practice. Working in your own challenging projects is the best way to do that.
Enjoy it.
http://jquery.com
Most fun javascript library ever.
javascripter, learn about Javascript's language features. Learn about nested function and function passing. Learn about object-oriented Javascript and prototypes. Learn the difference between Javascript the language, and DOM, the thing within the language you use to add functionality to web pages. If you find that you are repeating things, write your own library.
Is this the first programming language you are learning? If so, it will give you a leg up when you learn a more conventional language like C or Java, because it will give your mind flexibility. If you already know a programming language, understand that different programming languages have different ideas about how programs can or should be expressed. (That's why there are so many languages.) It will sometimes be helpful to see how something in a new language is similar to a language you already know, but other times you have to just say to yourself, this is different, and I have to think a new way.
Instead choosing a good library can give you free range to explore the advanced programming concepts in JavaScript, instead. jQuery, for example, is highly functional. It makes heavy use of lambdas and closures - even encouraging newbie programmers to use them.
If you want to get better at programming, through programming JavaScript, then a library is the only way that you'll be able to keep your sanity and make that a reality.
http://www.crockford.com/
(Note that to become the best JavaScript programmer ever, you'll probably have to pick up some other languages along the way. But JavaScript is both a good language to learn and a good language for learning, so it's not a bad idea to learn JavaScript really well first before learning others. Keep an open mind.)
The best way, in fact the only way, to learn programming is to read and write a lot of code. An interactive environment like Firebug makes that easy. If I were you, I'd get myself a good Javascript book and type in the examples as I read them. Then I'd try modifying them to do cool things. Good luck!
Edit: when you get stuck, ask questions. I taught myself programming when I was your age and my biggest obstacle was not having anyone around who could help me when I got stuck. Nowadays that's not a problem since there are lots of people on the web who are happy to help.
jQuery... I have mixed feelings about it.
On the one hand, its very good for high level thinking and writing good, readable code. On the other hand, it slows down your javascript code by at least 2x, which is particularly noticeable if you're doing a javascript intensive application. Then again, the future of browsers is speeding up javascript, so this may not be an issue in a couple of years.
My experience with Prototype is that it handles the speed issue much better - however, it is a bloated monster of a framework.
I don't pretend to know what I'm doing with JS, so I'll keep your advice in mind should I have to figure out why something isn't as fast as it should be.
(I wrote something to this effect on Proggit once, and John Resig reply was something like, "Of course. JQuery's not intended for performance-critical code - usually you don't want to be using any framework for that. JQuery's meant to make the other 90% of JavaScript development go faster.)
BTW, I won't go near Prototype (after having used it pretty extensively at a past employer) because it messes with Object.prototype. When libraries do that, you have no way of knowing which libraries are compatible, which means that you'll suddenly get bitten by very odd, hard-to-track-down bugs.
Now if development time is a greater priority over performance then I think the choice is pretty obvious.
Wittens' talk at http://acko.net/blog/jquery-oscms-presentation-slides at the OSCMS was pretty good; basically, JavaScript is not bad, but too much can be overwhelming to people.
P.S. Not always the slowest set of elements to load on a page. A fun little hack: http://www.spaceminnow.com/school - standard disclaimer -
2. Then learn Javascript.
Firebug is nice, but Venkman's Javascript Debugger for FireFox is my favorite. The interface is a bit weird, but your mind should be flexible enough to figure it out. :)
Good luck!
2) Check out the videos on http://developer.yahoo.com/yui/theater/ There's 2.2gigs of them for you to digest. Crockfords are especially good, and will teach you good practices.
3) Use a framework like mootools to save you time on real projects. However, I advise against assuming these frameworks are "perfect"; they all have faults.
4) Don't copy other people too much - many JS devs, including me, are terrible programmers :-P
5) Learn JS by creating AJAX projects as it's so important to web apps. "Professional Ajax" by Zakas is a decent place to start.
6) Enjoy it! JS is a fantastic language, and the quick returns can be incredibly rewarding. It has its faults, but it is amazingly powerful and quite unique.
I totally disagree. Learning how to write functions is a big, big deal and will take you far indeed. I can't think of anything more important for learning programming.
Meanwhile, "object-orientated prototype madness" is entirely optional.
One of the biggest problems with JavaScript is its community. I'm not talking about N.YC readers who think they are bad programmers. No, I'm talking about the fact that there are reams and reams of plain old bad advice on JavaScript out there that still outrank the good stuff in most search engines.
99% of the time a Google search on a JavaScript problem will score you pages of hits with antiquated, non-standard, buggy or IE-only approaches.
Always be working on a project. Come up with an idea, like tic-tac-toe and start hacking on it, until you are finished. Then cook up another idea and hack on it. Without an idea, you'll just float around. Get Firebug and learn to love jQuery, it's magic.
And if you want to be great, you don't want to be a programmer, you want to be a hacker. :)
If you are absolutely determined to learn Javascript - I agree with others read the articles by Crockford and watch the Yahoo UI videos - Read the code for dojo. Alex is one sharp javascript guy. - For ajax frameworks look at DWR
Good luck... and have fun !!
In fact, Douglas Crockford (mentioned elsewhere in this topic) says it's the only JavaScript book he can recommend.
On a side note, don't learn a library as the first thing you do as you'll be learning how to code in jQuery, Prototype, etc, rather than in Javascript.
There's at least one thing you're already doing right: you're starting out with a problem that interests you. However, I don't think you have quite the right goal. You don't want to be the best Javascript programmer ever. You want to be the best programmer ever. Javascript should just be one weapon in your arsenal, and a rather specialized one at that.
That said, you have to start somewhere. Usually I recommend that people start with Scheme and read SICP (online at http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html), but since you've indicated that you're interested in web programming, that's probably not the right first step for you. The trouble with web programming is that it's messy. Any non-trivial website requires you to understand a whole alphabet soup of different programming languages and markup languages, some of which were designed for each other and some of which weren't, and then to top that off you get to worry about Internet Explorer dain bramage. If you're just programming for an audience of you and nobody else and you choose carefully what to work on, then you can ignore some of these issues, but sooner or later they'll leak in and it's going to seem overwhelming. (This isn't necessarily bad; coping with information overload is one of the most valuable skills a hacker can learn.)
So, here's what I suggest. Start by learning Python. It's a clean, reasonably powerful, easy-to-learn language, and it's very good for web programming. I assume you already know HTML; if not, learn that first -- it'll take you a couple days max. You can make a pretty capable website using just Python and HTML. You could almost write news.yc, except for the AJAX up-arrows which require Javascript. A site like this would be pretty big as a first project, though.
I'll let someone else recommend a Python tutorial. I just learned it from the reference manual, so I don't know a good one.
Once you feel confident making web pages using Python and HTML, then it's time to start learning Javascript. It might also be a good time to go back and learn to write standards-compliant XHTML-strict and CSS, since this will make working with the Javascript DOM a bit less of a headache, but this is optional and you can do it in parallel with learning Javascript if you do it at all.
Finally, here are some bits of non-technical reading I recommend:
http://www.catb.org/~esr/faqs/hacker-howto.html
http://www.catb.org/~esr/faqs/smart-questions.html
http://paulgraham.com/gh.html
I don't think a 12 yr old would have that enthusiasm for pure javascript.. would definitely ask about HTML (if he knows html he knows how to find out about javascript?)...
what 12 year old knows about YC.news?
Seriously... I'm calling this one out... spam.
Whoa, just found it again: http://www.newsweek.com/id/103827/output/print
Practice. Read and write a lot of code. You might try to work your way through set problems like Project Euler or the Ruby Quiz or other competitions.
Learn the "laws of physics" of programming - some things are harder to do than others. all programming is an interplay between making a tiny, trivial and deterministic step on one hand and managing complexity through abstraction on the other.
it's most instructive to try things for yourself - even if you fail - but on the other hand make sure you attempt things you will definitely succeed at too because the feeling of success will fuel your passion. you will never be a great developer without passion!
Watch Douglas Crockford's JavaScript videos.
use Flanagan's Rhino book.
Try and use different programming patterns and styles in javascript: imperative, functional, object oriented, continuation-passing, dependency injection, fluent interface.
Always use var and semicolon.
Never use "with" or "eval".
Plan to learn another programming language (which smart people recommend you) and it will also greatly assist your javascript programming - you should not be too tied to a single language that you can't change. If you really like web 2.0 you should learn a good server side language as well. As a second to JavaScript for a youngster I would recommend Ruby or Python, (or PHP if you must). Other languages are really great for that purpose but these will be easier to learn first and will be readily available on cheap hosting providers. Those others may include: Lisp/Scheme, Smalltalk, Java, C#, Scala etc. Do not learn VB.
Get firebug.
Read "The Pragmatic Programmer".
Reuse code.
Write automated tests. You can use a unit test framework.
Write lots of cranky cryptic puzzle code right now. Get it out of your system. Then seek to write clean comprehensible code forever more.
Port code from another language.
Recognise that lots of people in professional development have absolutely no idea what they're talking about. Others are absolute genius gurus who's words you should memorise and meditate on. Good luck telling the difference!
Use the force.
http://www.jalix.org/ressources/internet/dhtml/_dynduo/dyndu...
Have fun.
Lots of people have recommended the definitive guide, David Flannagan's book.
I recommend, also, John Resig's book, Pro JavaScript Techniques, and also take a look at his website.
If you'd like to learn some functional programming, and write some of the coolest code possible, take a look at Oliver Steele's website.
It doesn't matter super much what language you learn initially. So if you have some friend who is an expert in another language, you might be better off learning that, then switching to Javascript once you know the basics of programming.
You wont really understand any language until you've learned a couple of others and are able to see programming from several perspectives.
Quirksmode.org has some really good compatibility tables as well: http://www.quirksmode.org/dom/compatibility.html
Just my 2 cents...
So, get a copy of O'Reily Definitive guide, Start working through that. Watch the Douglas Crockford lectures from Yahoo.
Install firebug and start messing around.
"Hrm I've read about the arguments.callee property. Lets play with that for a few minutes and see how it works" etc etc
The main thing is just to explore, get down to the nuts and bolts, see how it all really works. Try things out, and see if they work or not.