Thursday, July 2, 2009

Javascript - the right way...

Simple a useful 'tips' for write (much) better java script code

Always pass your code in JSLINT
This is the most basic/best advice I can give you.
JSlint should be your 'compiler' for java script. It will catch so many bad coding behaviors that you want to bind it to your process and before committing any new code to your source control (you do use source control, right? :) you are passing the code there and fixing all the recommendations.

Use jQuery
"...jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript." or in the short version "Do more, write less".
It's so true in their case. Specially, if you aren't a JS guru, jQuery will give you the option to 'look' like one.
If you do need a nice widgets that aren't part of jQuery (e.g. Rich Text Editor) - I would go with YUI. There new version (3.0) is very well documented and they giving you lots of excellent tools to build on their widgets.

Always Use 'var'
Variables in java script either have global scope or function scope, and using the 'var' keyword is vital to keeping them straight. When declaring a variable for use either as a global variable or as a function-level variable, always prefix the declaration with the 'var' keyword.
It is a good idea to always declare global variables using 'var', but it is vital to declare function-scoped variables using 'var'.

Avoid 'eval'
The eval() function in javascript is a way to run arbitrary code at run-time. In almost all cases, eval should never be used. If it exists in your page, there is almost always a more correct way to accomplish what you are doing. For example, eval is often used by programmers who do not know about using Square Bracket Notation. Don't use it unless you are an experienced developer and know that your case is an exception.

Avoid 'with'

The 'with' statement in javascript inserts an object at the front scope chain, so any property/variable references will first try to be resolved against the object. This is often used as a shortcut to avoid multiple long references.

Use The + Operator To Type Convert To Number
In javascript, the + operator is used for both addition and concatenation. This can cause problems when adding up form field values, for example, since javascript is a non-typed language. Form field values will be treated as strings, and if you + them together, javascript will treat it as concatenation instead of addition.

To fix this problem, Javascript needs a hint to tell it to treat the values as numbers, rather than strings. You can use the unary + operator to convert the string value into a number. Prefixing a variable or expression with + will force it to evaluate as a number, which can then be successfully used in a math operation.
Example: +theform.elements["field1"].value // this will 'tell' the JS that its a number.

Avoid document.all
document.all was introduced by Microsoft in IE and is not a standard javascript DOM feature. Although many newer browsers do support it to try to support poorly-written scripts that depend on it, many browsers do not.

Friday, June 19, 2009

Scientifically proven ways to be (more) persuasive


It is an interesting field 'behavior intelegance' or as we like to call it in the IT world Peopleware. When we talk about peopleware we refer to anything that has to do with the role of people in the development or use of computer software and hardware systems. But more specifically issues as developer productivity, teamwork, group dynamics, the psychology of programming, project management, organizational factors, human interface design, and human-machine-interaction. As a developer and/or manager (leader) you want to be better in harnessing your developer after your ideas, goals and most imprtant 'boring tasks'. Last night I found this interesting article about scientifically proven ways to be persuasive.
Here is just one good example:
"Ads quoting negative behavior en masse reinforces negative behavior. Petrified Forest National Park A/B tested two versions of a sign imploring people not to steal pieces of petrified forest from the park. One mentioned large amounts of petrified forest taken away on an annual basis, the other one simply asked the visitors not to remove petrified wood. The first one actually tripled the theft ratio as it showed stealing petrified wood as something commonplace. Same effect was observed after airing an ad that implored women to vote, but mentioned that 22 million single women did not vote last year. That kind of information actually portrays not voting as more socially acceptable."

All the rest of the list...

Btw, the photo was taken by me 217 years ago on a wonderful trip to New Zealand! Bonus points to the reader that will recongnize the palce ;)

Thursday, June 18, 2009

SEO for developers

Wednesday, June 17, 2009

The Blue Angles from the pilot sit

Tuesday, June 9, 2009

Google I/O 2009 - Ignite Google I/O

If you have 50min and you want to see 10 persentations (yes - 5 min per one) check this:
 
1. 2. 3. 4. 5.