SlideShare a Scribd company logo
CoffeeScript
                        a better way to write javascrip




photo by SixRevisions
You can get this slide on
www.eddie.com.tw/slides
Who am I ?
I’m a Flash guy.




photo by JD Hancock
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.
 A little bit Objective-C for personal inerests.
 Technical Education and Consulant.
 PTT Flash BM (since 2007/4).
 Adobe Certificaed Flash Developer (Since 2006/7).
 Linux Professional Institue Certification (Since 2005/3).
                                                               photo by Eddie
or just google me with keyword "   "
JavaScript
                becomes
                hugely
                popular.
                9th on TIOBE, Nov 2011

photo by gr3m
JavaScript
                       seems
photo by apple apple
                       easy..
But it’s
not easy
o wrie
good
JavaScript
code.
             photo by Marcus Q
Today, I won't ell you..
   You should give up the way you did
I am going o ell you..
Maybe you have a better way to do with this
CoffeeScript
We’re not
                      alking
                   about this
                      kind of
                      coffee.
photo by Nick Humphries
WTF?
CoffeeScript is JavaScript
     just written with different syntax
..exposes the good parats of
JavaScript in a simple way.
Synax borrowed from
  Python and Ruby.
      I love Python & Ruby
..and will be compiled ino
JavaScript code.
..that doesn’t mean you can
have no knowledge about
JavaScript.
CoffeeScript is not used
 o replace JavaScript.
Let’s get our feet wet!
photo by jlhopes
Insall
          photo by Daniel Dionne
Requirements
You need o insall some software first..

    Node.js
     >   git clone git://github.com/joyent/node.git
     >   cd node
     >   ./configure
     >   make
     >   sudo make insall
Requirements
You need o insall some software first..

    NPM, the “node package manager”
     > curl http://npmjs.org/insall.sh | sh
Insall CoffeeScript

  CoffeeScript
   > npm insall coffee-script
   > coffee -v
   CoffeeScript version 1.1.3




     http://blog.eddie.com.w/2011/08/03/install-coffeescrip/
How o use


        photo by roboppy
Usage
Compile *.coffee ino *.js

    Compile
     > coffee --wach --compile app.coffee




  http://blog.eddie.com.w/2011/08/03/how-to-use-coffeescrip-compiler/
Synax
         photo by zigazou76
}
        }
    }
}
No { }
indenations rule!
    whitespace matters!
( ) is not necessary.
No trailing semicolon.
Return is not necessary.
      everything is an expression
No { }, (), and ;
 if(age > 20){
     voe();
 }


                    // javascript


 if age > 20
     voe()



                    # coffeescript
Variable & Function
Variable
You don’t have o declare it before using it.

 lang = ["php", "python", "perl", "ruby"]
 name = "Eddie"


                                                # coffeescript


 var lang, name;
 lang = ["php", "python", "perl", "ruby"];
 name = "Eddie";


                                                // javascript
Function
say_hello = (guest1, guest2 = "Nayumi") ->
   "Hello #{guest1} and #{guest2}"

say_hello "Eddie"

                                                  # coffeescript


var say_hello;
say_hello = function(guest1, guest2) {
   if (guest2 == null) {
       guest2 = "Nayumi";
   }
   return "Hello " + guest1 + " and " + guest2;
};
say_hello("Eddie");
                                                  // javascript
Array
Array
heroes = [
   'Spider Man',
   'Capain America',
   'X-men',
   'Iron Man'
]

students = [1..10]
eachers = [1...10]                                                # coffeescript


var heroes, students, eachers;
heroes = ['Spider Man', 'Capain America', 'X-men', 'Iron Man'];
students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
eachers = [1, 2, 3, 4, 5, 6, 7, 8, 9];

                                                                   // javascript
Array
heroes[0..2]
heroes[1..2] = ["Batman", "ThunderCat"]




                                                               # coffeescript


 heroes.slice(0, 3);

 var _ref;
 [].splice.apply(heroes, [1, 2].concat(_ref = ["Batman", "ThunderCat"])), _ref;


                                                                // javascript
Object
Object
eddie = { name: "Eddie Kao", age: 18, speciality: "eat" }




                                                      # coffeescript


var eddie;
eddie = {
   name: "Eddie Kao",
   age: 18,
   speciality: "eat"
};
                                                       // javascript
Object
eddie =                   var eddie;
 name: "Eddie Kao"        eddie = {
 age: 18                     name: "Eddie Kao",
 lovers:                     age: 18,
   nayumi:                   lovers: {
    name: "Nayumi Hung"        nayumi: {
    age: 18                       name: "Nayumi Hung",
   mary:                          age: 18
    name: "Mary Bloody"        },
    age: 20                    mary: {
                                  name: "Mary Bloody",
                                  age: 20
                               }
                             }
                          };


# coffeescript                               // javascript
Loop
Loop
alert i for i in [1..10]          var i, _sep;
                                  for (i = 1; i <= 10; i++) {
                                    alert(i);
                                  }
alert i for i in [1..10] when i   for (i = 1; i <= 10; i++) {
% 2 == 0                            if (i % 2 === 0) {
                                      alert(i);
                                    }
                                  }
alert i for i in [1..10] by 2     for (i = 1, _sep = 2; i <= 10; i +=
                                  _sep) {
                                    alert(i);
                                  }
alert i * 2 for i in [1..10]      for (i = 1; i <= 10; i++) {
                                    alert(i * 2);
# coffeescript                    }                      // javascript
Modifier
Modifier
You can put "if", "unless", "while", "until" behind

 if (age > 20) {
   voe();
 }



                                                      // javascript


 voe() if age > 20



                                                      # coffeescript
Synactic Sugar
Synactic Sugar
wrie more readable code by using synactic sugar.
# coffeescript                                // javascript

  is                                               ===
  isnt                                              !==
  true, on, yes                                   true
  false, off, no                                  false
  not                                                  !
  and                                              &&
  or                                                 ||
  unless                                        if not
  until                                      while not
  of                                                 in
Synactic Sugar
alert "I can't see anything" if light is off

alert "It's impossible!" if eddie isnt handsome

if girl is not single
    alert "Don't Touch! Be Careful!"
                                                  # coffeescript

if (light === false) {
     alert("I can't see anything");
}
if (eddie !== handsome) {
     alert("It's impossible!");
}
if (girl === !single) {
     alert("Don't Touch! Be Careful!");
}                                                 // javascript
Synactic Sugar

 if (Answer === true) {
     alert("I'll marry you!");
 }

                                      // javascript



    alert "I'll marry you!" if Answer is yes
Synactic Sugar
age ?= 18
                                                   # coffeescript


if (typeof age !== "undefined" && age !== null) {
     age;
} else {
     age = 18;
};
                                                   // javascript
Raw JavaScript
If you still prefer the original way
Raw JavaScript
say_hello = `function(name){
   return "Hello, " + name
}`


                               # coffeescript


var say_hello;
say_hello = function(name){
   return "Hello, " + name
};



                               // javascript
OOP
OOP - new
class Animal
   construcor: (name, age) ->
       this.name = name
       this.age = age

animal = new Animal("eddie", 18)
alert animal                        # coffeescript

var Animal, animal;
Animal = (function() {
   function Animal(name, age) {
      this.name = name;
      this.age = age;
   }
   return Animal;
})();
animal = new Animal("eddie", 18);
alert(animal);                      // javascript
OOP - method
class Animal
   construcor: (@name, @age) ->

   say_hello: (something) ->
      console.log "Hello, #{something}"

animal = new Animal("eddie", 18)
animal.say_hello("CoffeeScript")                        # coffeescript

var Animal, animal;
Animal = (function() {
   function Animal(name, age) {
      this.name = name;
      this.age = age;
   }
   Animal.prootype.say_hello = function(something) {
      return console.log("Hello, " + something);
   };
   return Animal;
})();
animal = new Animal("eddie", 18);                       // javascript
animal.say_hello("CoffeeScript");
OOP - inheriance
class Animal
   construcor: (@name, @age) ->
   say_hello: (something) ->
       alert "Hello, #{something}"

class Human exends Animal
   walk: ->
       alert "I can walk with my foots!"

eddie = new Human("eddie", 18)
eddie.say_hello "CoffeeScript"
eddie.walk()
                                           # coffeescript



TL; DR                                     // javascript
References
Websies:
 http://jashkenas.github.com/coffee-scrip/
 http://blog.eddie.com.w/category/coffeescrip/


Book:
 http://pragprog.com/book/tbcoffee/coffeescrip
the good parts
photo by Steve Ganz
                               I love
I Love..




              Coding Style
           I love Python & Ruby, of course :)
I Love..




           Indenation!
I Love..




    Anonymous function
     No global function and variable by default
I Love..




     String Inerpolation
       sorry, but string building really sucks :)
I Love..




     List Comprehension
I Love..




           Synactic Sugar
I Love..




    English-like grammar
  alert "of course it is!" if PHPConf is awesome
I Love..




  Comparison & Equality
           "true" == true // true
           "true" === true // false
I Love..



    Works with other JS
     frameworks well.
           Because it’s just JavaScrip
I Love..




           Compilation
            JSLint Approved
What else?
CoffeeScript compiler is
writen in CoffeeScript.
Tianium Mobile



http://blog.eddie.com.w/2011/08/03/using-coffeescrip-in-titanium-studio/
photo by Andrew
Immature?
            photo by theseanster93
Performance?
photo by chr1sl4i           photo by theseanster93
CoffeeScript Means Giving
Up on JavaScript?
Learn JavaScript, and Use
CoffeeScript.
Any Question?   photo by jamuraa
Conacts
     Websie    http://www.eddie.com.tw
     Blog       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

More Related Content

What's hot

5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
Todd Anglin
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer Toolbox
Jeff Strauss
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
Robert Nyman
 
Ruby
RubyRuby
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
Bert Wijnants
 
JavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayJavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDay
Robert Nyman
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
Jarod Ferguson
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
Mohd Saeed
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
Aizat Faiz
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
Michael Girouard
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
pratiknaik
 
JavaScript and HTML5 - Brave New World (revised)
JavaScript and HTML5 - Brave New World (revised)JavaScript and HTML5 - Brave New World (revised)
JavaScript and HTML5 - Brave New World (revised)
Robert Nyman
 
CoffeeScript in 5mins
CoffeeScript in 5minsCoffeeScript in 5mins
CoffeeScript in 5mins
Masakuni Kato
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
Rebecca Murphey
 
DSLs Internas e Ruby
DSLs Internas e RubyDSLs Internas e Ruby
DSLs Internas e Ruby
Fabio Kung
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friends
Good Robot
 
Javascript - The Good, the Bad and the Ugly
Javascript - The Good, the Bad and the UglyJavascript - The Good, the Bad and the Ugly
Javascript - The Good, the Bad and the Ugly
Thorsten Suckow-Homberg
 
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesJavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
Robert Nyman
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
Sylvain Zimmer
 

What's hot (20)

5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer Toolbox
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 
Ruby
RubyRuby
Ruby
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 
JavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayJavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDay
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
 
JavaScript and HTML5 - Brave New World (revised)
JavaScript and HTML5 - Brave New World (revised)JavaScript and HTML5 - Brave New World (revised)
JavaScript and HTML5 - Brave New World (revised)
 
CoffeeScript in 5mins
CoffeeScript in 5minsCoffeeScript in 5mins
CoffeeScript in 5mins
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
 
DSLs Internas e Ruby
DSLs Internas e RubyDSLs Internas e Ruby
DSLs Internas e Ruby
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friends
 
Javascript - The Good, the Bad and the Ugly
Javascript - The Good, the Bad and the UglyJavascript - The Good, the Bad and the Ugly
Javascript - The Good, the Bad and the Ugly
 
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesJavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 

Viewers also liked

AS3 Better Practices
AS3 Better PracticesAS3 Better Practices
AS3 Better Practices
Eddie Kao
 
Code Reading
Code ReadingCode Reading
Code Reading
Eddie Kao
 
Forumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate AffairForumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate Affair
guest06ed72
 
Flash Ecosystem and Open Source
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open SourceEddie Kao
 
測試
測試測試
測試
Eddie Kao
 
Agenda 6è b setmana 02-gener-curs 16-17
Agenda 6è b setmana 02-gener-curs 16-17Agenda 6è b setmana 02-gener-curs 16-17
Agenda 6è b setmana 02-gener-curs 16-17
6sise
 

Viewers also liked (6)

AS3 Better Practices
AS3 Better PracticesAS3 Better Practices
AS3 Better Practices
 
Code Reading
Code ReadingCode Reading
Code Reading
 
Forumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate AffairForumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate Affair
 
Flash Ecosystem and Open Source
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open Source
 
測試
測試測試
測試
 
Agenda 6è b setmana 02-gener-curs 16-17
Agenda 6è b setmana 02-gener-curs 16-17Agenda 6è b setmana 02-gener-curs 16-17
Agenda 6è b setmana 02-gener-curs 16-17
 

Similar to CoffeeScript

JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New World
Robert Nyman
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
None
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
Ben Scheirman
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Ryan McGeary
 
CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better!
Jack Franklin
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScript
Eddie Kao
 
WappZapp & Appcelerator Titanium
WappZapp & Appcelerator TitaniumWappZapp & Appcelerator Titanium
WappZapp & Appcelerator Titanium
Wienke Giezeman
 
bol.com Partner event 2013 - Presentatie Wienke Giezeman
bol.com Partner event 2013 - Presentatie Wienke Giezemanbol.com Partner event 2013 - Presentatie Wienke Giezeman
bol.com Partner event 2013 - Presentatie Wienke Giezeman
bolcompp
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
jeresig
 
CoffeeScript - en introduksjon
CoffeeScript - en introduksjonCoffeeScript - en introduksjon
CoffeeScript - en introduksjon
Kamikaze Media AS
 
Node.js for PHP developers
Node.js for PHP developersNode.js for PHP developers
Node.js for PHP developers
Andrew Eddie
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Raimonds Simanovskis
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worlds
Ignacio Martín
 
Coffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesCoffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotes
Brandon Satrom
 
Modern Perl
Modern PerlModern Perl
Modern Perl
Marcos Rebelo
 
Scala.js
Scala.jsScala.js
Scala.js
Vitaly Tsaplin
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Scott Leberknight
 
Coffee script
Coffee scriptCoffee script
Coffee script
Night Wolf
 
Javascript The Good Parts
Javascript The Good PartsJavascript The Good Parts
Javascript The Good Parts
Federico Galassi
 

Similar to CoffeeScript (20)

JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New World
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better!
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScript
 
WappZapp & Appcelerator Titanium
WappZapp & Appcelerator TitaniumWappZapp & Appcelerator Titanium
WappZapp & Appcelerator Titanium
 
bol.com Partner event 2013 - Presentatie Wienke Giezeman
bol.com Partner event 2013 - Presentatie Wienke Giezemanbol.com Partner event 2013 - Presentatie Wienke Giezeman
bol.com Partner event 2013 - Presentatie Wienke Giezeman
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
 
CoffeeScript - en introduksjon
CoffeeScript - en introduksjonCoffeeScript - en introduksjon
CoffeeScript - en introduksjon
 
Node.js for PHP developers
Node.js for PHP developersNode.js for PHP developers
Node.js for PHP developers
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worlds
 
Coffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesCoffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotes
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Scala.js
Scala.jsScala.js
Scala.js
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Coffee script
Coffee scriptCoffee script
Coffee script
 
Javascript The Good Parts
Javascript The Good PartsJavascript The Good Parts
Javascript The Good Parts
 

More from Eddie Kao

Rails girls in Taipei
Rails girls in TaipeiRails girls in Taipei
Rails girls in Taipei
Eddie Kao
 
Rails Girls in Taipei
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in Taipei
Eddie Kao
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
Eddie Kao
 
iOS app development and Open Source
iOS app development and Open SourceiOS app development and Open Source
iOS app development and Open Source
Eddie Kao
 
Vim
VimVim
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
Eddie Kao
 
CreateJS - from Flash to Javascript
CreateJS - from Flash to JavascriptCreateJS - from Flash to Javascript
CreateJS - from Flash to Javascript
Eddie Kao
 
May the source_be_with_you
May the source_be_with_youMay the source_be_with_you
May the source_be_with_youEddie Kao
 
Why I use Vim
Why I use VimWhy I use Vim
Why I use Vim
Eddie Kao
 
There is something about Event
There is something about EventThere is something about Event
There is something about Event
Eddie Kao
 
Ruby without rails
Ruby without railsRuby without rails
Ruby without rails
Eddie Kao
 
API Design
API DesignAPI Design
API Design
Eddie Kao
 
3rd AS Study Group
3rd AS Study Group3rd AS Study Group
3rd AS Study GroupEddie Kao
 
iOS Game Development with Cocos2d
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2d
Eddie Kao
 
AS3讀書會(行前準備)
AS3讀書會(行前準備)AS3讀書會(行前準備)
AS3讀書會(行前準備)
Eddie Kao
 
Misunderstanding about flash
Misunderstanding about flashMisunderstanding about flash
Misunderstanding about flashEddie Kao
 
Refactoring in AS3
Refactoring in AS3Refactoring in AS3
Refactoring in AS3
Eddie Kao
 
Test
TestTest
Test
Eddie Kao
 

More from Eddie Kao (19)

Rails girls in Taipei
Rails girls in TaipeiRails girls in Taipei
Rails girls in Taipei
 
Rails Girls in Taipei
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in Taipei
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
 
iOS app development and Open Source
iOS app development and Open SourceiOS app development and Open Source
iOS app development and Open Source
 
Vim
VimVim
Vim
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
 
CreateJS - from Flash to Javascript
CreateJS - from Flash to JavascriptCreateJS - from Flash to Javascript
CreateJS - from Flash to Javascript
 
May the source_be_with_you
May the source_be_with_youMay the source_be_with_you
May the source_be_with_you
 
Why I use Vim
Why I use VimWhy I use Vim
Why I use Vim
 
There is something about Event
There is something about EventThere is something about Event
There is something about Event
 
Ruby without rails
Ruby without railsRuby without rails
Ruby without rails
 
API Design
API DesignAPI Design
API Design
 
3rd AS Study Group
3rd AS Study Group3rd AS Study Group
3rd AS Study Group
 
iOS Game Development with Cocos2d
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2d
 
AS3讀書會(行前準備)
AS3讀書會(行前準備)AS3讀書會(行前準備)
AS3讀書會(行前準備)
 
AMF
AMFAMF
AMF
 
Misunderstanding about flash
Misunderstanding about flashMisunderstanding about flash
Misunderstanding about flash
 
Refactoring in AS3
Refactoring in AS3Refactoring in AS3
Refactoring in AS3
 
Test
TestTest
Test
 

Recently uploaded

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 

Recently uploaded (20)

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 

CoffeeScript

  • 1. CoffeeScript a better way to write javascrip photo by SixRevisions
  • 2.
  • 3. You can get this slide on www.eddie.com.tw/slides
  • 5. I’m a Flash guy. photo by JD Hancock
  • 6. 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. A little bit Objective-C for personal inerests. Technical Education and Consulant. PTT Flash BM (since 2007/4). Adobe Certificaed Flash Developer (Since 2006/7). Linux Professional Institue Certification (Since 2005/3). photo by Eddie
  • 7. or just google me with keyword " "
  • 8. JavaScript becomes hugely popular. 9th on TIOBE, Nov 2011 photo by gr3m
  • 9. JavaScript seems photo by apple apple easy..
  • 10. But it’s not easy o wrie good JavaScript code. photo by Marcus Q
  • 11. Today, I won't ell you.. You should give up the way you did
  • 12. I am going o ell you.. Maybe you have a better way to do with this
  • 14. We’re not alking about this kind of coffee. photo by Nick Humphries
  • 15. WTF?
  • 16. CoffeeScript is JavaScript just written with different syntax
  • 17. ..exposes the good parats of JavaScript in a simple way.
  • 18. Synax borrowed from Python and Ruby. I love Python & Ruby
  • 19. ..and will be compiled ino JavaScript code.
  • 20. ..that doesn’t mean you can have no knowledge about JavaScript.
  • 21. CoffeeScript is not used o replace JavaScript.
  • 22. Let’s get our feet wet! photo by jlhopes
  • 23. Insall photo by Daniel Dionne
  • 24. Requirements You need o insall some software first.. Node.js > git clone git://github.com/joyent/node.git > cd node > ./configure > make > sudo make insall
  • 25. Requirements You need o insall some software first.. NPM, the “node package manager” > curl http://npmjs.org/insall.sh | sh
  • 26. Insall CoffeeScript CoffeeScript > npm insall coffee-script > coffee -v CoffeeScript version 1.1.3 http://blog.eddie.com.w/2011/08/03/install-coffeescrip/
  • 27. How o use photo by roboppy
  • 28. Usage Compile *.coffee ino *.js Compile > coffee --wach --compile app.coffee http://blog.eddie.com.w/2011/08/03/how-to-use-coffeescrip-compiler/
  • 29. Synax photo by zigazou76
  • 30. } } } }
  • 31. No { } indenations rule! whitespace matters!
  • 32. ( ) is not necessary.
  • 34. Return is not necessary. everything is an expression
  • 35. No { }, (), and ; if(age > 20){ voe(); } // javascript if age > 20 voe() # coffeescript
  • 37. Variable You don’t have o declare it before using it. lang = ["php", "python", "perl", "ruby"] name = "Eddie" # coffeescript var lang, name; lang = ["php", "python", "perl", "ruby"]; name = "Eddie"; // javascript
  • 38. Function say_hello = (guest1, guest2 = "Nayumi") -> "Hello #{guest1} and #{guest2}" say_hello "Eddie" # coffeescript var say_hello; say_hello = function(guest1, guest2) { if (guest2 == null) { guest2 = "Nayumi"; } return "Hello " + guest1 + " and " + guest2; }; say_hello("Eddie"); // javascript
  • 39. Array
  • 40. Array heroes = [ 'Spider Man', 'Capain America', 'X-men', 'Iron Man' ] students = [1..10] eachers = [1...10] # coffeescript var heroes, students, eachers; heroes = ['Spider Man', 'Capain America', 'X-men', 'Iron Man']; students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; eachers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // javascript
  • 41. Array heroes[0..2] heroes[1..2] = ["Batman", "ThunderCat"] # coffeescript heroes.slice(0, 3); var _ref; [].splice.apply(heroes, [1, 2].concat(_ref = ["Batman", "ThunderCat"])), _ref; // javascript
  • 43. Object eddie = { name: "Eddie Kao", age: 18, speciality: "eat" } # coffeescript var eddie; eddie = { name: "Eddie Kao", age: 18, speciality: "eat" }; // javascript
  • 44. Object eddie = var eddie; name: "Eddie Kao" eddie = { age: 18 name: "Eddie Kao", lovers: age: 18, nayumi: lovers: { name: "Nayumi Hung" nayumi: { age: 18 name: "Nayumi Hung", mary: age: 18 name: "Mary Bloody" }, age: 20 mary: { name: "Mary Bloody", age: 20 } } }; # coffeescript // javascript
  • 45. Loop
  • 46. Loop alert i for i in [1..10] var i, _sep; for (i = 1; i <= 10; i++) { alert(i); } alert i for i in [1..10] when i for (i = 1; i <= 10; i++) { % 2 == 0 if (i % 2 === 0) { alert(i); } } alert i for i in [1..10] by 2 for (i = 1, _sep = 2; i <= 10; i += _sep) { alert(i); } alert i * 2 for i in [1..10] for (i = 1; i <= 10; i++) { alert(i * 2); # coffeescript } // javascript
  • 48. Modifier You can put "if", "unless", "while", "until" behind if (age > 20) { voe(); } // javascript voe() if age > 20 # coffeescript
  • 50. Synactic Sugar wrie more readable code by using synactic sugar. # coffeescript // javascript is === isnt !== true, on, yes true false, off, no false not ! and && or || unless if not until while not of in
  • 51. Synactic Sugar alert "I can't see anything" if light is off alert "It's impossible!" if eddie isnt handsome if girl is not single alert "Don't Touch! Be Careful!" # coffeescript if (light === false) { alert("I can't see anything"); } if (eddie !== handsome) { alert("It's impossible!"); } if (girl === !single) { alert("Don't Touch! Be Careful!"); } // javascript
  • 52. Synactic Sugar if (Answer === true) { alert("I'll marry you!"); } // javascript alert "I'll marry you!" if Answer is yes
  • 53. Synactic Sugar age ?= 18 # coffeescript if (typeof age !== "undefined" && age !== null) { age; } else { age = 18; }; // javascript
  • 54. Raw JavaScript If you still prefer the original way
  • 55. Raw JavaScript say_hello = `function(name){ return "Hello, " + name }` # coffeescript var say_hello; say_hello = function(name){ return "Hello, " + name }; // javascript
  • 56. OOP
  • 57. OOP - new class Animal construcor: (name, age) -> this.name = name this.age = age animal = new Animal("eddie", 18) alert animal # coffeescript var Animal, animal; Animal = (function() { function Animal(name, age) { this.name = name; this.age = age; } return Animal; })(); animal = new Animal("eddie", 18); alert(animal); // javascript
  • 58. OOP - method class Animal construcor: (@name, @age) -> say_hello: (something) -> console.log "Hello, #{something}" animal = new Animal("eddie", 18) animal.say_hello("CoffeeScript") # coffeescript var Animal, animal; Animal = (function() { function Animal(name, age) { this.name = name; this.age = age; } Animal.prootype.say_hello = function(something) { return console.log("Hello, " + something); }; return Animal; })(); animal = new Animal("eddie", 18); // javascript animal.say_hello("CoffeeScript");
  • 59. OOP - inheriance class Animal construcor: (@name, @age) -> say_hello: (something) -> alert "Hello, #{something}" class Human exends Animal walk: -> alert "I can walk with my foots!" eddie = new Human("eddie", 18) eddie.say_hello "CoffeeScript" eddie.walk() # coffeescript TL; DR // javascript
  • 61. the good parts photo by Steve Ganz I love
  • 62. I Love.. Coding Style I love Python & Ruby, of course :)
  • 63. I Love.. Indenation!
  • 64. I Love.. Anonymous function No global function and variable by default
  • 65. I Love.. String Inerpolation sorry, but string building really sucks :)
  • 66. I Love.. List Comprehension
  • 67. I Love.. Synactic Sugar
  • 68. I Love.. English-like grammar alert "of course it is!" if PHPConf is awesome
  • 69. I Love.. Comparison & Equality "true" == true // true "true" === true // false
  • 70. I Love.. Works with other JS frameworks well. Because it’s just JavaScrip
  • 71. I Love.. Compilation JSLint Approved
  • 76. Immature? photo by theseanster93
  • 77. Performance? photo by chr1sl4i photo by theseanster93
  • 79. Learn JavaScript, and Use CoffeeScript.
  • 80. Any Question? photo by jamuraa
  • 81. Conacts Websie http://www.eddie.com.tw Blog 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