SlideShare une entreprise Scribd logo
1  sur  39
Fugly JavaScript
  Sometimes it’s good to be bad
Profiling
 CSI: Front End
Homespun Profiling
https://gist.github.com/1409341
The Good
How to make friends and influence people
Algorithms
Sorts             Iteration

Searches          Recursion

Filters           Functional Programming

Caching           Object orientation
Unrolled Loops
Unrolling Epic Loops
Lookup Tables
Memoization
Expressions
The Evil
How to lose friends and alienate people
Falsey and Truthy
        Falsey                 Truthy
"" = false               "something" = true

  0 = false               "0" = true

  undefined = false       1 = true

  null = false            -1 = true
Comparisons


==, !=, ===, !==, >, >=, <, <=
Ternary


condition ? ifTrue : ifFalse
Bitwise


&, |, ^, ~, <<, >>, >>>
Know thine enemy
Number
[ digits ][ .digits ][ ( E | e ) [ ( + | - ) ] digits ]
  x=0           x = -077
  x = 123       x = NaN
  x = -14       x = Number.MAX_VALUE = 1.7976931348623157e+308
  x = 0.1541    x = Number.MIN_VALUE = 5e-324
  x = NaN       x = Number.NEGATIVE_INFINITY
  x = 0x1123    x = Number.POSITIVE_INFINITY
  x = -0xF1A7   x = Number.NaN
  x = 015
128   64   32   16   8   4   2   1


1 0 1 1 0 1 0 1 = 181
 -    64   32   16   8   4   2   1


1 0 1 1 0 1 0 1 = -53
Invisible Functions
    ToInteger
    ToInt32
    ToUint32
    ToUint16
var x = parseInt(x, 10);
Comma


expression1, expression2, expression 3;
Comma
Logical OR


expression1 || expression2;
Logical OR
Logical AND


expression1 && expression2;
Logical AND
Fugly JavaScript

Contenu connexe

Similaire à Fugly JavaScript

PyCon2009_AI_Alt
PyCon2009_AI_AltPyCon2009_AI_Alt
PyCon2009_AI_Alt
Hiroshi Ono
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
Ross Lawley
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
Siva Arunachalam
 
F# Presentation
F# PresentationF# Presentation
F# Presentation
mrkurt
 
Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)
Ohgyun Ahn
 

Similaire à Fugly JavaScript (20)

Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python Fundamentals - Basic
Python Fundamentals - BasicPython Fundamentals - Basic
Python Fundamentals - Basic
 
PyCon2009_AI_Alt
PyCon2009_AI_AltPyCon2009_AI_Alt
PyCon2009_AI_Alt
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Welcome to python
Welcome to pythonWelcome to python
Welcome to python
 
機械学習モデルの判断根拠の説明
機械学習モデルの判断根拠の説明機械学習モデルの判断根拠の説明
機械学習モデルの判断根拠の説明
 
A brief introduction to functional programming
A brief introduction to functional programmingA brief introduction to functional programming
A brief introduction to functional programming
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
The Fuss about || Haskell | Scala | F# ||
The Fuss about || Haskell | Scala | F# ||The Fuss about || Haskell | Scala | F# ||
The Fuss about || Haskell | Scala | F# ||
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
Python
PythonPython
Python
 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Context
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
Python
PythonPython
Python
 
Vcs16
Vcs16Vcs16
Vcs16
 
F# Presentation
F# PresentationF# Presentation
F# Presentation
 
Fancy talk
Fancy talkFancy talk
Fancy talk
 
1.1 Real Numbers and Number Operations
1.1 Real Numbers and Number Operations1.1 Real Numbers and Number Operations
1.1 Real Numbers and Number Operations
 
Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)
 

Dernier

Dernier (20)

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
 
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
 
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...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 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
 

Fugly JavaScript

Notes de l'éditeur

  1. Some techniques break JSLint rulesOthers look bizarre or daftFine when you’re coding by yourselfRequire good reasons and good explanatory comments in a team environment
  2. Plenty of tools availableSome even in the browsers
  3. Doing it wrongTime from beginning to endDoing it rightCount number of iterations
  4. There is an overhead to looping
  5. Variation on Duff’s deviceIf we know we have a number of iterations that is a 32 bit number, we can dump the parseInt too
  6. Dynamically typedDifference between equal and strict equal
  7. Equal only compares valuesStrict equal compares values AND type
  8. Returns one of two values based on the logical value of the condition
  9. Perform functions on values as binary numbersTreat operands as a set of 32 bitsReturn standard numerical values
  10. Technically a 64-bit number; actually 32-bit when doing anything bitwise.
  11. Invisible functions
  12. Converts to an integerConverts to a signed 32-bit integerConverts to an unsigned 32-bit integerConverts to an unsigned 16-bit integer
  13. Allows multiple expressions to be evaluated in a single statementReturns the result of the last expression
  14. Returns expr1 if it can be converted to true; otherwise, returns expr2.
  15. Returns expr1 if it can be converted to false; otherwise, returns expr2.