SlideShare a Scribd company logo
1 of 27
Amir Barylko MavenThought Inc.
AMIR BARYLKO
BEAUTIFUL JS
WITH
COFFEESCRIPT
Amir Barylko Beautiful JS with CS
WHO AM I?
• Software quality expert
• Architect
• Developer
• Mentor
• Great cook
• The one who’s entertaining you for the next hour!
Amir Barylko Beautiful JS with CS
RESOURCES
• Email: amir@barylko.com
• Twitter: @abarylko
• Blog: http://www.orthocoders.com
• Materials: http://www.orthocoders.com/presentations
Amir Barylko Beautiful JS with CS
COFFEESCRIPT
Amir Barylko Beautiful JS with CS
WHAT’S WRONG WITH JS
• Too verbose (too many { and } )
• GlobalVariables
• Lacks support for classes
• Hard to make inheritance
• Automatic type conversion between strings and numbers
• NaN is not a number, however it is a number
Amir Barylko Beautiful JS with CS
WHAT IS IT?
“CoffeeScript is a little language that compiles into
JavaScript. Underneath all those awkward braces and
semicolons, JavaScript has always had a gorgeous
object model at its heart. CoffeeScript is an attempt
to expose the good parts of JavaScript in a simple
way.”
http://coffeescript.org/
Amir Barylko Beautiful JS with CS
STRING INTERPOLATION
•You can concatenate inside a double quote string
using the “#” and “{ }”
"The result is #{3}" == "The result is 3"
•Or use any expression
"/movies/#{id}"
Amir Barylko Beautiful JS with CS
FUNCTIONS
•The arrow/lambda defines functions
square = (x) -> x * x
•Parenthesis are optional when passing
parameters
storageDelete movieId, true
Amir Barylko Beautiful JS with CS
FUNCTIONS II
•Implicit return
(the last expression is the return value)
•Multiple lines, indentation is important
deleteMovie = (e) ->
movieId = $(e.target)....
storageDelete(movieId)
Amir Barylko Beautiful JS with CS
OBJECTS AS HASHES
•Declared using indentation
config =
local:
user: 'dev'
pwd: 'dev123'
remote:
user: 'superdev'
pwd: "impossibleToGuess"
Amir Barylko Beautiful JS with CS
ARRAYS
•Arrays are declared with “[ ]”
deploy = ['local', 'remote', 'uat']
fib = [1, 3, 5, 8, 13, 21]
•Slicing
first = fib[0..3]
noLast = fib[0..-2]
Amir Barylko Beautiful JS with CS
DESTRUCTURING
ASSIGNMENT
•Multiple assignments
[firstName, nick, last] = ['D'Arcy', 'Baconator', 'Lussier']
•Splat
reviews = [45, 29, 21, 10, 8, 4]
[best, secondBest, theRest...] = reviews
Amir Barylko Beautiful JS with CS
CONDITIONALS
•Classic if does not need parenthesis
if isJson
callIndex()
display()
else
showMessage()
•Or use unless for the negated form
Amir Barylko Beautiful JS with CS
MODIFIERS
•The conditionals can be use as modifiers
callIndex() if isJson
exit() unless validated and inContext
Amir Barylko Beautiful JS with CS
SWITCH
• Selects between multiple conditions
movieReview = (critic, movie) ->
switch critic
when 'Jay'
'It Stinks!'
when 'Darcy'
if movie.match(/Bacon/) then...
else
throw new Error('Invalid critic name!')
Amir Barylko Beautiful JS with CS
LIST COMPREHENSION
•Iterate and call a function over each element
deploy env for env in ['local', 'uat', 'prod']
•Or filter over a collection
nums = (num for num in [1..960] when isInteger(960 / num))
Amir Barylko Beautiful JS with CS
EXISTENTIAL OPERATOR
• Checks if a variable is null or undefined
question = paragraph? and not createdDate?
defaultValue ?= 5
precendence = first ? 5
• It can be used to avoidTypeError exception
extension = secondaryAddress?().phone?.extension
Amir Barylko Beautiful JS with CS
CLASSES
class MovieRepository
constructor: (@baseUrl) ->
newMovie: ->
$.ajax
url: "#{@baseUrl}/movies/create"
success: (data) -> $(id).append data
Amir Barylko Beautiful JS with CS
INHERITANCE
• One class can extend another
class Shape
constructor: (@width) ->
class Square extends Shape
computeArea: -> Math.pow @width, 2
class Circle extends Shape
radius: -> @width / 2
computeArea: -> Math.PI * Math.pow @radius(), 2
Amir Barylko Beautiful JS with CS
COMPLAINS
(Go ahead, say it)
Amir Barylko Beautiful JS with CS
I ALREADY KNOW JS
•Continuous learning
•Benefits outweigh effort
•Generates way better code
•Do your duty as developer!
Amir Barylko Beautiful JS with CS
EXTRA COMPILATION STEP
•.NET and Java frameworks will do it for you
•Or tools will watch your folder and generate it
for you
•Hardly notice the extra work
Amir Barylko Beautiful JS with CS
DEBUGGING IS HARD
•Same variable names
•Just set a breakpoint in the code
•and add watches, etc....
Amir Barylko Beautiful JS with CS
TESTING & 3RD PARTY
•Is just Javascript
•so use Jasmine
•or Qunit
•any other....
Amir Barylko Advanced Design Patterns
QUESTIONS?
Amir Barylko Beautiful JS with CS
RESOURCES
• Email: amir@barylko.com, @abarylko
• Slides & Source: http://www.orthocoders.com/presentations
• http://coffeescript.org
• https://github.com/sleepyfox/coffeescript-koans
• http://pivotal.github.com/jasmine/
• http://qunitjs.com/
• http://nodejs.org/
Amir Barylko Beautiful JS with CS
RESOURCES II

More Related Content

Viewers also liked

Viewers also liked (7)

Quotes
QuotesQuotes
Quotes
 
UNK Product specification
UNK Product specificationUNK Product specification
UNK Product specification
 
OJS Author Part by Prof. Aziz I. Abdulla
OJS Author  Part by Prof. Aziz I. AbdullaOJS Author  Part by Prof. Aziz I. Abdulla
OJS Author Part by Prof. Aziz I. Abdulla
 
Armas Especial Rifles
Armas Especial RiflesArmas Especial Rifles
Armas Especial Rifles
 
Success quotes
Success quotesSuccess quotes
Success quotes
 
Pointing and finishing
Pointing and finishingPointing and finishing
Pointing and finishing
 
Final magazine construction
Final magazine constructionFinal magazine construction
Final magazine construction
 

Similar to Beutiful javascript with coffeescript

PRDC12 advanced design patterns
PRDC12 advanced design patternsPRDC12 advanced design patterns
PRDC12 advanced design patternsAmir Barylko
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextMugunth Kumar
 
Infrastructure as Code on Azure: Show your Bicep!
Infrastructure as Code on Azure: Show your Bicep!Infrastructure as Code on Azure: Show your Bicep!
Infrastructure as Code on Azure: Show your Bicep!Marco Obinu
 
Something Died Inside Your Git Repo
Something Died Inside Your Git RepoSomething Died Inside Your Git Repo
Something Died Inside Your Git RepoCliff Smith
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
The Future of HTML Motion Design
The Future of HTML Motion DesignThe Future of HTML Motion Design
The Future of HTML Motion DesignTerry Ryan
 
Advanced Technology for Web Application Design
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application DesignBryce Kerley
 
WordCamp Bristol 2019 - WordPress custom theme building
WordCamp Bristol 2019 - WordPress custom theme buildingWordCamp Bristol 2019 - WordPress custom theme building
WordCamp Bristol 2019 - WordPress custom theme buildingJonny Allbut
 
Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...
Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...
Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...Marco Obinu
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Eric Phan
 
Write your Ruby in Style
Write your Ruby in StyleWrite your Ruby in Style
Write your Ruby in StyleBhavin Javia
 
CSS workshop @ OutSystems
CSS workshop @ OutSystemsCSS workshop @ OutSystems
CSS workshop @ OutSystemsRuben Goncalves
 
PRDCW-advanced-design-patterns
PRDCW-advanced-design-patternsPRDCW-advanced-design-patterns
PRDCW-advanced-design-patternsAmir Barylko
 
October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101Eric Sembrat
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
A baryklo design-patterns
A baryklo design-patternsA baryklo design-patterns
A baryklo design-patternssdeconf
 
sdec11-Advanced-design-patterns
sdec11-Advanced-design-patternssdec11-Advanced-design-patterns
sdec11-Advanced-design-patternsAmir Barylko
 

Similar to Beutiful javascript with coffeescript (20)

PRDC12 advanced design patterns
PRDC12 advanced design patternsPRDC12 advanced design patterns
PRDC12 advanced design patterns
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreText
 
Infrastructure as Code on Azure: Show your Bicep!
Infrastructure as Code on Azure: Show your Bicep!Infrastructure as Code on Azure: Show your Bicep!
Infrastructure as Code on Azure: Show your Bicep!
 
Something Died Inside Your Git Repo
Something Died Inside Your Git RepoSomething Died Inside Your Git Repo
Something Died Inside Your Git Repo
 
Design Without Types
Design Without TypesDesign Without Types
Design Without Types
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
The Future of HTML Motion Design
The Future of HTML Motion DesignThe Future of HTML Motion Design
The Future of HTML Motion Design
 
Advanced Technology for Web Application Design
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application Design
 
WordCamp Bristol 2019 - WordPress custom theme building
WordCamp Bristol 2019 - WordPress custom theme buildingWordCamp Bristol 2019 - WordPress custom theme building
WordCamp Bristol 2019 - WordPress custom theme building
 
Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...
Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...
Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!
 
Write your Ruby in Style
Write your Ruby in StyleWrite your Ruby in Style
Write your Ruby in Style
 
CSS workshop @ OutSystems
CSS workshop @ OutSystemsCSS workshop @ OutSystems
CSS workshop @ OutSystems
 
PRDCW-advanced-design-patterns
PRDCW-advanced-design-patternsPRDCW-advanced-design-patterns
PRDCW-advanced-design-patterns
 
October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101
 
Jquery2012 defs
Jquery2012 defsJquery2012 defs
Jquery2012 defs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
A baryklo design-patterns
A baryklo design-patternsA baryklo design-patterns
A baryklo design-patterns
 
sdec11-Advanced-design-patterns
sdec11-Advanced-design-patternssdec11-Advanced-design-patterns
sdec11-Advanced-design-patterns
 

More from Amir Barylko

Functional converter project
Functional converter projectFunctional converter project
Functional converter projectAmir Barylko
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web developmentAmir Barylko
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep diveAmir Barylko
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting trainingAmir Barylko
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessAmir Barylko
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6Amir Barylko
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?Amir Barylko
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideAmir Barylko
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityAmir Barylko
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentAmir Barylko
 
Agile requirements
Agile requirementsAgile requirements
Agile requirementsAmir Barylko
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilitiesAmir Barylko
 
Agile requirements
Agile requirementsAgile requirements
Agile requirementsAmir Barylko
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integrationAmir Barylko
 

More from Amir Barylko (20)

Functional converter project
Functional converter projectFunctional converter project
Functional converter project
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web development
 
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
 
No estimates
No estimatesNo estimates
No estimates
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep dive
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting training
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomeness
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6
 
Productive teams
Productive teamsProductive teams
Productive teams
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other side
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivity
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
Refactoring
RefactoringRefactoring
Refactoring
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilities
 
Refactoring
RefactoringRefactoring
Refactoring
 
Sass & bootstrap
Sass & bootstrapSass & bootstrap
Sass & bootstrap
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integration
 

Recently uploaded

Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfFIDO Alliance
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyUXDXConf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...FIDO Alliance
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfUK Journal
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...marcuskenyatta275
 

Recently uploaded (20)

Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 

Beutiful javascript with coffeescript

  • 1. Amir Barylko MavenThought Inc. AMIR BARYLKO BEAUTIFUL JS WITH COFFEESCRIPT
  • 2. Amir Barylko Beautiful JS with CS WHO AM I? • Software quality expert • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour!
  • 3. Amir Barylko Beautiful JS with CS RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Blog: http://www.orthocoders.com • Materials: http://www.orthocoders.com/presentations
  • 4. Amir Barylko Beautiful JS with CS COFFEESCRIPT
  • 5. Amir Barylko Beautiful JS with CS WHAT’S WRONG WITH JS • Too verbose (too many { and } ) • GlobalVariables • Lacks support for classes • Hard to make inheritance • Automatic type conversion between strings and numbers • NaN is not a number, however it is a number
  • 6. Amir Barylko Beautiful JS with CS WHAT IS IT? “CoffeeScript is a little language that compiles into JavaScript. Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.” http://coffeescript.org/
  • 7. Amir Barylko Beautiful JS with CS STRING INTERPOLATION •You can concatenate inside a double quote string using the “#” and “{ }” "The result is #{3}" == "The result is 3" •Or use any expression "/movies/#{id}"
  • 8. Amir Barylko Beautiful JS with CS FUNCTIONS •The arrow/lambda defines functions square = (x) -> x * x •Parenthesis are optional when passing parameters storageDelete movieId, true
  • 9. Amir Barylko Beautiful JS with CS FUNCTIONS II •Implicit return (the last expression is the return value) •Multiple lines, indentation is important deleteMovie = (e) -> movieId = $(e.target).... storageDelete(movieId)
  • 10. Amir Barylko Beautiful JS with CS OBJECTS AS HASHES •Declared using indentation config = local: user: 'dev' pwd: 'dev123' remote: user: 'superdev' pwd: "impossibleToGuess"
  • 11. Amir Barylko Beautiful JS with CS ARRAYS •Arrays are declared with “[ ]” deploy = ['local', 'remote', 'uat'] fib = [1, 3, 5, 8, 13, 21] •Slicing first = fib[0..3] noLast = fib[0..-2]
  • 12. Amir Barylko Beautiful JS with CS DESTRUCTURING ASSIGNMENT •Multiple assignments [firstName, nick, last] = ['D'Arcy', 'Baconator', 'Lussier'] •Splat reviews = [45, 29, 21, 10, 8, 4] [best, secondBest, theRest...] = reviews
  • 13. Amir Barylko Beautiful JS with CS CONDITIONALS •Classic if does not need parenthesis if isJson callIndex() display() else showMessage() •Or use unless for the negated form
  • 14. Amir Barylko Beautiful JS with CS MODIFIERS •The conditionals can be use as modifiers callIndex() if isJson exit() unless validated and inContext
  • 15. Amir Barylko Beautiful JS with CS SWITCH • Selects between multiple conditions movieReview = (critic, movie) -> switch critic when 'Jay' 'It Stinks!' when 'Darcy' if movie.match(/Bacon/) then... else throw new Error('Invalid critic name!')
  • 16. Amir Barylko Beautiful JS with CS LIST COMPREHENSION •Iterate and call a function over each element deploy env for env in ['local', 'uat', 'prod'] •Or filter over a collection nums = (num for num in [1..960] when isInteger(960 / num))
  • 17. Amir Barylko Beautiful JS with CS EXISTENTIAL OPERATOR • Checks if a variable is null or undefined question = paragraph? and not createdDate? defaultValue ?= 5 precendence = first ? 5 • It can be used to avoidTypeError exception extension = secondaryAddress?().phone?.extension
  • 18. Amir Barylko Beautiful JS with CS CLASSES class MovieRepository constructor: (@baseUrl) -> newMovie: -> $.ajax url: "#{@baseUrl}/movies/create" success: (data) -> $(id).append data
  • 19. Amir Barylko Beautiful JS with CS INHERITANCE • One class can extend another class Shape constructor: (@width) -> class Square extends Shape computeArea: -> Math.pow @width, 2 class Circle extends Shape radius: -> @width / 2 computeArea: -> Math.PI * Math.pow @radius(), 2
  • 20. Amir Barylko Beautiful JS with CS COMPLAINS (Go ahead, say it)
  • 21. Amir Barylko Beautiful JS with CS I ALREADY KNOW JS •Continuous learning •Benefits outweigh effort •Generates way better code •Do your duty as developer!
  • 22. Amir Barylko Beautiful JS with CS EXTRA COMPILATION STEP •.NET and Java frameworks will do it for you •Or tools will watch your folder and generate it for you •Hardly notice the extra work
  • 23. Amir Barylko Beautiful JS with CS DEBUGGING IS HARD •Same variable names •Just set a breakpoint in the code •and add watches, etc....
  • 24. Amir Barylko Beautiful JS with CS TESTING & 3RD PARTY •Is just Javascript •so use Jasmine •or Qunit •any other....
  • 25. Amir Barylko Advanced Design Patterns QUESTIONS?
  • 26. Amir Barylko Beautiful JS with CS RESOURCES • Email: amir@barylko.com, @abarylko • Slides & Source: http://www.orthocoders.com/presentations • http://coffeescript.org • https://github.com/sleepyfox/coffeescript-koans • http://pivotal.github.com/jasmine/ • http://qunitjs.com/ • http://nodejs.org/
  • 27. Amir Barylko Beautiful JS with CS RESOURCES II