• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Ultimate Language Shootout IV: CoffeeScript
 

Ultimate Language Shootout IV: CoffeeScript

on

  • 1,037 views

A presentation on CoffeeScript given at ChiPy's 2013 Ultimate Language Shootout on June 13, 2013.

A presentation on CoffeeScript given at ChiPy's 2013 Ultimate Language Shootout on June 13, 2013.

Video:
http://pyvideo.org/video/1864/ultimate-language-shootout-iv-coffeescript

Statistics

Views

Total Views
1,037
Views on SlideShare
1,037
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Ultimate Language Shootout IV: CoffeeScript Ultimate Language Shootout IV: CoffeeScript Presentation Transcript

    • Ultimate LanguageShootout IV: CoffeeScriptChiPyJune 13, 2013
    • What is CoffeeScript?It’s basically syntax sugar for JavaScript.Perhaps some analogies are in order...
    • If JavaScript is gluten-freehaggis pizza
    • Then CoffeeScript is anenchanted thincrusthandcrafted by Gandalf
    • If JavaScript is a corrupt,lecherous cop
    • Then CoffeeScript isSynchronized SwimmingDetective
    • If JavaScript is Smaug, theevil dragon
    • Then CoffeeScript is anadorable frog-shaped lighter
    • If JavaScript is a terrifyinghell clown
    • Then CoffeeScript is PrincessAmidala
    • If JavaScript is a smellydonkey with bad knees
    • Then CoffeeScript is a robotunicorn
    • If JavaScript is a grumpyblobfish
    • Then CoffeeScript is a muppetfish quartet
    • If JavaScript is a poisonmushroom
    • Then CoffeeScript is thehammer suit
    • If JavaScript is A Night atthe Roxbury
    • Then CoffeeScript isAnchorman
    • If JavaScript is a poo-flavored Tootsie Roll
    • Then CoffeeScript is a baconchocolate bar
    • If JavaScript is a lonecommando with a crappy gun
    • Then CoffeeScript is a giantrobot made of other robots
    • I guess I’m trying to say thatCoffeeScript might not be aterrible idea.
    • CoffeeScript does borrowfrom some of the bestlanguages.The Python and Rubyinfluences are glaringly obvious.
    • Let’s walk through a simpleCoffeeScript application.https://github.com/feihong/coffeescript-talk
    • Multiline comments###Implement a shuffle() function that randomlyrearranges the elements in a given array.Also demo its usage and effect.###
    • Multiline commentnotes• Multiline comments appear as-is in thecompiled .js file, using the /* */ commentsyntax.
    • Main functionmain = ->array = (c.toUpperCase() for c in abcdefg)display array$(document.body).append <hr>for i in [1..6]shuffle arraydisplay array
    • Main function notes• Whitespace delimits blocks• Define function using -> operator• Array expression uses parentheses• Parentheses not required for functioninvocation• Ranges specified using [a..b]• No colon at end of looping statement
    • Shuffle functionshuffle = (array) ->i = array.lengthj = nullif i == 0returnwhile i -= 1j = Math.floor(Math.random() * (i+1))[array[i], array[j]] = [array[j], array[i]]
    • Shuffle function notes• Parentheses somewhat advised whencomplex expressions are passed into afunction• No colon at end of conditional statement• Destructuring assignment requires squarebrackets
    • Display functiondisplay = (array) ->para = $(<p></p>)$(document.body).append parafor char in arrayval = 60 # simplifiedstyle = """background: rgb(#{val}, #{val}, #{val});border: 1px solid black;padding: 5px; margin: 5px;"""h = "<span style="#{style}">#{el}</span>"para.append h
    • Display function notes• Multiline string takes indentation intoaccount (resulting string doesn’t containextra spaces).• String interpolation requires double-quotedstrings
    • CoffeeScript’s bigweaknessDebugging sucks! Errors in the console referto the generated .js file, not theoriginal .coffee file.
    • Chrome to the rescue!• Open Developer Tools• Click gear icon in lower-right corner• Check “Enable source maps”• Compile your .coffee files using the -moption
    • Compiling CoffeeScriptRunning “coffee -c -m main.coffee”produces main.js and main.map.
    • So, in conclusion...
    • CoffeeScript might notbe terrible.
    • The end