The Holy Java

Building the right thing, building it right, fast

Archive for February, 2015

The Are No Silver Bullets: Which Error Handling Style to Pick For a Given Configuration of Constraints?

Posted by Jakub Holý on February 18, 2015

Kent Beck in his Patterns Enhance Craft Step 3: A Few Good Solutions highlights an important fact about software development:

We encounter repeating configurations of forces/constraints that have only a handful of “solution families” and the optimal solution(s) depend on the relative weights of these constraints.

For example when deciding what error handling style we should choose when calling an unreliable rutine:

Depending on whether readability, reliability, automated analysis, performance, or future maintenance are most important you could reasonably choose any one of:

  • Exceptions
  • Return value plus errno
  • Exceptional value (e.g. Haskell’s Maybe)
  • Success and failure callbacks

So there is no single perfect error handling style to rule them all.

Kent further explains that the forces shaping most design decisions are generated internal to the process of design, not by external constraints: whether we’re building a barn or an airport, the list of forces influencing the roofing decision is the same – snow, wind, etc. – but their relative strengths may be different. Internal forces in SW development include use of the same bits of logic repeatedly, code made for/by people, etc.. F.ex. the forces influencing naming a variable do not depend on what SW we are building but on its purpose, lifetime, etc. We encounter some configurations of these constraints again and again and a catalogue of design patterns representing the “solution families” mentioned above can guide us towards the most suitable solution for given weights.

Conclusion

When designing a solution, it is helpful to think in terms of these forces and their relative strengths. There is no single superior solution (a.k.a. silver bullet) as different configurations of forces and their weights might be best suited by radically different solutions. Keeping this on our minds might prevent design discussions from dengenerating into an argument.

Posted in SW development | Tagged: , | Comments Off on The Are No Silver Bullets: Which Error Handling Style to Pick For a Given Configuration of Constraints?

Fix Shell Script Run via SSH Hanging (Jenkins)

Posted by Jakub Holý on February 17, 2015

There is an important difference between running a script manually (ssh machine; machine$ ./script.sh) and running it via ssh (ssh machine < script.sh): in the letter case the connection will not close when the script finishes but will stay open until stdout/stderr are closed or a timeout occurs. In Jenkins it will therefore seem as if the script hangs.

So if your shell scripts starts any background job, make sure to redirect all its output to somewhere:

nohup some-background-task &> /dev/null   # No space between & and > !

This has bitten me when trying to deploy an application from the Jenkins CI using SSH and a shell script.

References: http://www.snailbook.com/faq/background-jobs.auto.html

Posted in Uncategorized | Comments Off on Fix Shell Script Run via SSH Hanging (Jenkins)