Skip to content

Instantly share code, notes, and snippets.

@NathanielWroblewski
Last active August 29, 2015 14:10
Show Gist options
  • Save NathanielWroblewski/d5556d02b2685d33b732 to your computer and use it in GitHub Desktop.
Save NathanielWroblewski/d5556d02b2685d33b732 to your computer and use it in GitHub Desktop.
Pocket Mice Notes

Notes on Backbone and Everything Else

Backbone

Todo app

I've included a link to a simple Todo application built in backbone with a detailed commit history. I would recommend going through the repo from the first commit to the last. It should be clear what is going on, and if not, I'll happily answer any questions. Repository History

I will include a screenflow later.

Backbone Notes

Server-side MVC Client-side MVC
Model Model
View Template
Controller View
Router Controller (Router)

Typical Backbone Story

  • User visits a hash url
    • The router instantiates the correct 'views' and models
  • User interacts with the template
    • The 'view' listens for the interaction and updates the model
  • The model is updated
    • The view listens to the model for changes, and re-renders

Client-side MVC Heirarchy

Router -> Views -> Models

  • Routers can know about Views and Models
  • Views can know about models, collections of models
  • Models should not know about anything else
  • Views should not know about Routers

Workflow Process

  1. Identify problem and define how to measure success
  2. Brainstorm on solutions
  • look for open source solutions
  • look for proprietary solutions
  • consider rolling your own
  1. Appraise the solutions
  • What is the estimated time investment?
  • What are the hidden costs?
  • Is the project actively maintained?
  • Are there open issues that could be problematic?
  • Is the project immature? (< version 1.0)
  • What is the amount of complexity?
  • Is this the right tool for the job?
  • Simple vs easy
  • Does this work well with our current systems?
  • What is the future maintenance cost?
  1. Build or automate
  2. Measure success
  • Include analytics in the code
  • Every user interaction is an opportunity to learn and improve, track it
  • Segment.io, Mixpanel, KISSmetrics, Keen.io, etc
  1. Iterate
  • A/B test improvements
  • Optimize.ly

Build Workflow

  • Start a story in Pivotal Tracker
  • Behavior Driven Development (BDD)
    • write a capybara spec if the feature merits one
    • consider the tradeoff of test coverage and test suite run time
  • Drill down during building to Test Driven Development (TDD), i.e. unit tests, etc
  • Push your finished code up to a branch for code review
  • Finish your story in Pivotal Tracker
  • Merge after review using a production git workflow
  • Push code to staging, a replica of your production environment for testing
  • Use continuous integration to prevent broken code from being deployed
  • Manually inspect and test your feature on staging
  • Push to production

Git Workflow

  1. git fetch
  2. git rebase origin/master
  3. git checkout master
  4. git merge my-branch --ff-only

Create Checklists for Every Feature

  1. Am I aware of why I'm building this feature?
  2. Do I understand how to measure success of this feature?
  3. Am I measuring success?
  4. Does this feature merit an integration test?
  5. If I'm touching a model, have I written unit tests? Can I pull anything out into a module?
  6. If I'm touching a view, am I feature flagging the feature? Am I caching it? If already cached, am I sure the cache will be invalidated properly?
  7. If I'm touching a mailer, do I have a preview? Have I written tests?
  8. Am I introducing a validation? Will this break existing data?
  9. Have I considered all the sad paths?
  10. Am I altering url structure? Could I be breaking existing links?
  11. Have I refactored this code before submitting a pull request?
  12. Does this page need to render when offline?
  13. If I'm touching a migration, am I keeping models out of the migration? Am I considering null/default values? Does it require an index? Can I rollback safely?
  14. If I'm removing code, have I removed all references of it?
  15. If I'm exposing a route, can the user hack it? Is it RESTful? Is it an API? Can I make it one?
  16. If I'm nesting routes, can I implement the same functionality using unnested resources and query-string params?
  17. Have I hardcoded any constants that are likely to change?
  18. Am I anticipating likely changes in requirements?
  19. Are my API keys hidden? Is this feature secure?

Miscellaneous

  • Vim, for faster editing, macros, etc
  • HAML, coffeescript, etc. for writing less code and more readable code
  • Parallelize your test suite
  • Use continuous integration like CodeShip.io or CircleCI
  • Use a rails pre-loader like Spring or Zeus
  • Automatically run the appropriate specs anytime a file is changed with guard-rspec
  • Keep tests fast by not loading the entire rails environment, i.e. require 'spec_helper'
  • automate your routines with bash scripts
  • write performance tests if you can afford to
  • bundle update frequently
  • get on PagerDuty
  • cache every line of rails template
  • profile your app with new relic
  • run things in background jobs
  • test your webpage for single points of failure
  • asynchronously load content where possible
  • check code quality with CodeClimate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment