SlideShare a Scribd company logo
CoffeeScript
   Petr Pokorný
Obsah


Co to je?
Proč to používat?
Jak to vypadá?
Jak to rozchodit?
Co to je?
Co to je?

CoffeeScript is a little language that compiles
into JavaScript.
Co to je?

CoffeeScript is a little language that compiles
into JavaScript.




The code compiles one-to-one into the
equivalent JS, and there is no interpretation
at runtime.
JavaScript je v jádru docela dobrý jazyk, ale…
JavaScript je v jádru docela dobrý jazyk, ale…


“   JavaScript had to look like Java only less so, be
    Java’s dumb kid brother or boy-hostage sidekick.
JavaScript je v jádru docela dobrý jazyk, ale…


“   JavaScript had to look like Java only less so, be
    Java’s dumb kid brother or boy-hostage sidekick.

    Plus, I had to be done in ten days or something
    worse than JavaScript would have happened.
                                                     ”
                                      — Brendan Eich
Proč to používat?
Proč to používat?


Rychlejší vývoj
Proč to používat?


Rychlejší vývoj

Méně bugů
Proč to používat?


Rychlejší vývoj

Méně bugů

Lepší čitelnost
Jak to vypadá?




JavaScript     CoffeeScript
Functions


var cube, square;
square = function(x) {
   return x * x;           square = (x) -> x * x
};
cube = function(x) {       cube = (x) -> square(x) * x
   return square(x) * x;
};




      JavaScript                CoffeeScript
Objects

var kids = {            kids =
   brother: {             brother:
     name: "Max",           name: "Max"
     age: 11                age: 11
   },                     sister:
   sister: {                name: "Ida"
     name: "Ida",           age: 9
     age: 9
   }
};



      JavaScript              CoffeeScript
If, Else, Conditional Assignment


var date, mood;
if (singing) {                mood = greatlyImproved if singing
  mood = greatlyImproved;
}
if (happy && knowsIt) {       if happy and knowsIt
  clapsHands();                 clapsHands()
  chaChaCha();                  chaChaCha()
} else {                      else
  showIt();                     showIt()
}
date = friday ? sue : jill;   date = if friday then sue else jill



        JavaScript                    CoffeeScript
OOP
var Animal, Horse, Snake, sam, tom;
var __hasProp = Object.prototype.hasOwnProperty, __extends =
                                                                     class Animal
function(child, parent) {                                              constructor: (@name) ->
  for (var key in parent) {
 if (__hasProp.call(parent, key)) child[key] = parent[key]; }
  function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
                                                                       move: (meters) ->
child.prototype = new ctor; child.__super__ = parent.prototype;          alert @name +" moved "+ meters +"m."
return child;};Animal = (function() {
  function Animal(name) { this.name = name; }
  Animal.prototype.move = function(meters) {                         class Snake extends Animal
     return alert(this.name + " moved " + meters + "m.");
  };                                                                   move: ->
return Animal;})();
Snake = (function() { __extends(Snake, Animal); function
                                                                         alert "Slithering..."
Snake() {     Snake.__super__.constructor.apply(this, arguments);        super 5
} Snake.prototype.move = function() {      alert("Slithering...");
return Snake.__super__.move.call(this, 5); }; return
Snake;})();                                                          class Horse extends Animal
Horse = (function() { __extends(Horse, Animal); function
Horse() {                                                              move: ->
  }
    Horse.__super__.constructor.apply(this, arguments);                  alert "Galloping..."
Horse.prototype.move = function() {                                      super 45
    alert("Galloping...");    return
Horse.__super__.move.call(this, 45);
}; return Horse;})();                                                sam = new Snake "Sammy the Python"
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");                               tom = new Horse "Tommy the Palomino"




                  JavaScript                                                    CoffeeScript
Na co jste zvyklí z Pythonu
Loops

# Eat lunch.
for food in ['toast', 'cheese', 'wine']:
  eat(food)



# Eat lunch.
eat food for food in ['toast', 'cheese', 'wine']
Loops

# Eat lunch.
for food in ['toast', 'cheese', 'wine']:
  eat(food)



# Eat lunch.
eat food for food in ['toast', 'cheese', 'wine']


var food, _i, _len, _ref;
_ref = ['toast', 'cheese', 'wine'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  food = _ref[_i];
  eat(food);
}
Loops

for key in {‘foo’: ‘bar’}

for key, value in {‘foo’: ‘bar’}.items()




for key of {foo: ‘bar’}

for key, value of {foo: ‘bar’}
Ranges

for i in range(1, 10)

for i in range(10, 1, -1)

for i in range(1, 10, 2)


for i in [1..9] # nebo [1...10]

for i in [10..2]

for i in [1..9] by 2
Comprehensions


short_names = [name for name in list if len(name) < 5]




shortNames = (name for name in list when name.length < 5)
Slicing

my_list[3:6]

my_list[3:]

my_list[:-3]


myList[3..5]

myList[3..]

myList[...-3]
Slicing

my_list[3:6] = [1, 2, 3]

my_list[3:]

my_list[:-3]


myList[3..5] = [1, 2, 3]

myList[3..]

myList[...-3]
Splats
(a.k.a. argument list unpacking)




def foo(bar, *args): pass




foo = (bar, args...) ->
Chained Comparisons



 cholesterol = 127

 healthy = 200 > cholesterol > 60
more...
The Existential Operator


           alert "I knew it!" if elvis?




if (typeof elvis !== "undefined" && elvis !== null) {
  alert("I knew it!");
}
Destructuring Assignment

theBait = 1000
theSwitch = 0

[theBait, theSwitch] = [theSwitch, theBait]



weatherReport = (location) ->
  # Make an Ajax request to fetch the weather...
  [location, 72, "Mostly Sunny"]

[city, temp, forecast] = weatherReport "Berkeley, CA"
Fat arrow – binding this


Account = (customer, cart) ->
  @customer = customer
  @cart = cart

  $('.shopping_cart').bind 'click', (event) =>
    @customer.purchase @cart
String Interpolation


author = "Wittgenstein"
quote = "A picture is a fact. -- #{author}"

sentence = "#{ 22 / 7 } is a decent approximation of π"
Jak to rozchodit?
The CoffeeScript compiler is
itself written in CoffeeScript.
nodejs.org
Node Package Manager
$ curl http://npmjs.org/install.sh | sh

$ npm install -g coffee-script
$ coffee --watch --compile *.coffee


19:45:31 - compiled   myscript.coffee
19:47:22 - compiled   myscript.coffee
In myscript.coffee,   too many ) on line 39
19:47:40 - compiled   myscript.coffee
19:48:10 - compiled   myscript.coffee
19:48:47 - compiled   myscript.coffee
In myscript.coffee,   Parse error on line 3: Unexpected 'INDENT'
19:49:23 - compiled   myscript.coffee
<script src="/path/to/coffee-script.js"></script>
<script type="text/coffeescript">
  $(document).ready -> alert "Your DOM is ready."
</script>
Odkazy
CoffeeScript homepage
http://jashkenas.github.com/coffee-script/


node.js
http://nodejs.org/

npm
http://npmjs.org/

Introduction to CoffeeScript
http://screencasts.org/episodes/introduction-to-coffeescript/

Js2Coffee – The JavaScript to CoffeeScript compiler.
http://ricostacruz.com/js2coffee/

More Related Content

What's hot

Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
adamcookeuk
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
David Furber
 
Why (I think) CoffeeScript Is Awesome
Why (I think) CoffeeScript Is AwesomeWhy (I think) CoffeeScript Is Awesome
Why (I think) CoffeeScript Is Awesome
Jo Cranford
 
(Parameterized) Roles
(Parameterized) Roles(Parameterized) Roles
(Parameterized) Roles
sartak
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
Michael Galpin
 
P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)
lichtkind
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
Dave Cross
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
Todd Anglin
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
Daniel Spector
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
Fwdays
 
Creating native apps with WordPress
Creating native apps with WordPressCreating native apps with WordPress
Creating native apps with WordPress
Marko Heijnen
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
Manoj Kumar
 
Programming Language Swift Overview
Programming Language Swift OverviewProgramming Language Swift Overview
Programming Language Swift Overview
Kaz Yoshikawa
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
Dragos Ionita
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2Dave Cross
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
Vysakh Sreenivasan
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
hesher
 

What's hot (20)

Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
Why (I think) CoffeeScript Is Awesome
Why (I think) CoffeeScript Is AwesomeWhy (I think) CoffeeScript Is Awesome
Why (I think) CoffeeScript Is Awesome
 
(Parameterized) Roles
(Parameterized) Roles(Parameterized) Roles
(Parameterized) Roles
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
 
P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
 
Creating native apps with WordPress
Creating native apps with WordPressCreating native apps with WordPress
Creating native apps with WordPress
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
Programming Language Swift Overview
Programming Language Swift OverviewProgramming Language Swift Overview
Programming Language Swift Overview
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 

Viewers also liked

CoffeeScript in 5mins
CoffeeScript in 5minsCoffeeScript in 5mins
CoffeeScript in 5minsMasakuni Kato
 
Coffee script grunt
Coffee script gruntCoffee script grunt
Coffee script gruntKien Pham
 
Ruby Made Simple: Blocks Plus Iterators
Ruby Made Simple: Blocks Plus IteratorsRuby Made Simple: Blocks Plus Iterators
Ruby Made Simple: Blocks Plus Iterators
John Schmidt
 
Coffeescript: An Opinionated Introduction
Coffeescript: An Opinionated IntroductionCoffeescript: An Opinionated Introduction
Coffeescript: An Opinionated Introduction
Joe Fleming
 
CoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyCoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copy
Patrick Devins
 

Viewers also liked (6)

CoffeeScript in 5mins
CoffeeScript in 5minsCoffeeScript in 5mins
CoffeeScript in 5mins
 
Coffee script grunt
Coffee script gruntCoffee script grunt
Coffee script grunt
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Ruby Made Simple: Blocks Plus Iterators
Ruby Made Simple: Blocks Plus IteratorsRuby Made Simple: Blocks Plus Iterators
Ruby Made Simple: Blocks Plus Iterators
 
Coffeescript: An Opinionated Introduction
Coffeescript: An Opinionated IntroductionCoffeescript: An Opinionated Introduction
Coffeescript: An Opinionated Introduction
 
CoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyCoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copy
 

Similar to CoffeeScript

Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
niklal
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Ryan McGeary
 
Internal Project: Under the Hood
Internal Project: Under the HoodInternal Project: Under the Hood
Internal Project: Under the HoodVladik Khononov
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Scott Leberknight
 
Coffee Scriptでenchant.js
Coffee Scriptでenchant.jsCoffee Scriptでenchant.js
Coffee Scriptでenchant.js
Naoyuki Totani
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayEddie Kao
 
FITC CoffeeScript 101
FITC CoffeeScript 101FITC CoffeeScript 101
FITC CoffeeScript 101
Faisal Abid
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
OO JS for AS3 Devs
OO JS for AS3 DevsOO JS for AS3 Devs
OO JS for AS3 DevsJason Hanson
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
Roy Yu
 
Coffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesCoffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotes
Brandon Satrom
 
CoffeeScript - JavaScript in a simple way
CoffeeScript - JavaScript in a simple wayCoffeeScript - JavaScript in a simple way
CoffeeScript - JavaScript in a simple wayLim Chanmann
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
heumann
 
CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better!
Jack Franklin
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
William Narmontas
 
Quick coffeescript
Quick coffeescriptQuick coffeescript
Quick coffeescript
Thomas Hunter II
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
Demian Holderegger
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
Ben Scheirman
 

Similar to CoffeeScript (20)

Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Internal Project: Under the Hood
Internal Project: Under the HoodInternal Project: Under the Hood
Internal Project: Under the Hood
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Coffee Scriptでenchant.js
Coffee Scriptでenchant.jsCoffee Scriptでenchant.js
Coffee Scriptでenchant.js
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-Tuesday
 
FITC CoffeeScript 101
FITC CoffeeScript 101FITC CoffeeScript 101
FITC CoffeeScript 101
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
OO JS for AS3 Devs
OO JS for AS3 DevsOO JS for AS3 Devs
OO JS for AS3 Devs
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
 
Coffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesCoffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotes
 
CoffeeScript - JavaScript in a simple way
CoffeeScript - JavaScript in a simple wayCoffeeScript - JavaScript in a simple way
CoffeeScript - JavaScript in a simple way
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
JavaScript @ CTK
JavaScript @ CTKJavaScript @ CTK
JavaScript @ CTK
 
CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better!
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
 
Quick coffeescript
Quick coffeescriptQuick coffeescript
Quick coffeescript
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 

Recently uploaded

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 

Recently uploaded (20)

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 

CoffeeScript

  • 1. CoffeeScript Petr Pokorný
  • 2. Obsah Co to je? Proč to používat? Jak to vypadá? Jak to rozchodit?
  • 4. Co to je? CoffeeScript is a little language that compiles into JavaScript.
  • 5. Co to je? CoffeeScript is a little language that compiles into JavaScript. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime.
  • 6. JavaScript je v jádru docela dobrý jazyk, ale…
  • 7. JavaScript je v jádru docela dobrý jazyk, ale… “ JavaScript had to look like Java only less so, be Java’s dumb kid brother or boy-hostage sidekick.
  • 8. JavaScript je v jádru docela dobrý jazyk, ale… “ JavaScript had to look like Java only less so, be Java’s dumb kid brother or boy-hostage sidekick. Plus, I had to be done in ten days or something worse than JavaScript would have happened. ” — Brendan Eich
  • 11. Proč to používat? Rychlejší vývoj Méně bugů
  • 12. Proč to používat? Rychlejší vývoj Méně bugů Lepší čitelnost
  • 14. Functions var cube, square; square = function(x) { return x * x; square = (x) -> x * x }; cube = function(x) { cube = (x) -> square(x) * x return square(x) * x; }; JavaScript CoffeeScript
  • 15. Objects var kids = { kids = brother: { brother: name: "Max", name: "Max" age: 11 age: 11 }, sister: sister: { name: "Ida" name: "Ida", age: 9 age: 9 } }; JavaScript CoffeeScript
  • 16. If, Else, Conditional Assignment var date, mood; if (singing) { mood = greatlyImproved if singing mood = greatlyImproved; } if (happy && knowsIt) { if happy and knowsIt clapsHands(); clapsHands() chaChaCha(); chaChaCha() } else { else showIt(); showIt() } date = friday ? sue : jill; date = if friday then sue else jill JavaScript CoffeeScript
  • 17. OOP var Animal, Horse, Snake, sam, tom; var __hasProp = Object.prototype.hasOwnProperty, __extends = class Animal function(child, parent) { constructor: (@name) -> for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; move: (meters) -> child.prototype = new ctor; child.__super__ = parent.prototype; alert @name +" moved "+ meters +"m." return child;};Animal = (function() { function Animal(name) { this.name = name; } Animal.prototype.move = function(meters) { class Snake extends Animal return alert(this.name + " moved " + meters + "m."); }; move: -> return Animal;})(); Snake = (function() { __extends(Snake, Animal); function alert "Slithering..." Snake() { Snake.__super__.constructor.apply(this, arguments); super 5 } Snake.prototype.move = function() { alert("Slithering..."); return Snake.__super__.move.call(this, 5); }; return Snake;})(); class Horse extends Animal Horse = (function() { __extends(Horse, Animal); function Horse() { move: -> } Horse.__super__.constructor.apply(this, arguments); alert "Galloping..." Horse.prototype.move = function() { super 45 alert("Galloping..."); return Horse.__super__.move.call(this, 45); }; return Horse;})(); sam = new Snake "Sammy the Python" sam = new Snake("Sammy the Python"); tom = new Horse("Tommy the Palomino"); tom = new Horse "Tommy the Palomino" JavaScript CoffeeScript
  • 18. Na co jste zvyklí z Pythonu
  • 19. Loops # Eat lunch. for food in ['toast', 'cheese', 'wine']: eat(food) # Eat lunch. eat food for food in ['toast', 'cheese', 'wine']
  • 20. Loops # Eat lunch. for food in ['toast', 'cheese', 'wine']: eat(food) # Eat lunch. eat food for food in ['toast', 'cheese', 'wine'] var food, _i, _len, _ref; _ref = ['toast', 'cheese', 'wine']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { food = _ref[_i]; eat(food); }
  • 21. Loops for key in {‘foo’: ‘bar’} for key, value in {‘foo’: ‘bar’}.items() for key of {foo: ‘bar’} for key, value of {foo: ‘bar’}
  • 22. Ranges for i in range(1, 10) for i in range(10, 1, -1) for i in range(1, 10, 2) for i in [1..9] # nebo [1...10] for i in [10..2] for i in [1..9] by 2
  • 23. Comprehensions short_names = [name for name in list if len(name) < 5] shortNames = (name for name in list when name.length < 5)
  • 25. Slicing my_list[3:6] = [1, 2, 3] my_list[3:] my_list[:-3] myList[3..5] = [1, 2, 3] myList[3..] myList[...-3]
  • 26. Splats (a.k.a. argument list unpacking) def foo(bar, *args): pass foo = (bar, args...) ->
  • 27. Chained Comparisons cholesterol = 127 healthy = 200 > cholesterol > 60
  • 29. The Existential Operator alert "I knew it!" if elvis? if (typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); }
  • 30. Destructuring Assignment theBait = 1000 theSwitch = 0 [theBait, theSwitch] = [theSwitch, theBait] weatherReport = (location) -> # Make an Ajax request to fetch the weather... [location, 72, "Mostly Sunny"] [city, temp, forecast] = weatherReport "Berkeley, CA"
  • 31. Fat arrow – binding this Account = (customer, cart) -> @customer = customer @cart = cart $('.shopping_cart').bind 'click', (event) => @customer.purchase @cart
  • 32. String Interpolation author = "Wittgenstein" quote = "A picture is a fact. -- #{author}" sentence = "#{ 22 / 7 } is a decent approximation of π"
  • 34. The CoffeeScript compiler is itself written in CoffeeScript.
  • 36. Node Package Manager $ curl http://npmjs.org/install.sh | sh $ npm install -g coffee-script
  • 37. $ coffee --watch --compile *.coffee 19:45:31 - compiled myscript.coffee 19:47:22 - compiled myscript.coffee In myscript.coffee, too many ) on line 39 19:47:40 - compiled myscript.coffee 19:48:10 - compiled myscript.coffee 19:48:47 - compiled myscript.coffee In myscript.coffee, Parse error on line 3: Unexpected 'INDENT' 19:49:23 - compiled myscript.coffee
  • 38. <script src="/path/to/coffee-script.js"></script> <script type="text/coffeescript"> $(document).ready -> alert "Your DOM is ready." </script>
  • 39. Odkazy CoffeeScript homepage http://jashkenas.github.com/coffee-script/ node.js http://nodejs.org/ npm http://npmjs.org/ Introduction to CoffeeScript http://screencasts.org/episodes/introduction-to-coffeescript/ Js2Coffee – The JavaScript to CoffeeScript compiler. http://ricostacruz.com/js2coffee/