Happy Programming with CoffeeScript




                                 高見見龍龍
photo by yukop
高見見龍龍
a.k.a Eddie or Aquarianboy
 Live and work in Taipei, Taiwan.
 Serving in my own little tiny company.
 Flash / AS3 / Ruby / Rails / Python programming for living.
 Mac OS user, Objective-C for personal inerests.
 Technical Education and Consulant.
 PTT Flash BM (since 2007/4).
 Ruby Certified Programmer (Since 2012/1).
 Adobe Certified Flash Developer (Since 2006/7).
 Linux Professional Institue Certification (Since 2005/3).     photo by Eddie
Intro
 簡介
Popular
Popular

Powerful
Popular

 Powerful

Complicaed
Before   photo by Razlan
photo by Razlan
                  Now
seems
                         easy
photo by apple apple
photo by Marcus Q
Today, I am going o ell you..
Happy
 快樂
We’re not
                       alking
                    about this
                       kind of
                       coffee.

photo by Nick Humphries
Not this either.




photo by naotoj
I have no idea why engineers like
using food as their project name.
Jeremy
Ashkenas
       photo by jsconf
2009/12
and I sared o use
CoffeeScript since 2011/5
and I sared o use
CoffeeScript since 2011/5

   because of Rails
yet another new language !?
"It's just JavaScript"
just writen in different synax
borrowed from
Python, Ruby and Haskell.
and would be compiled ino
     JavaScript code
JSLint Compatible
So, it's still Javascript
"hmm.."
"It's just JavaScript"
"It's just JavaScript"
"I think it's just CoffeeScript"
whaever..

WTH can you do with
   CoffeeScript?
anything which JavaScript can do.
front-end, back-end, mobile.. ec.
but with less line of code..
        ~ 30% off
CoffeeScript compiler is writen in
           CoffeeScript
Is
                         JavaScript
                              that
                              bad?
photo by Bryan Gosline
the good parts
photo by Steve Ganz
CoffeeScript =
English-like grammar +
nice Synactic Sugar +
        Goodies
Syntax
  語法
indenations rule,
whiespace maters!
}
        }
    }
}
}
        }
    }
}
String Inerpolation
greeting = "hi, " + name + ", " + msg
greeting = "hi, #{name}, #{msg}"
semicolon
semicolon
var
var
->
say_hello = (msg) ->
   console.log "hello, JSDC"
var say_hello;
say_hello = function(msg) {
   return console.log("hello, JSDC");
};
default parameer
say_something = (msg = "JSDC") ->
 console.log "say #{msg}"
var say_something;

say_something = function(msg) {
   if (msg == null) {
      msg = "JSDC";
   }
   return console.log("say " + msg);
};
( ) is not always necessary.
greeting("eddie", "how are you");
greeting "eddie", "how are you"
everything is an expression
return is not necessary.
var hello;

hello = function() {
   return "hi, JSDC";
};
hello = ->
 "hi, JSDC"
Array
var a;
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
a = [1..10]
Loop
console.log i for i in [1..10]
var i, _i;

for (i = _i = 1; _i <= 10; i = ++_i) {
  console.log(i);
}
console.log "YES" if oday == 'JSDC'
Sugar
yes, no
A: “would you marry me?”
          B: true
A: “would you marry me?”
          B: yes
console.log "go home" if oday isnt "JSDC"
OO
Hello.prootype.greeting = function(name) {
   console.log("hi, " + name);
};
class Hello
    greeting: (name) ->
       console.log "hi, #{name}"
class Hello
  construcor: (@name) ->

 greeting: (msg) ->
   "hi, #{@name}, #{msg}"
var Hello;
Hello = (function() {
   Hello.name = 'Hello';
   function Hello(name) {
      this.name = name;
   }
   Hello.prootype.greeting = function(msg) {
      return "hi, " + this.name + ", " + msg;
   };
   return Hello;
})();
Diff?
 差別?
the Original Way

  Your Brain

  JavaScript

   Browser
the CoffeeScript way

    Your Brain

   CoffeeScript

    JavaScript

     Browser
lots of languages that compile o JS
           http://goo.gl/nkAkQ
Ref
參考
RTFM, it's awesome!
   http://coffeescript.org/
or my shameless promotion blog
 http://blog.eddie.com.tw/caegory/coffeescript/
Let’s get our feet wet!
photo by jlhopes
Demo
 展示
But..
 巴特..
CoffeeScript is not so perfect
Readability != Comprehension
People may still wrie
CoffeeScript as horribly as they
       wroe JavaScript..
indenations rule,
whiespace maters!
( ) is not always necessary.
Debugging ool?
You've beter have a human
CoffeeScript compiler in your head!
Then..
  然後..
CoffeeScript is not used o replace
            JavaScript.
If you don’t know Javascript, and
you think CoffeeScript can save
your life..
you would be in trouble.
So..
 所以..
Who is using CoffeeScript?
actually, I don't really care!
Who won't need this?
People who don't like CoffeeScript.
People who already know
javascript(the good parts) very
well.
Who might need/like this?
someone who don't like ;
someone who don't like { }
someone who don't like the
      PROTOTYPE.
Rails developer
Anyway
  總之
Should I learn CoffeeScript?
Is it worth it?
IMHO
 拙見
You should..
learn JavaScript!
learn JavaScript!
learn JavaScript!
learn JavaScript!
.. and use CoffeeScript !
oally worth it!
I can't go back
   anymore!
give it a try
Happy?
  快樂?
END
 結束
Conacts
高見見龍龍   Websie
        Blog
                   http://www.eddie.com.tw
                   http://blog.eddie.com.tw
        Plurk      http://www.plurk.com/aquarianboy
        Facebook   http://www.facebook.com/eddiekao
        Google Plus http://www.eddie.com.tw/+
        Twiter    https://twiter.com/#!/eddiekao
        Email      eddie@digik.com.tw
        Mobile     +886-928-617-687




                                                      photo by Eddie

Happy Programming with CoffeeScript