Your Code is Not a Version: How 'Build for Disable' can bring you true continuous integration

Get Started. It's Free
or sign up with your email address
Your Code is Not a Version: How 'Build for Disable' can bring you true continuous integration by Mind Map: Your Code is Not a Version: How 'Build for Disable' can bring you true continuous integration

1. Presenter Info

1.1. Nicholas Tuck

1.1.1. Work at AFWA for AFWWEBS

1.2. This preso url:

1.3. Previous Brown Bags

1.3.1. TDD

1.3.2. Unit Testing

1.3.3. Pair Programming


1.5. twitter: @nicholastuck

1.6. Find me on G+ (not kidding) seriously...

2. The Goals

2.1. Be productive... every day

2.2. Stop fearing merging and start improving your product confidently

2.3. Thought Experiment

2.3.1. Stop thinking of your code as a version and Start thinking of your code as a living entity

3. The Room for Improvement

3.1. Feature Branch

3.1.1. aka Branch by Version Control

3.1.2. Each feature has it's own branch See Graph (1a)

3.1.3. This process can work but not productive Most features merged at the end This week != fun Requires the entire team Often relies heavily on the most knowledgeable team members Merge first != win Sometimes it feels good though Constant testing on branches have limited value Last minute integration adds bugs that were already fixed individually, but have been reintroduced due to merging complications and last minute testing We have to redo alot tests after integration points and all merges See Confidence Graph (1b) Duplicate Work See Duplicate Work Graph (1c) Ever fix the same thing as someone else? Daily pulls do NOT fix this Large Feature Problem Major feature missed code cut off

4. Simple Solution

4.1. Commit Constantly and Push Hourly

4.1.1. This is not just DVC - commit hourly. This is actually push to the public repo hourly. See CI Graph (2a)

4.1.2. Push When Exactly? - Worked on a feature for a few hours - Added tests around all the work - Push your code out to everyone else - Fixed a small bug - Only a handful of lines of code - Write the test - Push the code - Working a big feature that will take days, maybe weeks - Write a couple hours worth - Push it to everyone

4.1.3. Why This is Better When you push daily you merge daily No more nightmare merges Continuous Testing Constant integration means testing at any point is testing the entire state of the sprint Confidence is incredibly high at the end of a sprint Eliminates Duplicate Work We are literally at the latest changeset, we have all the work that exists We can actually start helping eachother Large Features Add Value Constantly Large features consist of lots of small improvements Every improvement makes it into the baseline as soon as as possible See Change/Time Graph (3)

4.1.4. Rules That Have to Change Taboos Never commit code that doesn't fully work Never commit commented code Rules to Re-enforce Don't break the build!!

5. Build for Disable Techniques

5.1. Code Example: OldMath vs NewMath

5.1.1. Original Code

5.1.2. Code can be found on my Bit Bucket

5.2. Simple if check with a static boolean

5.2.1. Code example

5.3. Add a method for the alternative approach and static boolean

5.3.1. Code Example Tests

5.3.2. Writing tests could be challenging as you enable and disable Make this boolean protected and set it for pertinent tests When deleting old math, remove corresponding tests

5.4. Extend the class and override the methods you want to change. Point the app config at the new class, and to disable point to old class

5.4.1. Code example

5.4.2. This keeps tests separated from the other tests

5.4.3. When deleting Old Math copy the old tests into new test class and walk all failing tests Ideally it will be deleting old/changed functionality Maybe you broke something unintended

5.5. Actually USE interfaces!!

5.5.1. Decorator Pattern (sorta) Code example Old Math Imp Tests and Class can stay in place if desired, doesn't require being merged later Sometimes this is a good design, sometimes not

5.6. Leads to better coding practices in general

5.6.1. Sometimes you find out, this is better architectually and that functionality shouldn't be mixed in where it was

5.6.2. Writing code in separate and distinct groups is easier to test, easier to maintain

5.7. BONUS

5.7.1. Comment It Out Hide Buttons // showAwesomeFeatureButton(); Disable Web Service // @RequestMapping(value = "/export", method = { RequestMethod.POST }) public ... Short Circuit new functionality // satellite.maskUglyAreas(THE_NO_KIDDING_THRESHOLD);

6. Why Isn't Everyone Doing This? Introducing 'Build for Disable'

6.1. Few teams are implementing true continuous integration because we believe our code exists in versions

6.1.1. We believe we are working to deliver an idealized version of our code to production Implied (ABC) versions in Graph 1 This version of code is on a pedestal Only 100% done code is comitted Only Code that works without bugs is committed (yah right) All features undone are in a different version It's like the superhero of all code versions We try to have the public repo represent perfect versions of the code This gives us warm fuzzies Why We Do This We tend to develop processes around our tools Our single mitigation on how not to ship a product with half working features or buggy features

6.2. The Solution

6.2.1. Your Code is NOT a Version! Your code IS a living entity It is always It's being fed while you push code It's being exercised under test It's being relieved during refactoring It is basically alive Stop looking back at what might be a stable version Spend more time looking ahead and creating the product we want to ship (Bad) Car Analogy

6.2.2. Introducing 'Build for Disable' aka Branch by Abstraction (VS Branch by Source Control) (Similar to Feature Toggle) What is it? Build significant changes so that they can be trivially disabled When producing the product for a release We don't fall back An example for comparison Show Failed Feature Graph (1e) Show Failed Feature Graph (2d)

7. In closing

7.1. Your code as a version

7.1.1. See Graphs (1) Versioned progress Low confidence Feature pulling fiasco

7.2. Your code alive

7.2.1. See Graphs (2) Steady progress Consistent confidence Disabling mechanisms

7.3. Review Goals

8. Questions?

8.1. How do you manage peer reviews with everyone's code mixed together

8.1.1. Fisheye and Mercurial do a pretty good job

8.1.2. Spend 5 minutes to cleanup your peer review for others

8.1.3. Peer reviewing other's code isn't bad but sometimes it's undone

8.2. Does this only work if there exists a good automated test suite on the project?

8.2.1. No, it helps even more This means most of your testing is done manually Merging at the end means repeating all manual efforts and re-troubleshoot very difficult problems while merging Merging along the way means any manual tests are done across that integration Gaining more confidence and more manual test coverage throughout the iteration

8.3. When do we remove the extra and disable code?

8.3.1. When it makes sense Once the team accepts the code and is ready to make the feature production Once the risks of the feature are overcome Once everyone feels comfortable with the burn in time Basically when your team is ready

8.4. When do we peer review the code? Before disable code is removed or after?

8.4.1. Both You will want a full review of the code before disable code has been removed so that the team can agree to move forward with the code Then you will need a very quick/easy follow up review of removing the disable code and the extra tests