SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
Underneath  that  awkward  Java-­‐‑esque  patina,  
JavaScript  has  always  had  a  gorgeous  heart!
h<ps://github.com/jashkenas/coffee-­‐‑script

Spyros Ioakeimidis | TechTalk 21/10/2013
Intro
static  analysis  by  design
CoffeeScript  code  compiles  one-­‐‑to-­‐‑one  to  JavaScript
no  runtime  checking  (interpretation  at  runtime)
literate  mode,  you  can  write  markdown  document,  which  
can  contain  executable  CoffeeScript  code

2
Compile *.coffee
coffee  -­‐‑o  lib/  -­‐‑cw  src/  (and  sub-­‐‑directories)
in  the  alphabetical  order  of  the  files  (as  they  are  found  in  the  file  system)

coffee  -­‐‑j  lib/main.js  -­‐‑cw  src/
merge  *.coffee  files  into  one  merged.js  file,  again  in  the  alphabetical  order  
the  compiler  finds  them  in  the  file  system

it  can  also  be  used  in  strict  mode  (DEBUG  =  True)

3
Serve *.coffee
write
main.coffee

(1)  compile  *.coffee  file  in  runtime  when  it  is  
requested  (and  if  there  is  a  newer  version),  
cache  does  not  work  as  usual  (gets  the  
same  file  again,  though  it  is  not  slower)

use main.coffee
in html

client requests
main.coffee

compile to
main.js

main.js is served

4
Serve *.coffee
write
main.coffee

(2)  compile  during  development,  
generate  *.js  files  and  serve  those,  
include  them  in  templates  (precompile  
phase)

compile
main.coffee

use main.js file
in index.html

client requests
main.js

serve main.js
file

5
Serve *.coffee
django-­‐‑compressor
<script  type="ʺtext/coffeescript"ʺ  src="ʺ{%  static  'ʹrewards.coffee'ʹ  %}"ʺ></script>
when  a  file  is  requested,  it  is  compiled,  a  CACHE  directory  is  created  (if  it  
does  not  exist)  and  the  *.js  files  are  stored  and  served  from  in  there

Stitch,  NodeJS,  or  Rails
automatic  runtime  compile  is  included,  and  it  is  transparent
in  production,  Rails  will  write  the  compiled  output  to  disk,  ensuring  it'ʹs  
cached  and  fast  to  serve

6
CoffeeScript
whitespace  is  significant
no  semicolons
it  removes  global  variables
need  to  be  careful  with  functions  and  parens,  e.g.
alert  inspect  a
alert  inspect            #  gives  error,  is  it  a  function  or  an  argument?
alert  inspect(a)  #  this  is  beKer

7
CoffeeScript
aliases  for  this  is  @  and  for  accessing  the  prototype  is  ::
solves  the  issues  with  “with”  statements,  reserved  
keywords,  Number  property  lookups
fixes  the  equality  comparisons  ambiguity,  by  using  the  (===)  
strict  equality  operator,  e.g.
      "ʺ"ʺ                ==      "ʺ0"ʺ                      //  false
        0                  ==      "ʺ"ʺ                          //  true
        0                  ==      "ʺ0"ʺ                      //  true

        false      ==      "ʺfalse"ʺ          //  false

      ...

*example  taken  from  [1]
8
CoffeeScript
function  definitions,  CoffeeScript  uses  only  function  
expressions  and  discards  completely  declarative  functions
        e.g.  expression  =  function()  {  }  instead  of  function  declaration()  {  }
offers  cross-­‐‑browser  compatibility
but  there  are  other  things  that  CoffeeScript  can'ʹt  fix
eval
typeof
same  for  instanceof
delete,  parseInt()
9
CoffeeScript
{ functions, use of parens }

Console:
27

10
CoffeeScript
{ objects, arrays, splash..., string interpolation }

Console:
Gold: Michael Phelps in 9.68
Silver: Liu Xiang in 10.56
Rest: Yao Ming,Allyson Felix,...

11
CoffeeScript
{ loops, comprehensions, slicing, when, isnt, unless }

Console:
PY

12

:)
CoffeeScript
{ iterate over object properties }

Console:
max is 10,ida is 9,tim is 11

13
CoffeeScript
{ while, conditional assignment }

Console:
5 little
4 little
3 little
2 little
1 little

monkeys, jumping on the bed. One fell out and bumped his head.
monkeys, jumping on the bed. One fell out and bumped his head.
monkeys, jumping on the bed. One fell out and bumped his head.
monkeys, jumping on the bed. One fell out and bumped his head.
monkey, jumping on the bed. One fell out and bumped his head.

14
CoffeeScript
{ do, loop to generate functions }

Console:
Reading file: file-1 compiled as <file-1, ...file contents...>
Reading file: file-2 compiled as <file-2, ...file contents...>

15
CoffeeScript
{ existential operator }

Console:
9715 ZM
16
CoffeeScript
{ classes, inheritance, destructuring assignment }

Console:
char0: firstName -> Tom
char0: lastName -> and Jerry
Cartoon Report:
Tom and Jerry received 10!
char1: firstName -> Amazing
char1: lastName -> Spiderman
Superhero Report:
Amazing Spiderman received 1000!

17
CoffeeScript
{ instead of typeof, we can use a trick }

18
CoffeeScript
{ another example of destructuring assignment }

Console:
City: Groningen, NL

Temp: -10 Forecast: Mostly Snow

19
CoffeeScript
{ using the window to create top level variables }

20
CoffeeScript
{ function binding with the fat arrow => }

Console:
Purchase for customer 345 and cart cart_45654
21
CoffeeScript
{ switch statements, chained comparisons }

Console:
Grade: D+
22
CoffeeScript
{ exceptions }

Console:
Ops exception ReferenceError: Undefined is not defined
finally...

23
CoffeeScript
{ use of mixins when inheritance is not suited }

24
CoffeeScript
{ use of mixins when inheritance is not suited }

Console:
Finding id 1
Creating...
Saving...
(when the button with class ‘.show’
is pressed)
Showing user with id 1

25
CoffeeScript
{ or= }

Console:
empty something

26
Share Objects
exports  =  this
exports.variable  =  "ʺtest"ʺ
or  if  Node.js,  or  Stitch  is  used  with  CommonJS  which  
provides  modules,  e.g.
#  app/models/user.coffee
module.exports  =  class  User
        constructor:  (@name)  -­‐‑>
#  app/app.coffee
User  =  require("ʺmodels/user"ʺ)

27
JS vs CS
less  code  to  write!  the  example  with  the  fictional  character  
class  was:
100  loc  in  JS,  50  loc  in  CS

far  more  readable,  less  complex,  and  more  maintainable
CoffeeScript  tends  to  run  as  fast,  or  faster  than  hand-­‐‑wri<en  
JavaScript
however,  CoffeeScript  introduces  another  layer..
no  big  community  yet..  but  it  is  ge<ing  bigger  :)
28
CoffeeScript
&

AngularJS

29
Testing
unit  testing  and  Behaviour-­‐‑driven  Development  (BDD)  with  
the  popular  framework  Jasmine
assaf'ʹs  Zombie.js,  a  headless,  full-­‐‑stack,  faux-­‐‑browser  
testing  library  for  Node.js
Testing  with  CoffeeScript:  h<p://goo.gl/U67oKU

30
Performance
test  of  operations  on  a  million  floating  point  numbers
CoffeeScript  -­‐‑>  0.164s
CPython  -­‐‑>  0.603s
more  than  3.5x  faster
of  course  C++  is  10x  to  30x  faster  :)

*algorithms  taken  from  [3]
31
Performance
test  on  the  8  queens  problem,  more  info  can  be  found  in  [4]
CoffeeScript  -­‐‑>  0.034s
CPython  -­‐‑>  0.455s
more  than  13x  faster

*algorithms  taken  from  [3]
32
Used on...
several  open-­‐‑source  projects
brunch:  HTML5  applications  made  easy
h<ps://github.com/brunch/brunch

zombie:  a  headless,  full-­‐‑stack,  faux-­‐‑browser  testing  library  
for  Node.js
h<ps://github.com/assaf/zombie

underscore.coffee:  a  port  of  the  Underscore.js  library  of  
helper  functions
h<p://coffeescript.org/documentation/docs/underscore.html

33
What does the
future hold?
new  features  are  coming  with  the  new  EcmaScript6  [5]
(define  block-­‐‑local  vars),  destructuring,  parameter  default  values,  rest  
(splash...),  spread,  proxies,  weak  map,  generators,  iterators,  array  and  
generator  comprehension,  binary  data,  class  syntax,  with  extends,  
prototype,  and  super,  modules,  quasis:  multiline,  substitution-­‐‑ready  
strings  with  extensibility

experimental  javascript  can  be  tried  in  Chrome  by  enabling  
the  Experimental  JavaScript  flag  on
chrome://flags/#enable-­‐‑javascript-­‐‑harmony
*you  can  read  more  in  [6]
34
Little Book on
CoffeeScript
“ CoffeeScript  is  ge<ing  much  wider  use  and  integration,  such  
as  being  a  default  in  Rails  3.1.  Now  is  definitely  the  time  to  
jump  on  the  CoffeeScript  train.  The  time  you  invest  in  
learning  about  the  language  now  will  be  repaid  by  major  
time  savings  later.

35
Let’s write some
CoffeeScript
References
[1]  h<p://bonsaiden.github.io/JavaScript-­‐‑Garden/#types.equality
[2]  CoffeeScript  recipes  for  the  community  by  the  community,  
h<p://coffeescriptcookbook.com/
[3]  Smooth  CoffeeScript,  h<p://goo.gl/RjT74k
[4]  Eight  Queens  Puzzle,  h<p://en.wikipedia.org/wiki/Eight_queens_puzzle
[5]  h<p://espadrine.github.io/New-­‐‑In-­‐‑A-­‐‑Spec/es6/
[6]  h<p://gaslight.co/blog/does-­‐‑coffeescript-­‐‑have-­‐‑a-­‐‑future
[7]  Li<le  Book  on  CoffeeScript,  h<p://arcturo.github.io/library/coffeescript/

Contenu connexe

Tendances

Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 
React Native in Production
React Native in ProductionReact Native in Production
React Native in ProductionSeokjun Kim
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot CampTroy Miles
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module PatternsNicholas Jansma
 
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014Matthias Noback
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IVisual Engineering
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJSRan Mizrahi
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play appsYevgeniy Brikman
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Ran Mizrahi
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaExoLeaders.com
 
Improving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesImproving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesHassan Abid
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricksJavier Eguiluz
 
Fast C++ Web Servers
Fast C++ Web ServersFast C++ Web Servers
Fast C++ Web ServersTroy Miles
 
Symfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendSymfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendKirill Chebunin
 
Workshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSWorkshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSVisual Engineering
 

Tendances (20)

Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
React Native in Production
React Native in ProductionReact Native in Production
React Native in Production
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
Zenly - Reverse geocoding
Zenly - Reverse geocodingZenly - Reverse geocoding
Zenly - Reverse geocoding
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module Patterns
 
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
Présentation de HomeKit
Présentation de HomeKitPrésentation de HomeKit
Présentation de HomeKit
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJS
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with Karma
 
Improving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesImproving app performance with Kotlin Coroutines
Improving app performance with Kotlin Coroutines
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
 
Fast C++ Web Servers
Fast C++ Web ServersFast C++ Web Servers
Fast C++ Web Servers
 
Symfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendSymfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friend
 
Workshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSWorkshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJS
 

Similaire à CoffeeScript - TechTalk 21/10/2013

Writing Rust Command Line Applications
Writing Rust Command Line ApplicationsWriting Rust Command Line Applications
Writing Rust Command Line ApplicationsAll Things Open
 
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ BuilderA Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ BuilderAndrey Karpov
 
Boxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsBoxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsPuppet
 
TestUpload
TestUploadTestUpload
TestUploadZarksaDS
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleAnton Arhipov
 
Embulk - 進化するバルクデータローダ
Embulk - 進化するバルクデータローダEmbulk - 進化するバルクデータローダ
Embulk - 進化するバルクデータローダSadayuki Furuhashi
 
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioArcheology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioAndrey Karpov
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteDr Nic Williams
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...Jérôme Petazzoni
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design PatternsTrevorBurnham
 
Reuse, Reduce, Recycle in Serverless World
Reuse, Reduce, Recycle in Serverless WorldReuse, Reduce, Recycle in Serverless World
Reuse, Reduce, Recycle in Serverless WorldDmitri Zimine
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvarsSam Marley-Jarrett
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckAndrey Karpov
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)Soshi Nemoto
 
Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016PVS-Studio
 
Amazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionAmazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionPaolo latella
 
Microarmy - by J2 Labs
Microarmy - by J2 LabsMicroarmy - by J2 Labs
Microarmy - by J2 LabsJames Dennis
 

Similaire à CoffeeScript - TechTalk 21/10/2013 (20)

Writing Rust Command Line Applications
Writing Rust Command Line ApplicationsWriting Rust Command Line Applications
Writing Rust Command Line Applications
 
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ BuilderA Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
 
Boxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsBoxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of Laptops
 
TestUpload
TestUploadTestUpload
TestUpload
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
 
Embulk - 進化するバルクデータローダ
Embulk - 進化するバルクデータローダEmbulk - 進化するバルクデータローダ
Embulk - 進化するバルクデータローダ
 
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioArcheology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design Patterns
 
Reuse, Reduce, Recycle in Serverless World
Reuse, Reduce, Recycle in Serverless WorldReuse, Reduce, Recycle in Serverless World
Reuse, Reduce, Recycle in Serverless World
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvars
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd Check
 
Js tacktalk team dev js testing performance
Js tacktalk team dev js testing performanceJs tacktalk team dev js testing performance
Js tacktalk team dev js testing performance
 
Being agile with modern Java
Being agile with modern JavaBeing agile with modern Java
Being agile with modern Java
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016
 
Amazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionAmazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to production
 
Introducing Ansible
Introducing AnsibleIntroducing Ansible
Introducing Ansible
 
Microarmy - by J2 Labs
Microarmy - by J2 LabsMicroarmy - by J2 Labs
Microarmy - by J2 Labs
 

Dernier

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Dernier (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

CoffeeScript - TechTalk 21/10/2013

  • 1. Underneath  that  awkward  Java-­‐‑esque  patina,   JavaScript  has  always  had  a  gorgeous  heart! h<ps://github.com/jashkenas/coffee-­‐‑script Spyros Ioakeimidis | TechTalk 21/10/2013
  • 2. Intro static  analysis  by  design CoffeeScript  code  compiles  one-­‐‑to-­‐‑one  to  JavaScript no  runtime  checking  (interpretation  at  runtime) literate  mode,  you  can  write  markdown  document,  which   can  contain  executable  CoffeeScript  code 2
  • 3. Compile *.coffee coffee  -­‐‑o  lib/  -­‐‑cw  src/  (and  sub-­‐‑directories) in  the  alphabetical  order  of  the  files  (as  they  are  found  in  the  file  system) coffee  -­‐‑j  lib/main.js  -­‐‑cw  src/ merge  *.coffee  files  into  one  merged.js  file,  again  in  the  alphabetical  order   the  compiler  finds  them  in  the  file  system it  can  also  be  used  in  strict  mode  (DEBUG  =  True) 3
  • 4. Serve *.coffee write main.coffee (1)  compile  *.coffee  file  in  runtime  when  it  is   requested  (and  if  there  is  a  newer  version),   cache  does  not  work  as  usual  (gets  the   same  file  again,  though  it  is  not  slower) use main.coffee in html client requests main.coffee compile to main.js main.js is served 4
  • 5. Serve *.coffee write main.coffee (2)  compile  during  development,   generate  *.js  files  and  serve  those,   include  them  in  templates  (precompile   phase) compile main.coffee use main.js file in index.html client requests main.js serve main.js file 5
  • 6. Serve *.coffee django-­‐‑compressor <script  type="ʺtext/coffeescript"ʺ  src="ʺ{%  static  'ʹrewards.coffee'ʹ  %}"ʺ></script> when  a  file  is  requested,  it  is  compiled,  a  CACHE  directory  is  created  (if  it   does  not  exist)  and  the  *.js  files  are  stored  and  served  from  in  there Stitch,  NodeJS,  or  Rails automatic  runtime  compile  is  included,  and  it  is  transparent in  production,  Rails  will  write  the  compiled  output  to  disk,  ensuring  it'ʹs   cached  and  fast  to  serve 6
  • 7. CoffeeScript whitespace  is  significant no  semicolons it  removes  global  variables need  to  be  careful  with  functions  and  parens,  e.g. alert  inspect  a alert  inspect            #  gives  error,  is  it  a  function  or  an  argument? alert  inspect(a)  #  this  is  beKer 7
  • 8. CoffeeScript aliases  for  this  is  @  and  for  accessing  the  prototype  is  :: solves  the  issues  with  “with”  statements,  reserved   keywords,  Number  property  lookups fixes  the  equality  comparisons  ambiguity,  by  using  the  (===)   strict  equality  operator,  e.g.      "ʺ"ʺ                ==      "ʺ0"ʺ                      //  false        0                  ==      "ʺ"ʺ                          //  true        0                  ==      "ʺ0"ʺ                      //  true        false      ==      "ʺfalse"ʺ          //  false      ... *example  taken  from  [1] 8
  • 9. CoffeeScript function  definitions,  CoffeeScript  uses  only  function   expressions  and  discards  completely  declarative  functions        e.g.  expression  =  function()  {  }  instead  of  function  declaration()  {  } offers  cross-­‐‑browser  compatibility but  there  are  other  things  that  CoffeeScript  can'ʹt  fix eval typeof same  for  instanceof delete,  parseInt() 9
  • 10. CoffeeScript { functions, use of parens } Console: 27 10
  • 11. CoffeeScript { objects, arrays, splash..., string interpolation } Console: Gold: Michael Phelps in 9.68 Silver: Liu Xiang in 10.56 Rest: Yao Ming,Allyson Felix,... 11
  • 12. CoffeeScript { loops, comprehensions, slicing, when, isnt, unless } Console: PY 12 :)
  • 13. CoffeeScript { iterate over object properties } Console: max is 10,ida is 9,tim is 11 13
  • 14. CoffeeScript { while, conditional assignment } Console: 5 little 4 little 3 little 2 little 1 little monkeys, jumping on the bed. One fell out and bumped his head. monkeys, jumping on the bed. One fell out and bumped his head. monkeys, jumping on the bed. One fell out and bumped his head. monkeys, jumping on the bed. One fell out and bumped his head. monkey, jumping on the bed. One fell out and bumped his head. 14
  • 15. CoffeeScript { do, loop to generate functions } Console: Reading file: file-1 compiled as <file-1, ...file contents...> Reading file: file-2 compiled as <file-2, ...file contents...> 15
  • 16. CoffeeScript { existential operator } Console: 9715 ZM 16
  • 17. CoffeeScript { classes, inheritance, destructuring assignment } Console: char0: firstName -> Tom char0: lastName -> and Jerry Cartoon Report: Tom and Jerry received 10! char1: firstName -> Amazing char1: lastName -> Spiderman Superhero Report: Amazing Spiderman received 1000! 17
  • 18. CoffeeScript { instead of typeof, we can use a trick } 18
  • 19. CoffeeScript { another example of destructuring assignment } Console: City: Groningen, NL Temp: -10 Forecast: Mostly Snow 19
  • 20. CoffeeScript { using the window to create top level variables } 20
  • 21. CoffeeScript { function binding with the fat arrow => } Console: Purchase for customer 345 and cart cart_45654 21
  • 22. CoffeeScript { switch statements, chained comparisons } Console: Grade: D+ 22
  • 23. CoffeeScript { exceptions } Console: Ops exception ReferenceError: Undefined is not defined finally... 23
  • 24. CoffeeScript { use of mixins when inheritance is not suited } 24
  • 25. CoffeeScript { use of mixins when inheritance is not suited } Console: Finding id 1 Creating... Saving... (when the button with class ‘.show’ is pressed) Showing user with id 1 25
  • 27. Share Objects exports  =  this exports.variable  =  "ʺtest"ʺ or  if  Node.js,  or  Stitch  is  used  with  CommonJS  which   provides  modules,  e.g. #  app/models/user.coffee module.exports  =  class  User        constructor:  (@name)  -­‐‑> #  app/app.coffee User  =  require("ʺmodels/user"ʺ) 27
  • 28. JS vs CS less  code  to  write!  the  example  with  the  fictional  character   class  was: 100  loc  in  JS,  50  loc  in  CS far  more  readable,  less  complex,  and  more  maintainable CoffeeScript  tends  to  run  as  fast,  or  faster  than  hand-­‐‑wri<en   JavaScript however,  CoffeeScript  introduces  another  layer.. no  big  community  yet..  but  it  is  ge<ing  bigger  :) 28
  • 30. Testing unit  testing  and  Behaviour-­‐‑driven  Development  (BDD)  with   the  popular  framework  Jasmine assaf'ʹs  Zombie.js,  a  headless,  full-­‐‑stack,  faux-­‐‑browser   testing  library  for  Node.js Testing  with  CoffeeScript:  h<p://goo.gl/U67oKU 30
  • 31. Performance test  of  operations  on  a  million  floating  point  numbers CoffeeScript  -­‐‑>  0.164s CPython  -­‐‑>  0.603s more  than  3.5x  faster of  course  C++  is  10x  to  30x  faster  :) *algorithms  taken  from  [3] 31
  • 32. Performance test  on  the  8  queens  problem,  more  info  can  be  found  in  [4] CoffeeScript  -­‐‑>  0.034s CPython  -­‐‑>  0.455s more  than  13x  faster *algorithms  taken  from  [3] 32
  • 33. Used on... several  open-­‐‑source  projects brunch:  HTML5  applications  made  easy h<ps://github.com/brunch/brunch zombie:  a  headless,  full-­‐‑stack,  faux-­‐‑browser  testing  library   for  Node.js h<ps://github.com/assaf/zombie underscore.coffee:  a  port  of  the  Underscore.js  library  of   helper  functions h<p://coffeescript.org/documentation/docs/underscore.html 33
  • 34. What does the future hold? new  features  are  coming  with  the  new  EcmaScript6  [5] (define  block-­‐‑local  vars),  destructuring,  parameter  default  values,  rest   (splash...),  spread,  proxies,  weak  map,  generators,  iterators,  array  and   generator  comprehension,  binary  data,  class  syntax,  with  extends,   prototype,  and  super,  modules,  quasis:  multiline,  substitution-­‐‑ready   strings  with  extensibility experimental  javascript  can  be  tried  in  Chrome  by  enabling   the  Experimental  JavaScript  flag  on chrome://flags/#enable-­‐‑javascript-­‐‑harmony *you  can  read  more  in  [6] 34
  • 35. Little Book on CoffeeScript “ CoffeeScript  is  ge<ing  much  wider  use  and  integration,  such   as  being  a  default  in  Rails  3.1.  Now  is  definitely  the  time  to   jump  on  the  CoffeeScript  train.  The  time  you  invest  in   learning  about  the  language  now  will  be  repaid  by  major   time  savings  later. 35
  • 37. References [1]  h<p://bonsaiden.github.io/JavaScript-­‐‑Garden/#types.equality [2]  CoffeeScript  recipes  for  the  community  by  the  community,   h<p://coffeescriptcookbook.com/ [3]  Smooth  CoffeeScript,  h<p://goo.gl/RjT74k [4]  Eight  Queens  Puzzle,  h<p://en.wikipedia.org/wiki/Eight_queens_puzzle [5]  h<p://espadrine.github.io/New-­‐‑In-­‐‑A-­‐‑Spec/es6/ [6]  h<p://gaslight.co/blog/does-­‐‑coffeescript-­‐‑have-­‐‑a-­‐‑future [7]  Li<le  Book  on  CoffeeScript,  h<p://arcturo.github.io/library/coffeescript/