Tuesday, January 18, 2011

Sign-up task 2

I've got the code, but I still haven't figured out how to get the html code hosted so I can link to it as a web page.

I hope that you will accept this in the meantime! When I get it hosted, I will put up a link.

Sign-up task

Prior to watching this first video of the course, my knowledge of JavaScript was extremely nebulous - I knew it was a vital front-end development piece in my quest to gather familiarity with all parts of the programming process, and that was about it. Doug Crockford at least starts out the lecture saying that it is the most misunderstood programming language - so I'm not alone!

From his intro, I learned that there seems to be a lot of confusion about the program and its abilities and limitations. Crockford is of the opinion that there is poor documentation and poorly written books on the language, but notwithstanding it is a fully functional language.

Javascript's history is seemingly embroiled in the competitive business landscape. Jim Gosling at Sun Microsystems first created a new language that later came to be called Java, which Netscape used as a reference for its simpler language - LiveScript. In an effort to take power away from Microsoft, Netscape and Java attempted to band together, and in the process, the name of LiveScript was changed to Javascript. Not to be left behind, Microsoft reverse-engineered the language (calling their identical language JScript to avoid trademark issues). Netscape's attempt to make their Javascript language an industry standard ended up in their losing control of the course of the language to Microsoft (a more powerful player in the European industrial group to which Netscape lobbied).

Similar to Django, which I am simultaneously trying to learn, Javascript was built on a set of key ideas. Those covered in the video are:
  • load and go delivery, which means that programs are delivered to execution site as source code (text)
  • loose typing: controversial, can't check as much before being deployed --> programs are easier to write
  • objects as general containers which means that objects are now completely dynamic
  • prototypal inheritance: objects inherit from other objects and there are no classes
  • lamda: functions are used as first class objects
  • linkage through global variables: units combined in a global namespace (which can lead to security problems!)

The remainder of the video covered fine points related to the six different basic pieces of Javascript: numbers, strings, boolean, null, undefined and objects. Some highlights for me personally were:
  • Unlike Python, Javascript has just one number type - 64-bit floating point
  • The value NaN means "not a number", and is toxic and will flow to the end if it happens during a program.
  • Strings seem to work similarly as in Python - there is no difference between single or double quotes, they are immutable and they come with many built-in methods
  • There are just two boolean values - True and False
  • If you don't define a variable, it gets given the value of "undefined"

Crockford spent more time on objects and made a big point to correct the wrong assumption that Javascript isn't an object-oriented language. (Lucky for me, I haven't heard anything, so there is no knowledge that I have to unlearn!). I picked up many tips that I am eager to use as I become more familiar with this language. Some highlights for me were:
  • Attributes or members can be accessed with both dot notation and script notation
  • Any parameter can receive any type of object (this is an example of the loose typing
  • There are a ton of reserved words, which aren't all used in the actual program
  • Comments are made with // or /*
  • As with Python, operator overloading occurs with +
  • == and != can be type coercive, so it's saver to use === or !== to compare value AND type

These next two topics are a little tricky for me, and I am eager to actually see them in use so I can get a better understanding:
  • Guard operator && - used to avoid null references. It picks the first or second operand, depending on whether the first is "truthy" (picks second operand) or not (picks first operand).
  • Default operator || - works like && except opposite - if first operand is truthy, picks first operand. If not, picks the second.
I am eager to learn more about code itself and I was a bit disappointed that the video did not show us any code that we could analyze and learn from. Hopefully this course will give us some good resources. I always learn best when I can DO and see concepts in action.