SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 

Kürzlich hochgeladen (20)

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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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...
 

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