29
Efficient JavaScript Development tools, strategies, tips and tricks Wolfram Kriesing, uxebu [email protected]

Efficient JavaScript Development

Embed Size (px)

DESCRIPTION

tools, strategies, tips and tricks

Citation preview

Page 1: Efficient JavaScript Development

Efficient JavaScript Development

tools, strategies, tips and tricks

Wolfram Kriesing, [email protected]

Page 2: Efficient JavaScript Development

1. Writing Code2. Running Code3. Debugging Code4. Fixing Code

Page 3: Efficient JavaScript Development

Writing Code

• coding style, conventions, etc.

• editors

• customize your editor

• templates

• code analyzer

• try it first

Page 4: Efficient JavaScript Development

Coding Style, etc.

• less to think

• all code looks the same

• code not style

• stay focused

Page 5: Efficient JavaScript Development

Useful Editors

• komodo

• aptana

• eclipse

• many others ...

What is „useful“?faster writing of code, auto completion, code analyzer, syntax check

and coloring, dive in

Page 6: Efficient JavaScript Development

Customize your editor

• keyboard shortcuts

• folding, bookmarking

• make your editor do what you want!

Page 7: Efficient JavaScript Development

Templates

• no typos

• for the whole team

• docs built in

• copy with pride

http://www.activestate.com/Products/komodo_ide/edit_features.mhtml

Page 8: Efficient JavaScript Development

Code analyzer

• syntax coloring

• knows the API of your library

• understands your code

• links code (dive in)

• auto completion

• JSLint built in

Page 9: Efficient JavaScript Development

JSLint

• finds IE traps (trailing comma)

• gives JS insight (parseInt, ===, ...)

• understand type coercion

• finds missing var statements

• undefined variables (myVar vs. myvar)http://jslint.com

http://wolfram.kriesing.de/blog/index.php/2007/understanding-jslint-outputhttp://www.danhulton.com/blog/2008/01/16/integrate-js-lint-into-komodo-edit/

Page 10: Efficient JavaScript Development

Try it firstdojo.query("h1").style({color:"red"}).anim({left:300}, 500)

Page 11: Efficient JavaScript Development

Try it firstdojo.query("h1").style({color:"red"}).anim({left:300}, 500)

Are you sure this works?

Page 12: Efficient JavaScript Development

Try it first

• try the code in FireBug first

• you learn more about your library

• play with the code

• maybe there is even a better way

dojo.query("h1").style({color:"red"}).anim({left:300}, 500)

Are you sure this works?

Page 13: Efficient JavaScript Development

Running Code

• loading times, order, etc.

• environments

• ajax requests

• inspect and fix

Page 14: Efficient JavaScript Development

Loading the Code

• syntax errors

• any 404s

• need a build

Page 15: Efficient JavaScript Development

Watch the traffic

• Charles

• HTTP Live Headers

• Fiddler

• etc.

Page 16: Efficient JavaScript Development

Environments

• browsers

• phones

• air

• widgets

Page 17: Efficient JavaScript Development

AJAX Requests

• FireBug reveals it all

• watch out with XD requests

Page 18: Efficient JavaScript Development

Inspect and Fix

• fix the DOM

• fix the CSS

• see inheritance chains

• validate before trying

Page 19: Efficient JavaScript Development

Debugging Code

• debuggers

• object inspection

• other sources

• isolating the problem

Page 20: Efficient JavaScript Development

Debuggers• IE8, developer tool bar

• FireBug

• Drosera

• Venkman

• Microsoft Script Debugger

• Visual Studio Express

• pi.debugger, FireBug Lite, ....

http://www.nczonline.net/blog/2008/03/22/falling-in-love-with-the-ie8-javascript-debugger/

Page 21: Efficient JavaScript Development

debugger;

• programatic breakpoint

• set on the fly

Page 22: Efficient JavaScript Development

Object inspection

• console.log

• console.dir

Page 23: Efficient JavaScript Development

Other Sources

• google your problem

• talk to a colleague

• sleep over it

Page 24: Efficient JavaScript Development

Fixing Code

• trial and error

• alert, console.log, etc.

• in browser

• tuning

Page 25: Efficient JavaScript Development

Trial and Error

• you know your code

• you think you know it

• you imagine you knew it

• you think you should try

• you fail

Page 26: Efficient JavaScript Development

alert, console.log

• alert, confirm

• use numbered console.log

Page 27: Efficient JavaScript Development

*.toString()

• see the source

• missing function name (you know it)

• parameters

• fix it in place!

Page 28: Efficient JavaScript Development

Tuning

• console.time

• console.timeEnd

• console.trace