Ruby codebases in an entropic universe
Upcoming SlideShare
Loading in...5
×
 

Ruby codebases in an entropic universe

on

  • 1,909 views

How to manage entropy on Ruby codebase or, how not to kill a Ruby project in eighteen months

How to manage entropy on Ruby codebase or, how not to kill a Ruby project in eighteen months

Statistics

Views

Total Views
1,909
Views on SlideShare
1,876
Embed Views
33

Actions

Likes
6
Downloads
6
Comments
1

6 Embeds 33

http://lanyrd.com 24
http://speakerrate.com 3
http://www.slideshare.net 2
http://www.linkedin.com 2
http://www.lmodules.com 1
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • intro <br />
  • intro <br />
  • <br />
  • <br />
  • intro <br />
  • quality and entropy are the two themes underlying our talk. <br />
  • Quality <br />
  • <br />
  • how would you measure the value of a codebase? $ revenue generated? Time saved? LoC? None of these have a baseline against which you can measure success or failure <br />
  • how would you measure the value of a codebase? $ revenue generated? Time saved? LoC? None of these have a baseline against which you can measure success or failure <br />
  • The need to adapt software to changing realities is what drives feature requests. The quality of a static codebase doesn&#x2019;t matter as long as it *works* <br />
  • So... some part of code quality is encapsulation <br />
  • is the code factored in a manner which allows tuning parts of it without affecting other parts <br />
  • Which is encapsulation again <br />
  • So what exactly *is* encapsulation <br />
  • This is what we&#x2019;ve been taught in college <br />
  • <br />
  • David Parnas&#x2019; paper <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • This is a controller action. This is also really, really bad code. Is this familiar? <br />
  • Which brings us to entropy <br />
  • This is a controller action. This is also really, really bad code. Is this familiar? <br />
  • As you work on a codebase the complexity of the code always increases and quality decreases. The difference is that unlike Physics, entropy increase isn&#x2019;t constant - but more on that later, so hold your thoughts. <br />
  • Let&#x2019;s walk through this code quickly and see what&#x2019;s the problem. We aren&#x2019;t talking about fixing it - but just looking to understand the problems that exist. <br />
  • Step 1 when dealing with ANY code - specs. <br />
  • Ok, that&#x2019;s good. <br />
  • Coverage is good. It means we have *some* kind of safety net. How good that safety net actually is depends on how the specs were written, but lets defer looking into that for a bit. <br />
  • This is a controller action. This is also really, really bad code. Is this familiar? <br />
  • any method that has more handful of lines, or deals with more than a single concept is big. A one page method is an abomination. <br />
  • This is a controller action. This is also really, really bad code. Is this familiar? <br />
  • any method that has more handful of lines, or deals with more than a single concept is big. A one page method is an abomination. <br />
  • This is a controller action. This is also really, really bad code. Is this familiar? <br />
  • any method that has more handful of lines, or deals with more than a single concept is big. A one page method is an abomination. <br />
  • Clearly this isn&#x2019;t a good idea. And the people who wrote this would agree with me, and it was never their intention to get to this point. But they did, somehow, one if statement at a time and they started living with broken windows. That said, this could happen anywhere, in any language, right? Lets look at some Ruby specific fun and games involving the... <br />
  • The Ruby programmer that starts to understand metaprogramming is like a Jedi apprentice with a lightsaber. Power without wisdom/experience. It appears that all problems are easily solved using a few quick slashes and hacks. For example... <br />
  • Read the comment at the top of the page if you will. &#x201C;This method is regenerated at runtime based on what the prefix is set to.&#x201D; Uh, huh. And that&#x2019;s a good idea how? <br /> <br />
  • <br />
  • The metaprogramming lightsaber is fun, but sometime... ***? Like seriously, ***? <br />
  • <br />
  • <br />
  • well, that&#x2019;s a mechanic right there - the principle is that you need to wait until you have the judgement to apply the right tool for the job <br />
  • Clearly, these are bad ideas. They might have seemed like good ideas to begin with, solving the problem quickly with a hiss and a sizzle. Even though they do solve the problem, they don&#x2019;t do so in a manner that is well encapsulated, easy to spec and easy to understand. Over time, they act as points where cruft starts to accumulate. <br />
  • eventually, you&#x2019;re like the boiling frog. you did one little thing which wasn&#x2019;t &#x2018;clean&#x2019; as a quick hack, and then two months later you realise someone else saw it, though it was a good idea and replicated it everywhere. eventually you get <br />
  • which, in a nutshell, is entropy on a codebase. After a while you can&#x2019;t make any change without tripping over something (or someone). <br />
  • entropy is a complex engineering problem <br />
  • this is why Ruby codebases need more care and love than most other codebases <br />
  • <br />
  • You need to know when, where and how to use the lightsaber <br />
  • <br />
  • The point is... (next slide) <br />
  • basically... <br />
  • <br />
  • Step 1. Specs. <br />
  • <br />
  • preferably one that doesn&#x2019;t take too much time <br />
  • <br />
  • <br />
  • Back to step 1. Specs. <br />
  • no, seriously. we can&#x2019;t emphasise this enough. with something as flexible as Ruby, you need specs. <br />
  • <br />
  • Back to step 1. Specs. <br />
  • <br />
  • As entropy on any code base always increases, it is essential to keep an eye on trends, and refactor/redesign every once in a while to make sure that it doesn&#x2019;t go out of control <br />
  • to make sure it doesn&#x2019;t deteriorate like this <br />
  • the trends you should watch <br />
  • the trends you can quantify <br />
  • the trends you should watch <br />
  • the trends you should watch <br />
  • the trends you should watch <br />
  • the trends you should watch <br />
  • reek <br />
  • <br />
  • <br />
  • <br />
  • how long does it take a new person to get productive on your codebase <br />
  • <br />
  • which means the same entity does more <br />
  • <br />
  • <br />
  • <br />
  • first, you need a build <br />
  • first, you need a build <br />
  • <br />
  • <br />
  • bad specs, poor coverage <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • Using a hash <br />
  • <br />
  • <br />

Ruby codebases in an entropic universe Ruby codebases in an entropic universe Presentation Transcript

  • ruby codebases in an entropic universe or, how not to kill a Ruby project in eighteen months
  • niranjan paranjape
  • mechanical engineer. one rube goldberg machine. lots of ruby code.
  • http://github.com/niranjan http://twitter.com/niranjan_p
  • sidu ponnappa
  • programmer. bibliophile. failed entrepreneur.
  • http://github.com/kaiwren http://twitter.com/ponnappa
  • quality / entropy
  • quality
  • quality is valuable
  • quality is hard to measure it’s effects are also hard to measure
  • (especially in software)
  • flexibility
  • encapsulation
  • scalability
  • encapsulation
  • encapsulation?
  • grouping related data and behaviour. also, data hiding.
  • not really
  • the principle of segregation of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from extensive modification if the design decision is changed.
  • so... encapsulation is a means of limiting the effects change
  • conversely in a system that does what is needed, and, if what we need never changes, we don’t care about encapsulation
  • so, what’s the problem with change?
  • eventually, it comes to this:
  • entropy
  • codebases have entropy given enough time, the entropy of a codebase increases to a point where changes become impossible
  • analysis
  • 1
  • ok, it’s covered let’s get back to the analysis
  • quick analysis • this method is HUGE (smell!)
  • quick analysis • this method is HUGE (smell!) • multiple branches (obscene number, actually)
  • quick analysis • this method is HUGE (smell!) • multiple branches (obscene number, actually) • multiple exit points
  • boiling frog once upon a time a domain rule wound up in a controller over time controller became the place to put domain rules
  • the metaprogramming lightsaber
  • another example
  • basically
  • metaprogramming...
  • don’t
  • other fun examples • overriding responds_to? on Object • un-defing id on Object (thanks Brian!) • editing boot.rb in your Rails project • using instance_variable_get anywhere
  • bad ideas attract other bad ideas
  • entropy
  • complex engineering problem
  • made worse by... the lightsaber in ruby
  • lightsabers require discipline
  • lightsabers require precision
  • http://www.thetoque.com/images/stories/lightsaber.jpg
  • yeah, like that anyways...
  • ruby projects require more care
  • solutions?
  • 1
  • specs
  • everything begins with a safety net
  • they describe how the next developer (including yourself) should consume your code.
  • they are specifications. a spec doesn't prove anything, but it does tell you that for one very particular scenario, your code probably works.
  • 2
  • specs
  • they are the only confidence you, as a developer, should have in your code. whether it's an acceptance test script written by a QA (manual or automated) or the world's tiniest spec, this is your starting point. without specs, the only assumption you can reasonably make about your code is that it doesn't work.
  • 3
  • observe trends
  • trends to watch
  • quantifiable
  • code coverage
  • cyclometric complexity
  • file size
  • spec file size
  • call duplications
  • churn
  • class reopen count
  • performance
  • environment setup time
  • unquantifiable
  • public API methods stay the same, but the specs increase
  • modules without a contract
  • number of entities that need setup for one spec
  • how?
  • ci builds (ratcheted?)
  • metrics
  • specific issues
  • bad code
  • specs
  • DRYing prematurely
  • poor modelling
  • team dynamics
  • stick to idiomatic code conventions
  • but know when to deviate
  • too many conventions in a codebase
  • principles vs. mechanics