Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Your Code Sucks: Best Practices for Enterprise ...
Search
Arthur Kay
August 15, 2012
Programming
8
2.7k
Your Code Sucks: Best Practices for Enterprise JavaScript Development
From ThatConference 2012
Arthur Kay
August 15, 2012
Tweet
Share
More Decks by Arthur Kay
See All by Arthur Kay
Analyzing the ROI of JavaScript in Enterprise Software Development
arthurakay
0
150
Debugging your Apps with Google Chrome and Sencha
arthurakay
1
270
Announcing Ext JS 5
arthurakay
0
140
Conquering the Command Line
arthurakay
0
310
The Future of Enterprise App Development
arthurakay
0
130
Best Practices for Enterprise JavaScript Applications
arthurakay
7
2.5k
Bringing the Mobile Web to the Cloud
arthurakay
2
550
Building Native Windows 8 Apps with Sencha
arthurakay
0
250
Creating Windows 8 Apps with Ext JS
arthurakay
1
290
Other Decks in Programming
See All in Programming
非同期jobをtransaction内で 呼ぶなよ!絶対に呼ぶなよ!
alstrocrack
0
710
なぜGoのジェネリクスはこの形なのか? Featherweight Goが明かす設計の核心
ryotaros
7
1.1k
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
30k
overlayPreferenceValue で実現する ピュア SwiftUI な AdMob ネイティブ広告
uhucream
0
180
SpecKitでどこまでできる? コストはどれくらい?
leveragestech
0
690
After go func(): Goroutines Through a Beginner’s Eye
97vaibhav
0
370
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
160
Swift Concurrency - 状態監視の罠
objectiveaudio
2
510
CSC509 Lecture 05
javiergs
PRO
0
300
Foundation Modelsを実装日本語学習アプリを作ってみた!
hypebeans
0
110
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
230
NixOS + Kubernetesで構築する自宅サーバーのすべて
ichi_h3
0
620
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
33
8.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.5k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
Code Review Best Practice
trishagee
72
19k
RailsConf 2023
tenderlove
30
1.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Navigating Team Friction
lara
190
15k
A Modern Web Designer's Workflow
chriscoyier
697
190k
Speed Design
sergeychernyshev
32
1.2k
GitHub's CSS Performance
jonrohan
1032
470k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Optimising Largest Contentful Paint
csswizardry
37
3.4k
Transcript
Best Practices for Enterprise JavaScript Applications YOUR CODE SUCKS
WHO AM I? • Arthur Kay • Solutions Engineer @
Sencha, Inc. • Web Development ~15 years • www.akawebdesign.com • @arthurakay
AGENDA • Improving application performance • Increasing code stability •
Scaling applications for enterprise • Tools • Advice
None
IMPROVING APPLICATION PERFORMANCE Part 1
CACHING
THIS CODE SUCKS
DO THIS INSTEAD • Cache values (references) • Avoid using
document.getElementById() and other global queries
DO THIS INSTEAD
OVER NESTING
THIS CODE SUCKS
DO THIS INSTEAD • Use lightweight containers (reduce DOM) •
Lazy Rendering
DO THIS INSTEAD
MEMORY LEAKS
THIS CODE SUCKS
DO THIS INSTEAD
INCREASING CODE STABILITY Part 2
SYNTAX ERRORS
THIS CODE SUCKS
DO THIS INSTEAD • Use JSLint (or something else) •
AUTOMATE SYNTAX CHECKING
ONE CLASS PER FILE
THIS CODE SUCKS
DO THIS INSTEAD • Organize your file system • Files
and folders should match namespacing • MVC (or something) • Development loader / Production builder
NAMES HAVE MEANING
THIS CODE SUCKS
DO THIS INSTEAD • Descriptive names on everything (except iterators)
• Common naming conventions (camelCase vs TitleCase vs nocase) • Exceptions for • constants ( SOME_CONSTANT ) • constructors ( MyClass ) • sub-namespaces ( Foo.bar.Class )_
COMMENTS / DOCUMENTATION
THIS CODE SUCKS
DO THIS INSTEAD • Comment top-level structures • Add notes
whenever logic is not obvious • Build your docs into a searchable tool
SCALING APPLICATIONS FOR ENTERPRISE Part 3
AVOID DUPLICATION
THIS CODE SUCKS
DO THIS INSTEAD • Abstraction! • Use mixins when possible
• Apply stuff to prototypes • Have similar classes/methods? • call() and apply()
DO THIS INSTEAD
SMALLER FILES. WHITE SPACE.
THIS CODE SUCKS
DO THIS INSTEAD • Keep methods under 50 lines •
Keep files under 500 lines • Use as much whitespace as possible.
UNIT TESTS
THIS CODE SUCKS
DO THIS INSTEAD • Write “testable” code • Focus on
important / trouble areas • AUTOMATE UNIT TESTING • Don’t insist on UI (integration/iteraction) tests * Test Driven JavaScript Development by Christian Johansen
TOOLS Stuff You Should Know About
IDE
INSPECT ELEMENT
YSLOW
JS DUCK
PHANTOM.JS
ADVICE Things I’ve Learned
SPECIFICATION – NOT TDD
NEVER STOP LEARNING
BREAK (SOME) RULES
None
ADDITIONAL RESOURCES • “Maintainable JavaScript” by Nicholas Zakas • http://www.slideshare.net/nzakas/maintainable-javascript-2012
• “Code Conventions for JS” by Douglass Crockford • http://javascript.crockford.com/code.html • “JavaScript Performance Tips & Tricks” by Grgur Grisogono • http://moduscreate.com/javascript-performance-tips-tricks/
THANKS! Arthur Kay | @arthurakay
SPEAKERDECK.COM/U/ARTHURAKAY Share this presentation: