Talk Spotlight: Brandon Keepers
Why Our Code Smells - Brandon Keepers - RuLu 2012 I'm going cover my main take aways from his talk. I recommend watching the full presentation if you have a moment. Code Smells: Indication that something is wrong deep in the system. If your application experiences divergent change, when one class is changed in different ways for different reasons a smell can occur. The first step is identifying the problem. Change the class or methods causing the issue and consider refactoring them into a new separate entity, may it be a method or class. Test driven development is a design process that provided immediate feedback on our logic and quality of code. It could be the only thing saving you from falling down the rabbit hole. Benefits: 1. Guards against regressions (so it stops breaking) 2. Gives you the confidence to make changes 3. Encourages good design, by having to be clearer and more flexible to work with your tests Try not to fall in love with a test success. If a test succeeded but was difficult to implement it begs questions. Why was the test hard to structure? Is it testing for too much, or is the application trying to be too many things? Perhaps its time for a good ol' refactoring. Comments can be helpful. As an experiment, above the start of a class or function describe the Responsibility and Dependencies. By explicitly stating the Responsibility we can immediately see if its following the Single Responsibility Principle. Stating the Dependencies helps future developers manage the code. If unit tests are slow there is likely something wrong with the design. Causes: 1. Databases can slow down tests 2. Not testing an object in isolation - testing the whole unit takes time - try testing one thing at a time 3. Slow when bootstrapping heavy frameworks - this can happen when you're loading every gem ever along with rails... Slow Test Myths: 1. Too many tests! - Then create better focused tests 2. We need to parallelize tests - Perhaps, but try reviewing the application's design first 3. Lost confidence of stubs in tests (stubs mimic data) - stubs are good for isolated tests - keep our tests focused and quick









