• Maintenance development - freestyle

    How do you get started doing effective maintenance development? This topic is near and dear to me, as I’ve spent most of my career writing new functionality, but also to a large degree getting good at cleaning up and extending code written by others. There are some knacks to doing it well, and I’m in the process of writing write a practical guide to help you learn it faster.

    Style guides are topic with the potential for endless discussion. The ruby community has some good ones, and you are of course free to write your very own as well. One thing you will typically find taking over a project that has lived for a while, maybe with multiple maintainers, is inconsistent code styles. This is obviously not the end of the world, but it can sidetrack you when trying to reason about the current behavior of a piece of non-obvious code.

    Fortunately it is easy these days to setup rubocop and ensure a consistent style is used. It is even partially possible to automatically clean up most of it to conform. Consistent hash style, yay.

    Some large codebases are a beautiful and valuable mess. They often have a large gap between the current state and an ideal state of syntax consistency and well-managed complexity. All is fortunately not lost, The Rewrite is typically not the answer. Instead, a processes is needed to break things down and attacking the problem in smaller chunks over a period of time, without halting all other progress. It is such a process I’m describing in the guide.

    I’ll be happy to notify you when the guide Effective Maintenance: taming messy code (Ruby edition) is ready - simply enter your email in the box below, and I’ll keep you informed.

  • Upgrading ruby hash syntax

    Consistency makes code easier to read. Long-lived projects can be a wildly inconsistent in their ruby hash syntax, so here is a quick way of upgrading all symbol-based hash-keys to the new leaner format. Simply put: perform the below operation to convert :thing => 'value' to thing: 'value' in one easy step.

    Please remember to commit everything first so you have a clean slate to start out from, and undo is easy.

    In Sublime Text, open Find | Find in Files... and enter:

    Search:   ([^:]):([^:\s=]+)\b\s*=>\s*
    Replace:  \1\2:

    Ensure the Regular Expression mode is active (the button looks like: .*). Now is a good time to use the File | Save All action.

    Remember to double-check everything looks just right. I recommend using git add --patch . for this, because that way you can easily skip any changes you might not agree with.

    This is just a minor detail in the overall readability and consistency of a project, but even minor details matter when it comes to long-term ease of maintainance.

    Update 2015: Rubocop can easily fix this minor issue and also automatically fix quite a few other inconsistencies. Highly recommended.

subscribe via RSS