67
Huge Web Apps daniel.steigerwald.cz

Huge web apps web expo 2013

Embed Size (px)

DESCRIPTION

Apps with millions lines of code maintained by hundreds of SWEs. Can vanilla JS + HTML5 do the job? If not, what can? TypeScript? Dart?

Citation preview

Page 1: Huge web apps web expo 2013

Huge Web Appsdaniel.steigerwald.cz

Page 2: Huge web apps web expo 2013

● independent software gardener● web applications consultant and trainer● Google Developer Expert● libertarian svobodni.cz

About Me

Page 3: Huge web apps web expo 2013

What is a Huge App?

Page 4: Huge web apps web expo 2013

sooner or later

The Pain.

Page 5: Huge web apps web expo 2013

Symptoms

● fixing bugs creates new bugs● rotten code● developers paralyzed by fear● technical debts● reinventing the wheel● perpetual rewriting

= stress driven development

Page 6: Huge web apps web expo 2013

Remedies

● optional static typing● user interface frameworks● clean code● clean architecture● good infrastructure● unit tests● senior developers :-)

Page 7: Huge web apps web expo 2013

Optional Static Typingdynamic versus static

Page 8: Huge web apps web expo 2013

Keeping Your Code in Check!Make it hard to do the wrong thing.

Page 9: Huge web apps web expo 2013

Makes code more readable.function(duck) { // which duck? duck.quack(); }

Page 10: Huge web apps web expo 2013

Makes code more robust.function(duck) { duck.quack(); // does quack?}

Page 11: Huge web apps web expo 2013

No JavaScript?The king is dead, long live the king!

Page 12: Huge web apps web expo 2013

Closure, Dart, TypeScriptBorn to be wild tamed.

Page 13: Huge web apps web expo 2013

Google ClosureThat's how Google build apps.

Page 14: Huge web apps web expo 2013

function fn(duck) {

duck.quack();

}

Page 15: Huge web apps web expo 2013

/**

* @param {Duck} duck

*/

function fn(duck) {

duck.quack();

}

Page 16: Huge web apps web expo 2013

DartThat's how Google will build apps.

Page 17: Huge web apps web expo 2013

fn(duck) {

duck.quack();

}

Page 18: Huge web apps web expo 2013

fn(Duck duck) {

duck.quack();

}

Page 19: Huge web apps web expo 2013

TypeScriptMicrosoft did the right thing.

Page 20: Huge web apps web expo 2013

function(duck) {

duck.quack();

}

Page 21: Huge web apps web expo 2013

function(duck: Duck) {

duck.quack();

}

Page 22: Huge web apps web expo 2013

github.com/borisyankov/DefinitelyTyped

fixing legacy code

Page 23: Huge web apps web expo 2013

Ace Cloud9 Editor AmCharts AngularJS Arbiter async Backbone.js Backbone Relational Bootbox Bootstrap bootstrap-notify bootstrap.datepicker Box2DWeb Breeze Browser Harness CasperJS Cheerio Chosen Chrome CodeMirror Commander d3.js docCookies domo dust EaselJS ember.js EpicEditor expect.js Express Ext JS Fabric.js Fancybox File API: Directories and System File API: Writer Finite State Machine Firebase Firefox FlexSlider Foundation FPSMeter FullCalendar Gamepad glDatePicker GoJS GreenSock Animation Platform Grunt JS Google API Client Google App Engine Channel API GoogleMaps Google Geolocation Google Page Speed Online API Google Translate API Google Url Shortener Hammer.js Handlebars Highcharts highlight.js History.js Humane.js i18next iCheck Impress.js Intl iScroll jake Jasmine Jasmine-jQuery JointJS jQRangeSlider jQuery jQuery Mobile jQuery UI jQuery.Address jQuery.areYouSure jQuery.autosize jQuery.BBQ jQuery.contextMenu jQuery.clientSideLogging jQuery.Colorbox jQuery.Cookie jQuery.Cycle jQuery.dataTables jQuery.dynatree jQuery.Flot jQuery.form jQuery.Globalize jQuery.gridster jQuery.jNotify jQuery.noty jQuery.pickadate jQuery.payment jQuery.scrollTo jQuery.simplePagination jquery.superLink jQuery.timeago jQuery.Timepicker jQuery.TinyCarousel jQuery.TinyScrollbar jQuery.Transit jQuery.Validation jQuery.Watermark jScrollPane JSDeferred JSONEditorOnline jStorage JWPlayer KeyboardJS Knockback Knockout.js Knockout.DeferredUpdates Knockout.ES5 Knockout.Mapping Knockout.Postbox Knockout.Validation Knockout.Viewmodel ko.editables KoLite Leaflet Libxmljs ladda Levelup linq.js Livestamp.js Logg Marked Meteor Modernizr Moment.js MongoDB Mousetrap Mustache.js Node.js node_redis node-ffi node_zeromq node-sqlserver Numeral.js Parallel.js PDF.js Persona PhantomJS PhoneGap PixiJS Platform PouchDB PreloadJS QUnit Raven.js Rickshaw Restify Royalslider Rx.js Raphael Restangular require.js Sammy.js Select2 Sencha Touch SharePoint SignalR Sinon SlickGrid socket.io SockJS SoundJS Spin stripe Store.js Sugar Swiper SwipeView Tags Manager Teechart three.js Toastr trunk8 TweenJS tween.js twitter-bootstrap-wizard Ubuntu Unity Web API Underscore.js Underscore.js Underscore-ko.js UUID.js Viewporter Vimeo WebRTC WinJS WinRT YouTube YouTube Analytics API YouTube Data API Zepto.js Zynga Scroller ZeroClipboard

Page 24: Huge web apps web expo 2013

User InterfaceBeyond the jQuery Backbone.

Page 25: Huge web apps web expo 2013

Why Backbone is not enough?It doesn’t aspire to be anything more than a

lightweight library for models and collections.

Page 26: Huge web apps web expo 2013

Why Backbone is not enough?Default Backbone view is simply too simple.

Page 28: Huge web apps web expo 2013

Handlebars, Mustache, Underscore templates, Dust, Jade and many others...

HTML templates based only on string concatenation are

obsolete.

Page 29: Huge web apps web expo 2013

Don't hold state in DOM.Use DOM only as app state projection.

Page 30: Huge web apps web expo 2013

Partial DOM updates sucks.this.$('#filters li a') .removeClass('selected') .filter('[href="#/' + (app.TodoFilter || '') + '"]') .addClass('selected');

Page 31: Huge web apps web expo 2013

Say no to boilerplate code.especially for view updates

Page 32: Huge web apps web expo 2013

Angular, Ember, Reactview updates done well

Page 33: Huge web apps web expo 2013

/** @jsx React.DOM */

var HelloMessage = React.createClass({

render: function() {

return <div>{'Hello ' + this.props.name}</div>;

}

});

React.renderComponent(<HelloMessage name="John" />, el);

Facebook React

Page 34: Huge web apps web expo 2013

var Nav, Profile;

// Input (JSX):

var app =

<Nav color="blue">

<Profile>click</Profile>

</Nav>;

// Output (JS):

var app = Nav({color:"blue"}, Profile(null, "click"));

Facebook React

Page 35: Huge web apps web expo 2013

este.demos.react.todoApp = este.react.create

render: ->

@div [

este.demos.react.todoList 'items': @state['items']

if @state['items'].length

@p "#{@state['items'].length} items."

@form 'onSubmit': @onFormSubmit, [

@input

'onChange': @onChange

'value': @state['text']

@button "Add ##{@state['items'].length + 1}"

]

]

Facebook React in Este.js

Page 36: Huge web apps web expo 2013

Angular/Ember vs. React<HTML> vs. code()

Page 37: Huge web apps web expo 2013

Angular/Ember vs. ReactDeclarative programming doesn't work. Sooner or later, all declarative languages ended up Turing-

complete, even HTML+CSS.

Page 38: Huge web apps web expo 2013

Separating your markup and logic, that’s not real separation of concerns. That’s separation of

technologies.

React Great Idea

Page 39: Huge web apps web expo 2013

Angular vs. Reactserver render ready*

SVG/VML/Canvas render readyWolfenstein render ready**

* no, Phantom.js is not a solution, it's hideous hack** www.petehunt.net/wolfenstein3D-react/wlf3d.html

Page 40: Huge web apps web expo 2013

React/Angular + Backbone separate model from view

Page 41: Huge web apps web expo 2013

Clean Code and Architecture

Page 42: Huge web apps web expo 2013

The Fewer Magic the Betterexplicit code over clever code

Page 43: Huge web apps web expo 2013

How to Structure App?By features. Always.

Page 44: Huge web apps web expo 2013

/controllers

/directives

/services

/filters

/views

/enumerations

/classes

/wtf's?

Wrong

Page 45: Huge web apps web expo 2013

/users

/products

/orders

/controller.js

/model.js

/collection.js

/process.js

/delegate.js

Good

Page 46: Huge web apps web expo 2013

Ensure you have a good style,good source code style.

JSHint, Coffeelint,Closure Lint (for code style nacist)

Page 47: Huge web apps web expo 2013

SOLID HomeworkSingle responsibility, Open-closed, Liskov substitution,

Interface segregation and Dependency inversion.

en.wikipedia.org/wiki/SOLID_(object-oriented_design)cleancoders.com

Page 48: Huge web apps web expo 2013

MVCman versus controller

Page 49: Huge web apps web expo 2013

Separated ModelAlways.

Page 50: Huge web apps web expo 2013

Componentization"The secret to building large apps is never build

large apps. Break your application into small pieces. Then, assemble those testable, bite-sized pieces

into your big application." Justin Meyer

Page 51: Huge web apps web expo 2013

Components or Views?

Page 52: Huge web apps web expo 2013

Dependency Injectionor as it's also known, passing arguments

Page 53: Huge web apps web expo 2013

Service Locatorcode coupling FML

Page 54: Huge web apps web expo 2013

How to test this?function fire() { Wolf.sound.play(); ...}

Page 55: Huge web apps web expo 2013

Is sound instance ready?function fire() { Wolf.sound.play(); ...}

Page 56: Huge web apps web expo 2013

Better.function fire() { this.sound.play(); ...}

Page 57: Huge web apps web expo 2013

Fine Service Locatorcode coupling FTW!

Page 58: Huge web apps web expo 2013

// side effects free

Math.abs x

// intentionally coupled code

new Coordinate x, y

// constants

Math.PI

Fine Service Locators

Page 59: Huge web apps web expo 2013

Angular developers can check Facebook now.

App Logic and App Wiring Separation

Page 60: Huge web apps web expo 2013

Good Infrastructurepackage management, module loader, source code

linter, task runner

Page 61: Huge web apps web expo 2013

Require.js, Bower, Component.io, Grunt.js, Browserify, ECMAScript 6 modules… etc.

Good Infrastructure

Page 62: Huge web apps web expo 2013

Unit TestsWhy and How.

Page 63: Huge web apps web expo 2013

Why to Write Unit Tests?If you don't know why, don't write them!

Page 64: Huge web apps web expo 2013

How to Structure Unit TestsArrange, Act, Assert.

Page 65: Huge web apps web expo 2013

Humansorry, no patterns for that

Page 66: Huge web apps web expo 2013

Except…Don't cheat and have fun.

Page 67: Huge web apps web expo 2013

Thank youdaniel.steigerwald.cz