78
WAY ARCHITECT THE Jan Jongboom JSCamp.asia November 30, 2012, Singapore

The Architect Way - JSCamp.asia 2012

Embed Size (px)

Citation preview

Page 1: The Architect Way - JSCamp.asia 2012

WAY

ARCHITECTTHE

Jan JongboomJSCamp.asia

November 30, 2012, Singapore

Page 2: The Architect Way - JSCamp.asia 2012

@janjongboom

Page 3: The Architect Way - JSCamp.asia 2012

Program

• Cloud9? 5 minute intro + what's new

• Problems growing your codebase

• Introducing: Architect!

• Lessons learned

Page 4: The Architect Way - JSCamp.asia 2012

Normal developers

Page 5: The Architect Way - JSCamp.asia 2012

JavaScript Developer

Page 6: The Architect Way - JSCamp.asia 2012

OPPA CLOUD9 STYLE

Page 7: The Architect Way - JSCamp.asia 2012
Page 8: The Architect Way - JSCamp.asia 2012
Page 9: The Architect Way - JSCamp.asia 2012

Smart code completion

Page 10: The Architect Way - JSCamp.asia 2012

Static analysis

Page 11: The Architect Way - JSCamp.asia 2012

Free Linux machine

Page 12: The Architect Way - JSCamp.asia 2012

Real terminal

Page 13: The Architect Way - JSCamp.asia 2012

Program

• Cloud9? 5 minute intro + what's new

• Problems growing your codebase

• Introducing: Architect!

• Lessons learned

Page 14: The Architect Way - JSCamp.asia 2012

Hundreds of thousands of lines of JavaScript

(with semicolons ;-))

Page 15: The Architect Way - JSCamp.asia 2012

dynamicweakly-typedlanguage

Page 16: The Architect Way - JSCamp.asia 2012

one single thread

Page 17: The Architect Way - JSCamp.asia 2012
Page 18: The Architect Way - JSCamp.asia 2012

Modularization

Page 19: The Architect Way - JSCamp.asia 2012

Black box coding

Page 20: The Architect Way - JSCamp.asia 2012
Page 21: The Architect Way - JSCamp.asia 2012

Great at abstracting away

Page 22: The Architect Way - JSCamp.asia 2012

Not that good at app level abstraction

Page 23: The Architect Way - JSCamp.asia 2012

Relies on filesystem

• Duplicated modules

• Maps to folder / file name

• Hard to configure

Page 24: The Architect Way - JSCamp.asia 2012

coding time startup time run time

KA-BO

OM!

- Server crash- Unhappy customers- Developer gets fired

Dependency error handling

Page 25: The Architect Way - JSCamp.asia 2012

Program

• Cloud9? 5 minute intro + what's new

• Problems growing your codebase

• Introducing: Architect!

• Lessons learned

Page 26: The Architect Way - JSCamp.asia 2012

Architect

• Every piece of functionality is a plugin

• Plugins can consume other plugins

• An application is a set of plugins

Page 27: The Architect Way - JSCamp.asia 2012

Require

Architect

Runtime

Startup time

Page 28: The Architect Way - JSCamp.asia 2012

Dependency error handlingArchitect style

coding time compile time run time

- Happy customers- Developer keeps job- Fails before release

Page 29: The Architect Way - JSCamp.asia 2012

Here’s what we do

• Code representation of this talk

• Get a speaker from the database

• Talk, talk, talk

• And end with a dance

Page 30: The Architect Way - JSCamp.asia 2012
Page 31: The Architect Way - JSCamp.asia 2012
Page 32: The Architect Way - JSCamp.asia 2012
Page 33: The Architect Way - JSCamp.asia 2012
Page 34: The Architect Way - JSCamp.asia 2012
Page 35: The Architect Way - JSCamp.asia 2012

Group functions by behavior

Page 36: The Architect Way - JSCamp.asia 2012

Datalayer

Presentation

Page 37: The Architect Way - JSCamp.asia 2012

Datalayer Presentation

Dependency model

Page 38: The Architect Way - JSCamp.asia 2012

package.json

Builds dependency tree

executing codewithout

Page 39: The Architect Way - JSCamp.asia 2012

data-­‐layer/package.json

presentation/package.json

Page 40: The Architect Way - JSCamp.asia 2012

What’s next?

• Extract the code

• Wrap in Architect plugin code

• It’s simple!

• Make two plugins

Page 41: The Architect Way - JSCamp.asia 2012

Function signature

Call when done

Page 42: The Architect Way - JSCamp.asia 2012

Architect plugin code

• Options, will get to that

• Imports, everything you consume

• Register, invoke when done

Page 43: The Architect Way - JSCamp.asia 2012
Page 44: The Architect Way - JSCamp.asia 2012
Page 45: The Architect Way - JSCamp.asia 2012
Page 46: The Architect Way - JSCamp.asia 2012

Dependencies abstracted away

• Easily unit testable

• Mock dependencies

• Assert ‘talk’ function is called 5 times

Page 47: The Architect Way - JSCamp.asia 2012
Page 48: The Architect Way - JSCamp.asia 2012
Page 49: The Architect Way - JSCamp.asia 2012
Page 50: The Architect Way - JSCamp.asia 2012
Page 51: The Architect Way - JSCamp.asia 2012

No black magic

• Architect builds dependency model

• Feed architect a list of plugins

• Simple array with file names

• Call ‘createApp’

Page 52: The Architect Way - JSCamp.asia 2012
Page 53: The Architect Way - JSCamp.asia 2012
Page 54: The Architect Way - JSCamp.asia 2012
Page 55: The Architect Way - JSCamp.asia 2012

Configuration

• Per-plugin options

• No global options object

• Specify in config file

Page 56: The Architect Way - JSCamp.asia 2012
Page 57: The Architect Way - JSCamp.asia 2012
Page 58: The Architect Way - JSCamp.asia 2012

Options

• Automatically passed in at startup

• Options are also dependencies

• Fail if options aren’t present

• Use default assertions

Page 59: The Architect Way - JSCamp.asia 2012
Page 60: The Architect Way - JSCamp.asia 2012
Page 61: The Architect Way - JSCamp.asia 2012

Architect makes you think of your app as

chunks of functionalityrather than sets of classes

Page 62: The Architect Way - JSCamp.asia 2012

Think ‘chunks of functionality’

• Implicit type constraints

• Keep implementation private

• Swap feature implementations

• Rather than interface implementations

Page 63: The Architect Way - JSCamp.asia 2012

How do we use it?

• Open source version

• Hosted version

• Normal

• FTP

• SSH

Page 64: The Architect Way - JSCamp.asia 2012
Page 65: The Architect Way - JSCamp.asia 2012

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

Page 66: The Architect Way - JSCamp.asia 2012

HERE’S SOMETHING COOL

Page 67: The Architect Way - JSCamp.asia 2012

Centralized eventbus

• Loose coupling between plugins

• No hard dependencies!

• Can also do inter-context communication

Page 68: The Architect Way - JSCamp.asia 2012

Eventbus

Plugin

Other plugin

Emit event

React on event

Page 69: The Architect Way - JSCamp.asia 2012
Page 70: The Architect Way - JSCamp.asia 2012
Page 71: The Architect Way - JSCamp.asia 2012

And now scale up

• Need something inter-server

• Swap it with i.e. Redis PubSub

• Plugins will never notice

• Awesome!

Page 72: The Architect Way - JSCamp.asia 2012

Program

• Cloud9? 5 minute intro + what's new

• Problems growing your codebase

• Introducing: Architect!

• Lessons learned

Page 73: The Architect Way - JSCamp.asia 2012

Modularize in feature blocks

• Don’t over engineer

• Don’t create too small blocks

• They are no interfaces!

Page 74: The Architect Way - JSCamp.asia 2012

Avoid context switching

• Less code!

• Less errors!

• Less boilerplate!

Page 75: The Architect Way - JSCamp.asia 2012

Loose coupling

• Eventbus

• Smaller dependency graph

Page 76: The Architect Way - JSCamp.asia 2012

github.com/c9/architect

Page 77: The Architect Way - JSCamp.asia 2012

Happy coding!

Page 78: The Architect Way - JSCamp.asia 2012

Jan Jongboomgithub.com/janjongboom

@janjongboom

http://c9.io