Monday, October 27, 2014

JQuery refresher

The sprint is wrapping up so why not spend a bit of time polishing my skillset... so lets do the code school course about JQuery.  The thing I have always loved about JQuery is the documentation.  The documentation of the library is a shining example for all other open source libraries.

Neat things I didn't know about even though working with JQuery for years well these are actually CSS things:

  • The child selector - Select only the child elements not all matching descendants.
    • Example: $("#destinations > li");
    • This is very cool.  I knew it was that easy to do.  Normally I would just give everything and id of class to get around this but I like this method of getting the children or use JQuery traversal.
    • Actually this is a CSS selector I did not know about.
  • Select multiple items - You can use one selector to select multiple items with different criteria.
    • Example: $(".promo, #france");
    • Again very cool.  This is something I likely could have used in the past when I used multiple selection statements or gave all the elements the same class.
    • Actually this is a CSS selector I did knew about but never thought about applying in JQuery.

I heart Code School.

Wednesday, October 15, 2014

Argument against Ternary Conditional Operators

Time to get up on my soapbox...

I was just doing the CodeSchool JavaScript best practices course and the very first item in is it something I could not disagree with more.

The Ternary Conditional Operator is one of the worst things to allowed in common programming language syntax.  Unless you trying to write your code to be as minimalist as possible to save every possible byte in your source files it should not be used.  The reduction of readability and maintainability when using the ternary operator far out weighs the advantages  of being less verbose and requiring less lines of code.


var isHero = true;
var canFly = true;

//normal if else 
var name;
if (isHero && canFly) {
   name = "Superman"
} else {
   name = "Vader"
}

//ternary conditional operator
var name = isHero && canFly ? "Superman" : "Vader";



Yes, it the ternary conditional operator is quicker and dare I say easier.  However I will wager that 100% of the engineers in the world can understand the standard if/else and just a glance where as with the ternary operator some of them will confuse the result and the majority will have to pause for a second or two to try to make sure the way ternary operators work in their head.  Does it mean you are smarter than the rest of the your team if you use ternary operators? No. It just means like pavlov's dog you have been trained to translate the syntax into an if/else without needing to think about it.  When debugging a complex important issue the majority of people do not wish to waste time translating code so they can understand it.  It slows the team down and frankly increases the chances of defects.  I would love it if I could ban ternary operators from use in all languages but Assembly.

...stepping off my soapbox.

Monday, October 13, 2014

my CoffeeScript intro

Always Be Learning

Let's learn CoffeeScript today.

What is CoffeeScript?  Well it is a front end script language that gets compiled down to Javascript.  It was developed with the goal of making Javascript more readable and understandable.

So Code School here we come... (course)


The fact that it has a command line compiler that compiles into Javascript is very interesting.  I like the feature of being able to set up a service to watch your code and auto compile it.

The Code School course initially does not seem as well developed as the one for AngularJS in terms of the challenges.  You can tell the CoffeeScript was made earlier.

Not a fan of:

  • @ symbol used in the place of 'this' keyword.
    • although it is slick when getting this.properties
      • @name
  • Optional brackets ( )  for function arguments; arguments are one of those things I like being explicit about.
  • Intenting aka whitespace is very important since it takes the place of brackets, commas, semicolons, and more.  This concerns me cause I know how character encoding can vary between operating systems and editors.  I can foresee this being a very tricky thing to get to the bottom of when trying to debug unexpected behavior. 

A fan of:

  • automatic creation of variables, no need to declare them explicitly
  • the code around conditionals seems human readable.
    • Examples:
      • if paid() and coffee() is on then pour()
      • addCaffeine() if not Decaf()
      • addCaffeine() unless Decaf()
    • This is something I like in my unit test code but not sure how I will feel about it later in my production code.
  • they way object orientation and inheritance is written in CoffeeScript in my opinion is more intuitive
  • "the fat arrow"... google it

Overall I think CoffeeScript is nice but I am not sure I see more value in it than I do just knowing JavaScript very well.  I would have to see it in an enterprise setting most likely to really see its value.