SlideShare a Scribd company logo
1 of 34
Download to read offline
5 things I learned
about coffeescript
(in my year with it)
Wednesday, June 5, 13
Dean Hudson, @deanero
Senior Engineer, Super Secret Music Start Up
(and hiring!)
Who Am I?
Wednesday, June 5, 13
1. coffee -cp
Wednesday, June 5, 13
dean@hdh:~/Devel/coffee$ coffee --help
Usage: coffee [options] path/to/script.coffee -- [args]
[...]
-c, --compile compile to JavaScript and save as .js files
-p, --print print out the compiled JavaScript
[...]
Wednesday, June 5, 13
to see that this...
Wednesday, June 5, 13
qsort = (ar) ->
return ar unless ar.length > 1
pivot = ar.pop()
less = []
more = []
for val in ar
if val < pivot
less.push(val)
else
more.push(val)
qsort(less).concat([pivot], qsort(more))
module.exports = qsort
Wednesday, June 5, 13
...compiles to this:
Wednesday, June 5, 13
dean@hdh:~/Devel/coffee$ coffee -cp qsort.coffee
// Generated by CoffeeScript 1.4.0
(function() {
var qsort;
qsort = function(ar) {
var less, more, pivot, val, _i, _len;
if (!(ar.length > 1)) {
return ar;
}
pivot = ar.pop();
less = [];
more = [];
for (_i = 0, _len = ar.length; _i < _len; _i++) {
val = ar[_i];
if (val < pivot) {
less.push(val);
} else {
more.push(val);
}
}
return qsort(less).concat([pivot], qsort(more));
};
module.exports = qsort;
}).call(this);
dean@hdh:~/Devel/coffee$
Wednesday, June 5, 13
2. Program with
class
Wednesday, June 5, 13
Wednesday, June 5, 13
(me, 16 months ago)
Wednesday, June 5, 13
There’s only one way to do it.
It reduces mental overhead for devs.
It just works.
Because! With
class...
Wednesday, June 5, 13
__extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key))
child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.__super__ = parent.prototype;
return child;
};
Wednesday, June 5, 13
__extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key))
child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.__super__ = parent.prototype;
return child;
};
Tricksy! And...
Wednesday, June 5, 13
// Generated by CoffeeScript 1.4.0
(function() {
var Greet, Hello,
__hasProp = {}.hasOwnProperty;
Greet = (function() {
function Greet() {}
Greet.prototype.greet = function() {
return 'hi';
};
return Greet;
})();
Hello = (function(_super) {
__extends(Hello, _super);
function Hello() {
return Hello.__super__.constructor.apply(this, arguments);
}
Hello.prototype.hello = function() {
return 'hello';
};
return Hello;
})(Greet);
}).call(this);
Wednesday, June 5, 13
// Generated by CoffeeScript 1.4.0
(function() {
var Greet, Hello,
__hasProp = {}.hasOwnProperty;
Greet = (function() {
function Greet() {}
Greet.prototype.greet = function() {
return 'hi';
};
return Greet;
})();
Hello = (function(_super) {
__extends(Hello, _super);
function Hello() {
return Hello.__super__.constructor.apply(this, arguments);
}
Hello.prototype.hello = function() {
return 'hello';
};
return Hello;
})(Greet);
}).call(this);
...verbose
Wednesday, June 5, 13
vs.
Wednesday, June 5, 13
class Greet
greet: -> 'hi'
class Hello extends Greet
hello: -> 'hello'
Wednesday, June 5, 13
3. Use
comprehension
idioms!!!!!
Wednesday, June 5, 13
# what's wrong with this code?
_ = require 'underscore'
ar = [1,2,3,4,5,6,7,8,9]
doubled = _.map(ar, (x) -> x * 2)
Wednesday, June 5, 13
doubled = i * 2 for i in ar
YOU DON’T NEED
A LIBRARY!!!
Wednesday, June 5, 13
// Generated by CoffeeScript 1.4.0
(function() {
var ar, i, map, _i, _len;
ar = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (_i = 0, _len = ar.length; _i < _len; _i++) {
i = ar[_i];
map = i * 2;
}
}).call(this);
Wednesday, June 5, 13
// Generated by CoffeeScript 1.4.0
(function() {
var ar, i, map, _i, _len;
ar = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (_i = 0, _len = ar.length; _i < _len; _i++) {
i = ar[_i];
map = i * 2;
}
}).call(this);
This is also faster.
Wednesday, June 5, 13
ar = [1,2,3,4,5,6,7,8,9,10]
aSelect = i for i in ar when (i % 2) == 0
aMap = i * 2 for i in ar
aFind = (i for i in ar when i == 0)[0]
Similarly...
Wednesday, June 5, 13
4. One class per file
Wednesday, June 5, 13
Node.js provides a synchronous require
Stitch and browserify use node semantics
Require.js does AMD
How? A library.
Wednesday, June 5, 13
5. Watch your
return values.
Wednesday, June 5, 13
dontRunInATightLoop = (object) ->
# I meant to mutate this object and return void...
object[k] = "#{v}-derp" for k, v of object
This...
Wednesday, June 5, 13
dontRunInATightLoop = function(object) {
var k, v, _results;
_results = [];
for (k in object) {
v = object[k];
_results.push(object[k] = "" + v + "-derp");
}
return _results;
};
...compiles to this.
Wednesday, June 5, 13
Comprehensions
+
Implicit returns
Wednesday, June 5, 13
=
many allocations
Wednesday, June 5, 13
okayToRunInATightLoop = (object) ->
object[k] = "#{v}-derp" for k, v of object
# I need to do it explicitly
return
Wednesday, June 5, 13
Questions?
Wednesday, June 5, 13
Thanks!
@deanero
http://ranch.ero.com
(I’m hiring Rubyists!)
Wednesday, June 5, 13

More Related Content

What's hot

Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoopQuỳnh Phan
 
Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理niratama
 
Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDBGavin Cooper
 
JIP Pipeline System Introduction
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introductionthasso23
 
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Peter Higgins
 
Paver: the build tool you missed
Paver: the build tool you missedPaver: the build tool you missed
Paver: the build tool you missedalmadcz
 

What's hot (9)

Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
 
Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理
 
Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDB
 
JIP Pipeline System Introduction
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introduction
 
181220_slideshare_git
181220_slideshare_git181220_slideshare_git
181220_slideshare_git
 
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.
 
Jsconf.us.2013
Jsconf.us.2013Jsconf.us.2013
Jsconf.us.2013
 
dplyr use case
dplyr use casedplyr use case
dplyr use case
 
Paver: the build tool you missed
Paver: the build tool you missedPaver: the build tool you missed
Paver: the build tool you missed
 

Viewers also liked

Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricksdeanhudson
 
MCDM Digital Toolkit
MCDM Digital ToolkitMCDM Digital Toolkit
MCDM Digital ToolkitKathy Gill
 
MCDM Info Meeting
MCDM Info MeetingMCDM Info Meeting
MCDM Info MeetingKathy Gill
 
Mcdm presentations
Mcdm presentationsMcdm presentations
Mcdm presentationsdeanhudson
 
Network selection techniques:SAW and TOPSIS
Network selection techniques:SAW and TOPSISNetwork selection techniques:SAW and TOPSIS
Network selection techniques:SAW and TOPSISYashwant Dagar
 
MCDM Introduction 08-01
MCDM Introduction 08-01MCDM Introduction 08-01
MCDM Introduction 08-01rmcnab67
 
Multi criteria decision making
Multi criteria decision makingMulti criteria decision making
Multi criteria decision makingKhalid Mdnoh
 

Viewers also liked (7)

Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
 
MCDM Digital Toolkit
MCDM Digital ToolkitMCDM Digital Toolkit
MCDM Digital Toolkit
 
MCDM Info Meeting
MCDM Info MeetingMCDM Info Meeting
MCDM Info Meeting
 
Mcdm presentations
Mcdm presentationsMcdm presentations
Mcdm presentations
 
Network selection techniques:SAW and TOPSIS
Network selection techniques:SAW and TOPSISNetwork selection techniques:SAW and TOPSIS
Network selection techniques:SAW and TOPSIS
 
MCDM Introduction 08-01
MCDM Introduction 08-01MCDM Introduction 08-01
MCDM Introduction 08-01
 
Multi criteria decision making
Multi criteria decision makingMulti criteria decision making
Multi criteria decision making
 

Similar to 5 things I learned about coffeescript in my year with it

Real Time Web with Node
Real Time Web with NodeReal Time Web with Node
Real Time Web with NodeTim Caswell
 
Node Powered Mobile
Node Powered MobileNode Powered Mobile
Node Powered MobileTim Caswell
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Lukas Ruebbelke
 
Automating WordPress Theme Development
Automating WordPress Theme DevelopmentAutomating WordPress Theme Development
Automating WordPress Theme DevelopmentHardeep Asrani
 
Automated release management with team city & octopusdeploy - NDC 2013
Automated release management with team city & octopusdeploy - NDC 2013Automated release management with team city & octopusdeploy - NDC 2013
Automated release management with team city & octopusdeploy - NDC 2013Kristoffer Deinoff
 
Architecture patterns and practices
Architecture patterns and practicesArchitecture patterns and practices
Architecture patterns and practicesFuqiang Wang
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes
 
Recommender Systems with Ruby (adding machine learning, statistics, etc)
Recommender Systems with Ruby (adding machine learning, statistics, etc)Recommender Systems with Ruby (adding machine learning, statistics, etc)
Recommender Systems with Ruby (adding machine learning, statistics, etc)Marcel Caraciolo
 
Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.Eugene Lazutkin
 
Perl from the ground up: objects and testing
Perl from the ground up: objects and testingPerl from the ground up: objects and testing
Perl from the ground up: objects and testingShmuel Fomberg
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leetjohndaviddalton
 
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesJavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesRobert Nyman
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 

Similar to 5 things I learned about coffeescript in my year with it (20)

Txjs
TxjsTxjs
Txjs
 
Real Time Web with Node
Real Time Web with NodeReal Time Web with Node
Real Time Web with Node
 
Node Powered Mobile
Node Powered MobileNode Powered Mobile
Node Powered Mobile
 
asyncio internals
asyncio internalsasyncio internals
asyncio internals
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015
 
Automating WordPress Theme Development
Automating WordPress Theme DevelopmentAutomating WordPress Theme Development
Automating WordPress Theme Development
 
RequireJS
RequireJSRequireJS
RequireJS
 
Automated release management with team city & octopusdeploy - NDC 2013
Automated release management with team city & octopusdeploy - NDC 2013Automated release management with team city & octopusdeploy - NDC 2013
Automated release management with team city & octopusdeploy - NDC 2013
 
Architecture patterns and practices
Architecture patterns and practicesArchitecture patterns and practices
Architecture patterns and practices
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
 
Recommender Systems with Ruby (adding machine learning, statistics, etc)
Recommender Systems with Ruby (adding machine learning, statistics, etc)Recommender Systems with Ruby (adding machine learning, statistics, etc)
Recommender Systems with Ruby (adding machine learning, statistics, etc)
 
Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.
 
I motion
I motionI motion
I motion
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
Perl from the ground up: objects and testing
Perl from the ground up: objects and testingPerl from the ground up: objects and testing
Perl from the ground up: objects and testing
 
Programação Funcional
Programação FuncionalProgramação Funcional
Programação Funcional
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesJavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

5 things I learned about coffeescript in my year with it

  • 1. 5 things I learned about coffeescript (in my year with it) Wednesday, June 5, 13
  • 2. Dean Hudson, @deanero Senior Engineer, Super Secret Music Start Up (and hiring!) Who Am I? Wednesday, June 5, 13
  • 4. dean@hdh:~/Devel/coffee$ coffee --help Usage: coffee [options] path/to/script.coffee -- [args] [...] -c, --compile compile to JavaScript and save as .js files -p, --print print out the compiled JavaScript [...] Wednesday, June 5, 13
  • 5. to see that this... Wednesday, June 5, 13
  • 6. qsort = (ar) -> return ar unless ar.length > 1 pivot = ar.pop() less = [] more = [] for val in ar if val < pivot less.push(val) else more.push(val) qsort(less).concat([pivot], qsort(more)) module.exports = qsort Wednesday, June 5, 13
  • 8. dean@hdh:~/Devel/coffee$ coffee -cp qsort.coffee // Generated by CoffeeScript 1.4.0 (function() { var qsort; qsort = function(ar) { var less, more, pivot, val, _i, _len; if (!(ar.length > 1)) { return ar; } pivot = ar.pop(); less = []; more = []; for (_i = 0, _len = ar.length; _i < _len; _i++) { val = ar[_i]; if (val < pivot) { less.push(val); } else { more.push(val); } } return qsort(less).concat([pivot], qsort(more)); }; module.exports = qsort; }).call(this); dean@hdh:~/Devel/coffee$ Wednesday, June 5, 13
  • 11. (me, 16 months ago) Wednesday, June 5, 13
  • 12. There’s only one way to do it. It reduces mental overhead for devs. It just works. Because! With class... Wednesday, June 5, 13
  • 13. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; Wednesday, June 5, 13
  • 14. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; Tricksy! And... Wednesday, June 5, 13
  • 15. // Generated by CoffeeScript 1.4.0 (function() { var Greet, Hello, __hasProp = {}.hasOwnProperty; Greet = (function() { function Greet() {} Greet.prototype.greet = function() { return 'hi'; }; return Greet; })(); Hello = (function(_super) { __extends(Hello, _super); function Hello() { return Hello.__super__.constructor.apply(this, arguments); } Hello.prototype.hello = function() { return 'hello'; }; return Hello; })(Greet); }).call(this); Wednesday, June 5, 13
  • 16. // Generated by CoffeeScript 1.4.0 (function() { var Greet, Hello, __hasProp = {}.hasOwnProperty; Greet = (function() { function Greet() {} Greet.prototype.greet = function() { return 'hi'; }; return Greet; })(); Hello = (function(_super) { __extends(Hello, _super); function Hello() { return Hello.__super__.constructor.apply(this, arguments); } Hello.prototype.hello = function() { return 'hello'; }; return Hello; })(Greet); }).call(this); ...verbose Wednesday, June 5, 13
  • 18. class Greet greet: -> 'hi' class Hello extends Greet hello: -> 'hello' Wednesday, June 5, 13
  • 20. # what's wrong with this code? _ = require 'underscore' ar = [1,2,3,4,5,6,7,8,9] doubled = _.map(ar, (x) -> x * 2) Wednesday, June 5, 13
  • 21. doubled = i * 2 for i in ar YOU DON’T NEED A LIBRARY!!! Wednesday, June 5, 13
  • 22. // Generated by CoffeeScript 1.4.0 (function() { var ar, i, map, _i, _len; ar = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; for (_i = 0, _len = ar.length; _i < _len; _i++) { i = ar[_i]; map = i * 2; } }).call(this); Wednesday, June 5, 13
  • 23. // Generated by CoffeeScript 1.4.0 (function() { var ar, i, map, _i, _len; ar = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; for (_i = 0, _len = ar.length; _i < _len; _i++) { i = ar[_i]; map = i * 2; } }).call(this); This is also faster. Wednesday, June 5, 13
  • 24. ar = [1,2,3,4,5,6,7,8,9,10] aSelect = i for i in ar when (i % 2) == 0 aMap = i * 2 for i in ar aFind = (i for i in ar when i == 0)[0] Similarly... Wednesday, June 5, 13
  • 25. 4. One class per file Wednesday, June 5, 13
  • 26. Node.js provides a synchronous require Stitch and browserify use node semantics Require.js does AMD How? A library. Wednesday, June 5, 13
  • 27. 5. Watch your return values. Wednesday, June 5, 13
  • 28. dontRunInATightLoop = (object) -> # I meant to mutate this object and return void... object[k] = "#{v}-derp" for k, v of object This... Wednesday, June 5, 13
  • 29. dontRunInATightLoop = function(object) { var k, v, _results; _results = []; for (k in object) { v = object[k]; _results.push(object[k] = "" + v + "-derp"); } return _results; }; ...compiles to this. Wednesday, June 5, 13
  • 32. okayToRunInATightLoop = (object) -> object[k] = "#{v}-derp" for k, v of object # I need to do it explicitly return Wednesday, June 5, 13