SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Destacado (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 a 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 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
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 a 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 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
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
 

Más de 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
 

Más de 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
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 
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
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
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...
 

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