News for hackers. Stuff that matters.
Re:Writing Maintainable JavaScript by mberning on Friday May 06, 2011 @01:41PM (#2521736)
Write as little code as possible. The easiest code to maintain is the code you never had to write.
Re:Writing Maintainable JavaScript by cema on Friday May 06, 2011 @02:30PM (#2521939)
Partially true. Short code may be too cryptic to be easily maintained.
Re:Writing Maintainable JavaScript by IgorPartola on Friday May 06, 2011 @03:23PM (#2522143)
Write neat code. Not clever, not verbose. Neat.

Also, write code which calls only really well documented functions. Doing jQuery("#my-input").val() is clear enough. Doing myCrazyFramework.dom.manuplators.find.get_value('my-input') is more obscure, even though it's more verbose.

Write code that's been written before. Don't use clever patterns you found on code snippet sharing websites (http://code.activestate.com/recipes/66531-singleton-we-dont-... for example). Keep using the same pattern over and over.

Write small chunks of code: a function over 50 lines is probably really hard to read. This is a rule of thumb, not a commandment, but I found it to be true in at least > 51% of cases.

Avoid code magic. E.g.: deleteUsers(username) should not check for whether username has the substring "test" in it to see if the user should really be deleted.

Avoid state at all cost.

Avoid timing dependence. Pretend like anything in your application can happen any time any place.

Handle all exceptions.

I'm probably wrong on at least 50% of the above, and am probably missing 10 time as much...

Re:Writing Maintainable JavaScript by jamesbritt on Friday May 06, 2011 @09:22PM (#2523014)
Write small chunks of code: a function over 50 lines is probably really hard to read. This is a rule of thumb, not a commandment, but I found it to be true in at least > 51% of cases.

Peter Seibel, in Practical Common Lisp, has a footnote about this:

"A friend of mine was once interviewing an engineer for a programming job and asked him a typical interview question: how do you know when a function or method is too big? Well, said the candidate, I don't like any method to be bigger than my head. You mean you can't keep all the details in your head? No, I mean I put my head up against my monitor, and the code shouldn't be bigger than my head."

http://www.gigamonkeys.com/book/practical-a-simple-database....

Re:Writing Maintainable JavaScript by wccrawford on Friday May 06, 2011 @01:34PM (#2521707)
These apply to all languages, not just Javascript. It's pretty basic techniques for keeping your code nice:

Decouple/Blackbox

Naming Conventions

Start using these techniques now, refactor old code over time

Re:Writing Maintainable JavaScript by euroclydon on Friday May 06, 2011 @03:13PM (#2522111)
Straight up question: How do you build source code documentation?

I use jsDoc (closure compiler's version, with data annotations). Because of this, I can't wrap all my code in a closure, which seems so popular these days. jsDoc won't parse through the closure. So, I use namespaces, and keep all my code in the global scope. It works great.

Re:Writing Maintainable JavaScript by autalpha on Friday May 06, 2011 @01:18PM (#2521642)
I refuse to install Silverlight :P
Re:Writing Maintainable JavaScript by rmurphey3 on Friday May 06, 2011 @01:21PM (#2521655)
It's just a video tag for me in Chrome.
Re:Writing Maintainable JavaScript by hasenj on Friday May 06, 2011 @04:36PM (#2522387)
Works in Chrome without Silverlight, but not in Firefox.
Re:Writing Maintainable JavaScript by ChiperSoft on Friday May 06, 2011 @02:25PM (#2521925)
Shows up as an HTML5 video element for me in Safari.
Re:Writing Maintainable JavaScript by emehrkay on Friday May 06, 2011 @03:05PM (#2522083)
Forced me to install silverlight; safari windows (work machine so I dont care)
Re:Writing Maintainable JavaScript by autalpha on Friday May 06, 2011 @03:34PM (#2522163)
FF4 on OSX here and I can't view the slideshow without installing Silverlight. Didn't know I would offend people with my stance on Microsoft's Silverlight. I am peeved at Microsoft's stance on Flash or other open solutions. And don't get me started on their "web standards" implementations.
Re:Writing Maintainable JavaScript by PetrolMan on Friday May 06, 2011 @03:16PM (#2522122)
You should have to work with it...
Re:Writing Maintainable JavaScript by autalpha on Friday May 06, 2011 @03:35PM (#2522172)
"Doh! Your browser doesn't seem to support Silverlight or HTML5 video or we don't have an HTML5 video for this one."

that's what I get when I clicked play. I'm using FF4 on Mac OSX.

Re:Writing Maintainable JavaScript by Todd on Friday May 06, 2011 @09:54PM (#2523044)
Thanks for posting. I meant to go to this session but it was too early.
Re:Writing Maintainable JavaScript by ChiperSoft on Friday May 06, 2011 @02:25PM (#2521926)
My god, he is so hungover in this video...
Re:Writing Maintainable JavaScript by clocktower on Saturday May 07, 2011 @01:17AM (#2523249)
Not hungover; just _really_ tired. I want to have a talk with whomever scheduled me for a 9am slot. Also, the light was in my eyes whenever I tried to look out toward the audience. AND OTHER EXCUSES, TOO
Re:Writing Maintainable JavaScript by kragen on Friday May 06, 2011 @04:17PM (#2522318)
Is there a non-video version of this?
Re:Writing Maintainable JavaScript by diamondhead on Friday May 06, 2011 @04:13PM (#2522304)
see the irony