formats

Style Is Not Subjective

In Javascript, the left brace, {, should be at the end of the line that begins the compound statement.

I recently watched Douglas Crockford’s, author of Javascript: The Good Parts, Google Talk this past week. Amazing talk, if you have not had the opportunity I have embedded it below. While watching this video I cam across a "gotcha" in Javascript.

Code style is a very passionate topic to many people. To me it really is you do it your way and I do it mine. And it also really depends on the language you are working in. I generally prefer to put my curly braces on a new line.

It turns out that in Javascript this is a very bad thing to do. The Javascript compiler will attempt to insert semicolons any where it decides requires them. It is good programming practice to always insert a semicolon at the end of each line of code, but Javascript is very forgiving in this manner. If a developer writes the following code:

The compiler will insert a semicolon immediately following the return statement, therefore not returning the JSON value. This is a very difficult situation to debug if you do not understand what is happening in the background with Javascript.

formats

Back to Work

Published on March 31, 2012, by in Uncategorized.

Sorry I have not been able to keep updating this site. Excuses mean nothing, but as of this Thursday I finish my Computer Science degree from the University of Manitoba and will hopefully have more time to post here regularly.

Starting next week I will start adding short blogs about interesting or quirky things that I have come across in web development. I plan on taking some time over the summer to get a good understanding of backbone.js and will try to post some introductory tutorials here as well as some of its related technologies.

formats

JavaScript’s IEE-754 floating-point format

In an attempt to improve my web development skills, I have decided to go back and refresh myself on the basics of JavaScript. Don’t get me wrong, I have experience development web applications using JavaScript with jQuery, MooTools, and other JavaScript frameworks, but if you don’t have a solid understanding of the fundamentals its’ time to go back and learn..

Today I started reading Eloquent JavaScript by Marijn Haverbeke. Right off the bat I learned something new about JavaScript, I was expecting the bit representation of 144 to be:

10010000

but JavaScript does not represent 144 as an integer, but as a IEEE-754 floating-point number. Therefore it is represented in 64 bits:

0100000001100010000000000000000000000000000000000000000000000000

The ramification of storing numbers in the IEE-754 floating-point format is floating points have limited precision and therefore cannot represent all numbers with high percision. For more information on floating point values see WikiPedia’s Floating Point Page.

In retrospect, I should have known this but I never took the time to think about it. Unlike most other languages I have programmed in, JavaScript is a dynamically typed language. In dynamically typed languages type-checking occurs at run-time, opposed to statically typed which has compile time type-checking. This means that unlike languages such as C, C++, or Java (statically typed languages), a dynamically typed language variable can store any type whether it is an integer, double, or float.

Eloquent JavaScript will take me a couple days to read (really I should be studying for my exams!).

formats

Move the Web Forward

Yesterday I found an amazing website – Move the Web Forward. This site is an incredible asset, full of great links to tutorials and experts. A true learning playground of responsive web development. It is about more than just statically learning new tools and techniques, it is about sharing this knowledge with others and spreading the word.
My goal is to learn as much as I can to become an amazing web developer. Through doing that, I am going to continually add new postings here about what I am learning in hopes of passing on valuable knowledge to someone else. In return, I hope that if I make a mistake (only rarely I hope) someone will take the time to return the favour to me.

credit
© JSAdam