Upload
jan-jongboom
View
3.392
Download
2
Embed Size (px)
Citation preview
WAY
ARCHITECTTHE
Jan JongboomJSCamp.asia
November 30, 2012, Singapore
@janjongboom
Program
• Cloud9? 5 minute intro + what's new
• Problems growing your codebase
• Introducing: Architect!
• Lessons learned
Normal developers
JavaScript Developer
OPPA CLOUD9 STYLE
Smart code completion
Static analysis
Free Linux machine
Real terminal
Program
• Cloud9? 5 minute intro + what's new
• Problems growing your codebase
• Introducing: Architect!
• Lessons learned
Hundreds of thousands of lines of JavaScript
(with semicolons ;-))
dynamicweakly-typedlanguage
one single thread
Modularization
Black box coding
Great at abstracting away
Not that good at app level abstraction
Relies on filesystem
• Duplicated modules
• Maps to folder / file name
• Hard to configure
coding time startup time run time
KA-BO
OM!
- Server crash- Unhappy customers- Developer gets fired
Dependency error handling
Program
• Cloud9? 5 minute intro + what's new
• Problems growing your codebase
• Introducing: Architect!
• Lessons learned
Architect
• Every piece of functionality is a plugin
• Plugins can consume other plugins
• An application is a set of plugins
Require
Architect
Runtime
Startup time
Dependency error handlingArchitect style
coding time compile time run time
- Happy customers- Developer keeps job- Fails before release
Here’s what we do
• Code representation of this talk
• Get a speaker from the database
• Talk, talk, talk
• And end with a dance
Group functions by behavior
Datalayer
Presentation
Datalayer Presentation
Dependency model
package.json
Builds dependency tree
executing codewithout
data-‐layer/package.json
presentation/package.json
What’s next?
• Extract the code
• Wrap in Architect plugin code
• It’s simple!
• Make two plugins
Function signature
Call when done
Architect plugin code
• Options, will get to that
• Imports, everything you consume
• Register, invoke when done
Dependencies abstracted away
• Easily unit testable
• Mock dependencies
• Assert ‘talk’ function is called 5 times
No black magic
• Architect builds dependency model
• Feed architect a list of plugins
• Simple array with file names
• Call ‘createApp’
Configuration
• Per-plugin options
• No global options object
• Specify in config file
Options
• Automatically passed in at startup
• Options are also dependencies
• Fail if options aren’t present
• Use default assertions
Architect makes you think of your app as
chunks of functionalityrather than sets of classes
Think ‘chunks of functionality’
• Implicit type constraints
• Keep implementation private
• Swap feature implementations
• Rather than interface implementations
How do we use it?
• Open source version
• Hosted version
• Normal
• FTP
• SSH
Swap feature per implementation
• On Open source: talk local filesystem
• On FTP: talk FTP library
• On SSH: log in and talk via a SSH bridge
HERE’S SOMETHING COOL
Centralized eventbus
• Loose coupling between plugins
• No hard dependencies!
• Can also do inter-context communication
Eventbus
Plugin
Other plugin
Emit event
React on event
And now scale up
• Need something inter-server
• Swap it with i.e. Redis PubSub
• Plugins will never notice
• Awesome!
Program
• Cloud9? 5 minute intro + what's new
• Problems growing your codebase
• Introducing: Architect!
• Lessons learned
Modularize in feature blocks
• Don’t over engineer
• Don’t create too small blocks
• They are no interfaces!
Avoid context switching
• Less code!
• Less errors!
• Less boilerplate!
Loose coupling
• Eventbus
• Smaller dependency graph
Happy coding!