2011/11/14

The art of refuctoring

I recently saw @jasongorman present at JaxLondon on refuctoring. Unlike refactoring you try and reduce the readability of code to make you indispensable to your employer.


Here are my top ten 'refuctorings' in no particular order:



  1. Prefix all class names with the name of your employer and at least one TLA.

  2. Include @note comments in your file stating that the code must be thread safe. Then implement it in a way that is unsafe for multi threaded use.

  3. Prefix all member variables with either m_, s_ or p_, try your best not to follow the convention for their meanings i.e. use s_ (static) on non static private member variables.

  4. Make sure that you inherit all of your member variables from a parent class.

  5. Use bit level logic as much as you can, especially in application high level application code.

  6. Only write a comment if it is misleading: Include jokes like 'this method could blow our memory' to make the caller think twice before using it.

  7. Copy and paste public static methods between classes, take the time to rename them, reformat the layout and generally make it hard for static analysis to realise it is the same code.

  8. Avoid using brackets on if statements, just indent code after the first line to make it look like it is part of the if block.

  9. Optimise your code by manually in-lining supporting methods to increase the size of your code. Don't forget to take the time to change the variable names and layout.

  10. All methods should be at least 500 lines with fully expanded if statements nested as deeply as possible. If you have some if statements in your pre-amble of a method why not repeat those tests throughout the code.


The most important thing to remember is that you need a really good unit test suite so that you can make all of these changes, safe in the knowledge that you have not broken the code.


The idea of the exercise is to try and make you think of ways that you could make code worse without breaking it. It is amazing how many anti patterns you can come up with as part of this exercise. I can highly recommend the session with Jason.


For more information on the courses Jason offers see his website Codemanship

2011/10/12

Open source accessibility testing library

Website testing and accessibility have been interests of mine for a while and over the last couple of months I have been supporting the web accessibility testing project: I helped develop a core rule set of automate-able accessibility issues based on the WCAG standards and Open-Ajax in Java.

One of the key criteria for the library was for it to be used in a number of different environments like WebDriver based automated tests to inspect dynamic page content or static analysis of crawled pages running inside a map reduce job.

If you're interested in getting involved or using the library please contact us via the project page.

2011/10/06

Back at the yoke

Last weekend I finally got around to taking a flying lesson that I was given for my birthday last year. It was actually Friday and I think everyone in the south of England was thinking about being outside. It was a very good day for the time of year: I think the next day set a new record high temperature.


I haven't flown for a while so was pretty excited. The flight took us south east over the Thames estuary. The visibility was great and the feeling of being back in the air was awesome. I have always thought flying was as close as you can get to a state of divinity.


It didn't take me long to remember my turning skills, the glider lessons really helped. In no time at all I was pushing further over, going for the 60° turn which is 2G. I was having way too much fun to take pictures unfortunately so these few are all I managed.


In such a small plane the turbulence was quite noticeable but meant I had to learn to let go of the controls and let the plane find it's way.

The school was really helpful at giving me all the information I need to understand what's next: the sky's the limit

2011/10/02

Learning to turn with the California Superbike School

A couple of weeks ago I took a training course with the California Superbike School. Before arriving I had some apprehensions but they were quickly dismissed.

The level 1 course which I took covered throttle control, turn in points, fast turning rider input and riding lines. I have to admit that before the course I thought my riding was pretty good but during the interaction with my coach 'Hollywood' I was able to unlock a totally different level of riding. The overall effect was that I was more controlled and confident mid corner; the changes in turn in speed and turn in point also made a huge difference by increasing my confidence in the bike's ability to turn in fast.

I would seriously recommend the course to anyone who like me lives in the saddle. I haven't had any track time before but I think that might also be about to change.