Wednesday 21 December 2011

Passing of Time

In 2005 David Martineau drew the iNMR palette.
In 2011 Pascal Fricke has drawn it again.

Saturday 10 December 2011

Screenshot Bonanza-thon!

As promised, a mountain of new Apple Jack 2 screens await your eyes below. I've added a bit of text beneath each one to explain them, since if you haven't played the first game they might be a bit confusing:

 



This level is called 'The Panda Factory'. Apple Jack stumbles across a perpetual motion machine where pandas fall on to and then are nudged off of a series of moving platforms. He must DESTROY THEM ALL to progress.






RUN! AJ has to run like heck away from this massive panda.






The game includes a combo system - destroy enemies in quick succesion to multiply the amount of fruit they drop. Things can quickly get out of hand, as you can see.






The Pain Turbine - The huge saw blade relentlessly forces our hero to circle this small level, picking off enemies as he goes.




Bit of a boring screen, this one, but it shows that you can push large blocks around, even if enemies are walking around on them.






Coloured enemies can only be destroyed by picking up and throwing like-colours at each other. Otherwise they bounce off harmlessly.





These eyeballs are trapped at the moment and can only watch as AJ passes beneath. Later in the level they will be released and will seek a terrible vengence.





Unlike the first game, this one has boss fights.



 More combo madness.





 This level wobbles around, threatening to crush the player.





 Fatal Frame - AJ is forced through this level inside a moving chequered frame of death.




Friday 2 December 2011

Update!

Since last I wrote, I've done a lot of boring but nesessary stuff to the game, such as menus, particle effects, a new HUD and other bits and bobs. Expect it early next year. I'll post some more screenshots before long too.

Also, I've followed the advice of Neil the intro guy and the chap in the comments below, among others, and properly started a My Owl Twitter account. If you're into that sort of thing you can find it at:

http://twitter.com/#!/MyOwlSoftware

Monday 14 November 2011

Drawdle Reviewed in Germany

Drawdle has earned a couple of positive reviews in Germany over the past weekend, courtesy of AndroidPIT.de and Nikonierer.de (Danke Jungs!). Check them out:

AndroidPIT

Nikonierer

Spinach


A picture can be worth a thousands words. You can find many interesting and self-explanatory pictures here:
http://spindynamics.org/Spinach-examples.php
In a nutshell: Spinach is not a program, but an open source library; it's something for programmers, not for end users. The language is, once again, Matlab. When the language is Matlab, usually that the programmer and the end user are the same person.
The purpose of Spinach is, once again, to simulate NMR experiments and spectra, of all kinds. With this latest arrival, I am even more convinced that the vast majority of NMR software belongs to the class of simulation software. The mole of published material (in the sense that you can find an article in literature) is inversely proportional to the number of users. It is a fascinating field nonetheless. You can freely download Spinach and read it. Installing it is a different story.

Thursday 27 October 2011

Mentorship in Software Craftsmanship - part 3

In previous posts I covered:
Part 1: Mentor and mentee roles, gains and sacrifices, mutual respect
Part 2: How to choose mentors and mentees and mentorship misconceptions



Walking the long road together (or at least part of it)

Once the relationship between mentor and mentee is established, it is fair to say that they will be in a journey together. Every software craftsman is on a personal journey towards mastery. They are all walking the long road. Both mentor and mentees will be learning while they share part of their journey with each other.

What mentors and mentees should do during the mentorship?

Well, this may vary a lot depending of the type of mentorship. In general, they are expected to write code, loads of code. Ideally they should build something together, where the mentee should be the most active in terms of writing the code. The mentor is expected to pair-program with the mentee whenever possible and to be reviewing his code.

Agreeing on creating an application would probably be the best option since that would involve not just writing the code but also thinking about requirements, being able to prioritize, defining a development process, deployment strategies, production environment and everything else that is related to a software project in the real life.

Working on katas is also a valid. It's a simpler and quicker approach for the mentee to learn basic skills. This could be used when the mentees are interested in the basics of TDD, naming, refactoring, programming languages paradigms, etc. However, after learning a few basic skills using katas, they should aim to do something larger that really can mimic the sort of applications they would be working on in their professional environments.

Establishing goals and tracking progress

Establishing goals is definitely a good practice in a mentorship. It keeps mentor and mentees focused in whatever they want to achieve. Working towards an objective is always the best way to study and learn something. Goals should be achievable and used to motivate and direct the menteed and not to be treated as a hard deadline. However, they should be as concrete as they can be, for example, writing an application with features X, Yand Z and have it deployed into production or doing a number of katas using TDD, write blog posts, read books, submit patches to open source projects, or whatever the pair agrees on.

It's important that progress is tracked so both mentor and mentees can see how they are getting on and how much the mentee is evolving. Tracking progress is all about feedback. The quicker and shorter the feedback loop is, the better. It's also a good tool to trigger conversation about improvements and refinements.

How long a mentorship should last?

Unfortunately that's another question that does not have an exact answer. This will depend a lot on the type of mentorship, how much the mentee wants to learn from the mentor and also how much the mentor has to offer.

Some say that this should be a lifetime commitment, some say that it should last between 2 to 5 years and some say that it could be as short as a few months. Some mentorships start with very technical and specific things like learning the basics of a language or test disciplines. However they can evolve to an entire project lifecycle or even to a longer term career advice, networking, help with books and conferences, etc.

I, personally, would never try to define that upfront. Just enjoy the journey and let time tell when the mentorship should terminate.

How and when does it terminate?

For the majority of the relationships, both mentor and mentees at some point need to continue their journey in separate ways. This does not mean that they will never talk to each other again or that they don't like each other. This just means that they need to move on, teach or learn from other people. Also, we all change our minds in terms of what our next steps would be and we need to react to that.

One important thing is that regardless who wants to terminate the relationship, this termination should be explicit. It should be clear to both parts that the mentorship is over.

Professionalism, Reputation and Public recognition

Software craftsmanship is all about professionalism and it is almost impossible to talk about professionalism without talking about reputation.

Throughout the mentorship, it is important that the mentor advertises the progress of her mentee. Mentors should public recognise all the skills acquired by the mentee, what would help the mentee to start building her own reputation. However, mentors also need to be aware that every time they vouch for someone, they are also putting their reputations on the line. Mentees are also expected to be recognising their mentors for all the things they've been learning. This mutual recognition is one of the things that may help both to build their reputations.

Raising the bar

Mentorship is at the heart of software craftsmanship and this is probably one of the most efficient ways for us, developers, to help raising the bar of our industry. Sharing our knowledge and experiences with each other is what will help us learn from our mistakes and successes.

We probably can teach many things to someone in a fraction of the time that took us to learn them. With this, mentees could absorb a lot of knowledge in a much shorter space of time, making them, overtime, a much more complete professional than any of the mentors she had in her career.

Regardless of our level of seniority or if we are being mentored by someone else, if we all take the responsibility to mentor someone, we will all be helping to raise the bar of our industry.


For previous parts of this blog post, please check:

Part 1: Mentor and mentee roles, gains and sacrifices, mutual respect
Part 2: How to choose mentors and mentees and mentorship misconceptions

Saturday 22 October 2011

Installing Io language on Ubuntu

Since I'm new to Ubuntu and I had a hard time installing Io language, I've decided to record my steps. Hopefully I'll remember all of them and other people won't struggle as much as I did. I'm running Ubuntu 11.10.

The main problem I had was that I did not have all the dependencies needed to install Io and the installation was failing. The dependencies are yajl and libevent

If you've got then installed, you can skip the next steps.

NOTE: You will need to have cmake and make. You can install them running the following commands from the terminal:
sudo apt-get install cmake
sudo apt-get install make

Installing yajl

  1. Download yajl from here: https://github.com/lloyd/yajl/downloads
    1. In my case it was: lloyd-yajl-2.0.1-0-gf4b2b1a.zip
  2. Extract it into a folder.
  3. Open the terminal and go to the folder you extracted yajl
  4. Run the following commands
    1. mkdir build
    2. cd build
    3. cmake ..
    4. sudo make install

For more information, please check:
https://github.com/lloyd/yajl
https://github.com/lloyd/yajl/blob/master/BUILDING

Installing libevent

  1. Download libevent from here: http://libevent.org/
    1. In my case it was: libevent-2.0.15-stable.tar.gz
  2. Extract it into a folder
  3. Open the terminal and go to the folder you extracted libevent
  4. Run the following commands
    1. ./configure
    2. make
    3. sudo make install

For more information please check:
http://libevent.org/
Also check the README file inside the .tar.gz for your version

Installing Io language

You can go to the Io language website and download the language or click here to go start downloading it. As there is no Ubuntu package for that, you will be downloading the Io's source code. This will point to Steve Dekorte's version. I ended up downloading Jeremy Tregunna's version. It should work the same. Check each one is the most up-to-date.

  1. Download the Io version here: https://github.com/jeremytregunna/io/zipball/master
  2. Extract it into a folder.
  3. Open the terminal and go to the folder you extracted Io
  4. Run the following commands:
    1. mkdir build
    2. cd build
    3. cmake ..
    4. sudo make install

IMPORTANT: When running 'cmake ..', you may get a few errors. Even then, try to run 'sudo make install'. Some libraries may fail to compile because they are OS specific.

For mode information please check:
http://iolanguage.com/
https://github.com/stevedekorte/io
https://github.com/jeremytregunna/io


Updating ld.so.conf

Now we just need to update ld.so.conf so Io can be accessed from anywhere in your computer.

  1. From the terminal, type the following command: sudo gedit /etc/ld.so.conf
  2. Add the following line to the file: include /usr/local/lib
  3. Save and close the file
  4. From the terminal run the following command: sudo ldconfig

Running Io

That's it. Hopefully now you will be able to open a terminal window and type: io
You should see the Io runtime environment: Io> _

Wednesday 19 October 2011

Attention!

I have finally finished designing all the levels! There are 61 in total (so I can cleverly put 'over 60' in the item description), including three boss encounters.

Now that's all done I can finally get around to redrawing some of the blocks, getting the checkpointing fixed and the other million things that have to be done before I can release the game, probably in the space year 2025.

Sunday 16 October 2011

Drawdle on Appscribe, full game price reduced to $0.99

Been taking some time away from game development while I think of new products for One Side Software, but here are couple of updates:

- The full version of Drawdle is now a part of Appscribe, a new app-rental service. Check it out.

- If you'd rather own a copy of Drawdle it is now only 99 cents on the Android Market.

Wednesday 12 October 2011

The new game should have been finished and released by now, but I've still got a couple of levels to finish, and god knows how much stuff to do after that. Given that the game is built on a modified version of the first game's code, it really has taken an age.

Going forward after this game, I've got three options:

i) Keep going as I am, taking over a year to make games with a lot of content, and hope the quality is good enough for it to get noticed outside of the Xbox Indie games service (ie. Steam.)

ii) Find someone to do all the graphics for me, which would speed things up a bit but give me less control and a smaller percentage of the profits.

iii) Scale things back to focus on games which will only take 3-6 months to finish. Soumething like 'The Impossible Game" on XBLIG would be an example of such a game.

Regardless of what I do in the long term, I'll probably try and knock something out in a couple of months after this game, just to see if I can.

PS. Congratualtions to Steve W (full name withheld) for being the only entrant and therefore winner of the competition below. If he had an apple for a head he says he would hide in a tub of water during halloween and terrify the participants of an apple-bobbing competition. Well done Steve! (Although frankly you could have said anything and still won). I'll probably do something similar when the new game is coming out and hopefully get a few more entrants.

Sunday 9 October 2011

Mentorship in Software Craftsmanship - part 2


In part one I gave a bit of background history and also described the roles and responsibilities of mentors and mentees according to the Software Craftsmanship principles. In this second post I'll be convering a few other areas related to the relationship itself. Remember that the focus here is on mentorships outside work. Let's start from the beginning.

How do we find mentors or mentees?

That's probably the most difficult question to answer. I can think in three possibilities (in no particular order):

  1. Try to find someone that works with you in a daily basis. It will make the approach easier.
  2. Via user groups and communities. If you are an active member of a user group or community you will have the opportunity to meet a lot of people and maybe find the mentor or mentee you are looking for.
  3. Via indication: A friend could recommend/introduce you to someone. 


Choosing a mentor

Although not a rule, normally, in Software Craftsmanship, it is the mentee that chooses the mentor or, at least, start the conversation. The mentee needs to have an idea of the path he wants to take. For example, he may want to learn more about mobile development, work as a consultant, work in high-performance low-latency systems, learn about gaming development, improve his automated testing techniques or, in the best case, just learn how to become a better developer. Whatever the mentee's ambitions are, the mentee needs to make sure that his future mentor is a person that can provide the knowledge he or she is looking for.

Unfortunately, this may be easier said than done. Depending where the mentee is in his career, he may not know exactly what he wants. He may not even know what options he has. Although good developers are good developers and the foundation and priciples of software development always apply, we all know that the skills set used in different types of systems can vary a lot. A well experienced developer that spent the majority of his career doing web-development and became an expert in user experience may take a while to perform well in a completely server-side, asynchronous application with no GUI. Working on an application that heavily rely on algorithms and that don't use any database can be totally different from developing a mobile client application. The same way that working for a consultancy company can be very different from working for a bank or a startup.

Those are some of the things that developers at early stages of their careers may not even have a clue. If you are at this stage in your career, the best suggestion is that you focus purely on being a great developer and learn the basics. Things like Test-Driven Development, clean code, refactoring, Object-Oriented principles, different languages and paradigms. Once you have that, it will be easier for you to choose your next move.

Choosing a mentor involves is not an easy task. Maybe a single mentor won't be able to teach everything a mentee wants to know. Mentees should focus on their very next step(s) instead of focusing in everything they want to learn throughout their entire career. Mentees may change their minds quite often as soon as new opportunities and options are presented to them. They should keep their options open and choose a different mentors as time goes by.  

Choosing a mentee

Mentors, before accepting a mentee, should ask themselves: Would I be able to dedicate time to this person? Can I really help his or her career? If the answer is yes, fantastic.

The first thing to look for in a mentee is passion. Since a mentor will be allocating time to help someone, they should make sure that this person deserves their help. Make sure that the mentee is committed to be better.

Another thing mentors need to decide is what sort of seniority level their future mentee should have. Some mentors will prefer to take graduates, others prefer juniors with one or two years of experience and others prefer to get seniors or mentees on the verge of becoming seniors.

Choosing a mentee is a very personal thing and different mentors will have completely different criteria.  If the mentor already knows the mentee, than it is easier. When the mentor doesn't know the mentee I could suggest a few options that could either be combined or used independently:

  • Introduction letter: The mentor could ask the mentee for a summary of his career so far (not a CV). In this summary, the mentee would describe what he has done, where he thinks he are in his career, the things he learnt, provide (if any) links to his public profile like github account, twitter, blog, web/mobile applications and most importantly, what he expect from the mentor.
  • Coding challenge: The mentor can set up a challenge before considering to speak and accept a mentee. E.g. the mentee, using his preferred language, needs to write a simple blog or wiki application, have it deployed in somewhere (heroku, cloudbees, Google App Engine, Amazon Beanstalk, etc) and code should be public (github, for example). Or it could be simpler like solving a few katas using two different languages or anything along these lines.
  • Blog: Mentee should create a blog, if he or she does not have one, and publish a few posts related to things he has been learning on his own. 

The mentor, if going down this route, should set the challenges according to the level of seniority he is expecting from the mentee. Once the mentor is satisfied with the initial effort by the potential mentee, he could decide if he is going to accept or not the mentee.

Mentorship common misconceptions

The mentor is not better than the mentee. In general the mentor will have more knowledge and experience in the areas where the mentee has chosen to be mentored. However, the mentee can easily have more knowledge than the mentor in other areas. Mentees should not expect the mentor to have all the answers to all the problems and mentors should not be naive to think that the mentee doesn't know anything. Both mentors and mentees have skills and limitations and this needs to be understood by both parts.

Mentors should not be looking for themselves a few years younger. This can be frustrating for the mentor. People are different and the mentor will be missing out when not being more open to the type of mentee he or she is prepared to take on board. There is no reason to be so restrictive. Mentoring someone with different personality, possibly slightly different ambitions can be extremelly enriching for both mentors and mentees. However it is important that both have same values and principles.

Mentees should not expect that mentors will change their lives. The mentors will be there for the mentees, giving them advices and teaching what they know but it is up to the mentee to decide what to do with it. Mentees should do their part to improve and not think they are going to be spoon-fed by mentors. It's up to the mentee to look after his or her own career. 

In the next posts I'll be covering things like different types of mentorship, activities that could be performed by mentors and mentees, public recognition, professional reputation, graduation, mentorship duration, how this could change our industry and a few other points. Watch this space.

Part 3: What mentors and mentees should do, how long it should last, how does it end public recognition and reputation

Part 1: A bit of history, roles of the mentors and mentees, gains and sacrifices and mutual respect


Tuesday 4 October 2011

Mentorship in Software Craftsmanship - part 1

How's mentorship seen in Software Craftsmanship?

First, a little bit of background and metaphor 

In the medieval times, apprentices would work in workshops an would be mentored by senior craftsmen (journeymen) or by the master craftsman himself. The apprentice had the responsibility to learn, observing the master's and everyone else's work, questioning everything and practising as much as he could. This was different from the teacher/student relationship where the teacher had the responsibility to teach. Here it was the apprentice that had to push his own development.

The apprentice, mentored by the master, would learn and refine his skills on a daily basis. Over time, the master would reach his limit as in what he could teach the apprentice and the knowledge and skills gap between both would not be that big any more. The master would then publicly recognise the apprentice as a professional that could take on work on his own and would deliver it with the same quality that the he would deliver himself. The master, at this point, would be putting his own reputation on the line since he was the one that trained the apprentice and was now vouching for his ability. 

This would be the graduation point. Now the apprentice was ready to start his own journey, as a journeyman. As a journeyman, he would then go from town to town, work for and learn from different masters up to a point that he would be recognised by all of these masters and other craftsmen as a master himself. He would then be ready to have his own shop and start mentoring other journeymen and apprentices.

Back to the present

From now on, instead of master/apprentice, I'll be using mentor/mentee. The main reason is that you don't need to be a master craftsman to mentor someone. You also don't need to be an apprentice to have a mentor. Besides that, each developer has different areas of expertise. They can be very senior in certain areas and completely ignorant in other areas. As we all know, software development is not as limited as a blacksmith's workshop in the medieval times. 

The role of the mentor

Deciding to mentor someone is a big responsibility. The role of a mentor is more than just be available on the phone and answer a few questions here and there. Although this can be very helpful, the role of a mentor goes way beyond than that. The mentor has the responsibility to make the mentee a good professional and that includes the technical and the personal side. More than just teaching the mentee a specific framework or technique, the mentor will also be teaching the mentee how to become a professional software developer, including ethics and code of conduct. From the technical perspective, the mentor will do his best to teach everything he knows. If they don't work together, the mentor is expected to reserve formal time to work with the mentee. From the personal perspective, a mentor should help the mentee in his career (journey), giving some guidance, advices, opening doors or showing the doors he has already opened himself, introducing the mentee to his own professional circle and whatever else the mentor judges that can be important for the mentees.    

The role of the mentee

The mentee is expected to do whatever he or she can to learn from the mentor. The mentee must be open-minded, be able to take criticism on board, be able to listen and also be very proactive in terms of perpetuating the knowledge. Practice is key. The mentee is expected to practice as much as possible, making him or herself better everyday. Mentees are also expected to produce something. Something where the mentor can measure their progress and possibly identify areas of improvement. Besides the direct benefits to the mentee, this is also the best way to keep mentors excited to be helping. Mentees must show passion and a clear desire to learn otherwise mentors will probably loose interest and find it a waste of time.  

Gains and sacrifices

Mentors have the opportunity to perpetuate their knowledge since they need to organise their ideas to teach someone. Mentors will also need to be studying and practising hard to keep feeding his mentee, what obviously is a good thing. They will get the satisfaction of helping developers to progress in their careers, with good foundation, ethics and professionalism. They will be doing their part in rasing the bar of our industry, training the next generation, and this, on its own, is a very noble cause. But there are sacrifices and the main one is time. Mentors are expected to dedicate time to their mentees. If mentor and mentee work together in a daily basis, they won't need much time outside work. However, if they don't, mentors need to be clear they will need to find and reserve time for their mentees, ideally in a regular basis.

Mentees have the opportunity to speed up their development as professional software developers. They benefit from the mentor's experience acquired over the years, shortening the time they would take to learn something and avoiding to commit the same mistakes. They also have someone they trust that could offer a different perspective on the things they are going through (technical issue, problem with a manager, process, bureaucracy, deadlines, estimation, etc). Without any scientific evidence to back me up, I would dare to say that with the right attitude from both parts and a good amount of time together, the mentee could learn in two years what the mentor learned in ten. That gives the mentees a massive head-start in their careers. Time should never be called a sacrifice from the mentees perspective. When someone is getting a lot of knowledge and help for free, possibly saving years of their careers, complaining about time (or lack of it) would be very short-sighted, to say the least. 

Mutual Respect

Both mentors and mentees should respect each other. In order to have a healthy and prosperous relationship, there must be a commitment from both parts. This commitment is the mutual respect. The mentor shows respect with regular interactions with the mentee and time commitment. The mentee shows respect with his commitment to excel and demonstration of progress. That's the minimum a mentee could do for someone that is sacrificing time with family and friends in order to help him. 


In following posts I'll be exploring things like different types of mentorship, activities that could be performed by mentors and mentees, criteria for choosing a mentor and a mentee, public recognition, professional reputation, graduation, mentorship duration, how this could change our industry and a few other points. Watch this space.


Part 2: Choosing a mentor and a mentee and also common mentorship misconceptions 
Part 3: What mentors and mentees should do, how long it should last, how does it end public recognition and reputation


Competition time!

This is quite a long shot, but are you a fan of this blog who doesn't own the original Apple Jack on Xbox?

Perhaps you love slightly wonky platform games but don't have the funds required to play it?

Or maybe you bought it a while ago and your house burned down, killing your entire family and melting your Xbox. And then when you bought another console you forgot your Gamertag and lost all of your downloads.

Well in either case, TODAY IS YOUR LUCKY DAY!!

My Owl Software is giving one lucky person the chance to win a code which will let you download the popular Indie platformer Apple Jack ABSOLUTELY FREE! That's an astonishing saving of 65 new pence!!

Interested? All you have to do is email me explaining how you would spend your time if your head was replaced by a giant apple. I think the My Owl email address is on the right hand side of the page somewhere.

In the unlikely event that I get more than one reply, the winner will be the one I find most entertaining. And please don't bother entering if you have the game already, as it would be pointless.

Good luck, Apple heads!

Monday 3 October 2011

Screencast #1

This is my first screencast. It is a true waste of bandwidth and nothing else. I made it in high definition and added a beautiful soundtrack, but Blogger (the host of my blog) has decided to spoil it.
The visual effect you see in the movie is necessary: when you duplicate a page, the new page is identical to the old one. Without an animated effect it would be hard to understand if the command was executed or not. What was not necessary was the movie itself...

Sunday 25 September 2011

For an idea of what games COULD and SHOULD look like, have a browse through this blog:

{feuilleton}

It brings home the incredible diversity of visual art, of which videogames exploit only a tiny fraction.

Tuesday 20 September 2011

LSCC's First Code Retreat

On September 10th we had the London Software Craftsmanship Community's First Code Retreat.

We had 22 passionate and talented developers working in Java, C#, Ruby, Python and JavaScript. Some of them travelled two hours, waking up as early as 5am, to come to the code retreat and many others travelled at least one hour to be there.
We started at 8am, with breakfast and informal discussions. Then we had a quick introduction, where I explained the purpose of the day and used some of Corey Haines wise words. Here's a quick summary:

"In our day-to-day job, we need to get things done. We need to achieve something and deliver something. And we want and are committed to it. In order to do so, we end up cutting corners. So that's how we code. We sacrifice quality in order to deliver "faster".

But now imagine you have all the time in the world and all the knowledge in the world. Imagine what would be your idea of perfect code. Now compare it to what you do and how you code in your day-to-day job.



This gap is the measure of how much you suck. The bigger the gap is, the more you suck. The smaller the gap is, the less you suck. :)

But today, during the code retreat, is the day that we will practice perfect code. Today we don't need to deliver. Today we have no pressure, besides writing perfect code. That means the objective of a hands-on session like that, is not to finish the exercise, but to practice new approaches, expand our horizons and learn from others. Today we will reduce the gap from what we do in our day-to-day job and the perfect code, providing better value for our customers and being better professionals. "

It's not practice that leads to perfection, it's perfect practice that leads to it.

I also explained the four rules of simple design:
        - All tests need to pass;
        - No duplication;
        - Reveals intention (good naming)
        - Small
       
I have made this letter longer than usual, only because I have no time to make it shorter.
        Blaise Pascal (sometimes also attributed to Mark Twain)
       
Format of the day


After a good breakfast, developers formed pairs and worked on the Conway's Game of Life. We had three sessions in the morning, then lunch and another three sessions in the afternoon. Each session lasted 45 minutes and had a retrospective afterwards where developers discussed their approaches and problems they faced. Then developers deleted the code from their machines. In each session new pairs were formed and worked on the same problem.

  • First session: It was free. Basically the pairs worked with no constraints just to make themselves familiar with the problem.
  • Second session: As a challenge, they were asked to use different data structure other than arrays and we introduced the concept of "primitive obsession".
  • Third session: Developers were asked not to use flags and use polymorphism instead. This was to promote the exploration of abstractions.
  • Lunch: We had nice sandwiches and deserts from a good delicatesse. We had 1.5 hours for lunch. During lunch time, some more senior developers said they haven't been challenged enough so I changed the strategy.
  • Fourth session: In order to satisfy developers from different levels, I asked them to come up with a list of challenges and each pair would then decide which challenge they would take on, according to their level of expertise. The list they came up with was;
    • Maximum 3 lines of code per method;
    • Object-Oriented Programming to extreme.
    • No getters / setters / properties
    • Every line must start with "return" or "final" (Java/C# - functional style)
  • Fifth session: TDD as if you meant it, that means, all code needs to be written inside the test method and then refactored out.
  • Sixth session: Developers were free to do whatever they wanted again but many decided to use some of the challenges from sesson four. 
  • Pub
    
During the sessions, I also asked them to try different testing approaches: outside-in and inside-out. The reason was to compare how different the design would turn up. They were also encouraged to pair-program with developers from other languages, what is an amazing experience and broadens our mind.     

The experiment with each pair choosing the challenge on session four had a mixed feedback. Some developers enjoyed it because they could push themselves. Others said that the retrospective was not so good since pairs were working with different challenges and could not relate to the problems and solutions exposed by other pairs. This is something I'll need to think about for future code retreats. How can I balance the challenges so everyone feels, well, challenged.

Overall, we all had a fantastic day. There were many very interesting discussions during the retrospectives and, according to the feedback, everyone learnt something. I definitely learnt a lot myself and facilitating my first code retreat was an amazing experience that I want to repeat.

I would like to thank Valtech for providing the venue and for the full sponsorship. They provided us everything we needed for this event and were key for its success.

For the full list of attendees, details about the event and more photos, please check http://www.meetup.com/london-software-craftsmanship/events/27600561/

Sunday 18 September 2011

Hello! I've finished designing all the forest levels and now I've got the final beach environment to finish. There will be 60 levels in total (16 left to do), and while this isn't as many as the first game had, most of the levels are larger this time around.

Every level in AJ1 was laid out on a [50 x 50] tile grid, since I wanted to make something akin to Bubble Bobble, with lots of small, short levels. In practice, this led to many of them feeling a bit cramped, so I made sure to give myself enough room for the sequel.

So now we have a [350 x 30] tile level,  followed by a small [40 x 55], then a [27 x 350] level which has AJ dropping all the way down through the clouds, weaving through spikes as he falls.

I think the next one will have AJ trapped in a maze of blocks that he has to push his way out of, a bit like a Professor Layton puzzle, but with pandas and owls patrolling in little pockets of enemy resistance [80 x 80].

Tuesday 13 September 2011

Changes

After many happy experiments in the field of manual phase correction, after many years and many different solutions, this is what I like now, the perfect phase correction module for 2012:
At first it is confusing, because of the so many controls and because of its asymmetry. The two important elements are the circular slider for the zero-order phase correction and the long vertical slider for first-order correction. This module works in connection with a pivot marker, which can be either horizontal or vertical. Some people don't understand the idea behind the pivot marker. It is not a third parameter. It's simply an interface element which frees the user from the task of adjusting the zero-order correction. Without the pivot, the correction is a two-parameter optimization (iterative, non intuitive and tedious). With the pivot, it becomes a single parameter optimization (intuitive, natural, easy and instantaneous). This new module is so thin, that it let you see the whole spectrum behind it. When the thumb reaches the end of the run on the vertical slider, the value for the end of the run changes, so the visual effect is that the thumb returns to the center. If you aren't a purist, the button "auto" performs automatic phase correction.

Wednesday 7 September 2011

Ooh! What's this I spy on page 110 of the latest issue of the Official Xbox magazine?


(The text on the left says 'Best of the indie games, five hidden gems we loved')

Good eh! Well yes, but I'd have preferred it if they'd bothered to get the name right. Has anyone here heard of a game called "Apple Jack's"? I spent two bloody hours carving that apple for the box cover, and this is the thanks I get.

Still,  the last laugh is mine: I actually cancelled my subscription to the magazine two months ago but Future publishing doesn't seem to have noticed and have been sending it to me for free! Ha ha!

Sunday 28 August 2011

Still designing levels...Blah blah...Taking a long time...Yadda yadda...lots still to do...etcetera.

In other news, the first game has done quite well this month with over 500 sales. I certainly didn't expect it to be shifting decent numbers 15 months from release, but it's very welcome. 500 is quite a lot of people when you think about it, isn't it?

In otherer news, I had a good idea for a new game in the bath today; a 2D shooter with a real sense of scale and more fruit. Once I've finished AJ2 I'll probably get cracking on it. Possible title: SPACE ORANGE.

Monday 22 August 2011

nmrglue



NMR glue is based on the same libraries on which VeSPA is built. The installation of nmrglue is similar. Different is the result. After the installation is complete, there is no icon to click. The instructions say nothing about what to do after installation. While the purpose of the program is clearly described, I can't add anything of my own, because I can't use it. The program is somewhere on my computer, but I don't know how to launch it.

Who feels the need of another NMR program? I still haven't found the answer to the question: "Who felt the need of inventing Python?".

Sunday 21 August 2011

OpenGL Line Drawing is Broken on Some Android Phones

Drawdle is a somewhat performance-intensive application, both because of its physics engine and its graphics (crude as they are). On older devices, such as the HTC hero, it is advisable to turn the background off for a smoother performance, as the objects floating around back there account for a significant amount of rendering time. In fact, Drawdle automatically disables the background on devices that have a resolution smaller than 800x480 on the basis that such devices are probably older or otherwise less powerful, and we want to ensure good performance "out of the box" on as many devices as possible.




Drawdle with the backgrounds on
That said, I had been getting reports of very poor performance from users with new, high-powered devices such as the HTC Thunderbolt, Desire HD and Incredible 2. And not poor as in 15-20 FPS (as with my Hero when backgrounds are on), but as bad as 1-2 FPS, not even remotely playable. These users made their displeasure very clear on the Drawdle Lite ratings/comments board on the Android Market.

Why was this happening? Drawdle plays great, background and all, on my friend's HTC Evo 4G, a device that is similar to the HTC Thunderbolt only a year older and by any measure not as powerful. The story was the same for the Droid Incredible line of phones: Drawdle plays fine on the original and plays horribly on the newer model. Something was very wrong.

The culprit, as I was able to verify, was the background. Users who turned the Drawdle background off on their Thunderbolts reported markedly improved performance, in line with devices that were known to be OK. Unfortunately, this was not enough to go on: the code responsible for the background in Drawdle wasn't that different from the rest of the codebase. Creating the background required the physics engine, line rendering and buffer updating, nothing that that wasn't being done all the time anyway.

I didn't have access to an affected device to profile on (an a la carte Thunderbolt costs $700 retail), so tracking this down would not be quick. I started by converting my vertex arrays to VBOs, confident that there was a bug in the glDrawArrays implementation on these devices. A quick trip to the Verizon Store to test my fix showed that my optimism was misplaced, as there was no improvement. This pattern repeated itself when I tried disabling the physics engine and updates to the color buffers for the background objects (look closely and you can see the objects periodically change their colors). Nothing that I tried helped.

My only hint was this post discussing a similar problem on a weather application: some users were reporting that the app ran fine on their devices until they turned on county lines. I had an epiphany that night while thinking about that post: it was line drawing that was slowing my app on these devices, sprite rendering, which was implemented the same way, using glDrawArrays, worked fine.

I set about converting my line drawing calls to their equivalent triangle strip calls. This wasn't trivial or cheap (a triangle strip requires twice as many vertices as an equivalent line, line strip or line loop), but it was worth the effort. On my next round of testing (thank you Verizon Store) my app performed flawlessly.

Long story short, you should avoid drawing calls with GL_LINES, GL_LINE_STRIP and GL_LINE_LOOP when developing for Android. This goes for both vertex arrays and VBOs. This problem appears to affect only some phones with Adreno 205 GPUs, but that isn't proven at this point. More research is needed; if you have anything to share, please drop me a line or leave a comment here.

Friday 19 August 2011

One year of London Software Craftsmanship Community (LSCC)

Without a sense of caring, there can be no sense of community. - Anthony Burgess

Happy Birthday, LSCC!!!!

On 18th of August 2011, the London Software Craftsmanship Community completed one year. And what a great year we had!

How did it all start?

David Green and I had worked together in the past and we kept in touch since. Over one year ago, we were talking to each other about our jobs, pet projects, technologies, etc and we both realised that we couldn't discuss everything we wanted just with the people we knew. We were also aware of our own limitations. So we thought that it would be awesome if there was a group of people that we could meet regularly and share ideas about software development in general.

By then, I was very into the whole Software Craftsmanship thing. David was also very aware of everything that was going on, but we had slightly different views of craftsmanship as a movement. I remember having quite a few interesting conversations with him about that. However, we both always believed in the same principles and values regardless of the labels people were using.

I had been involved with the London Java Community (LJC) even before its existence. At some point I managed to bring David along to one of the LJC's social events. On that evening, David and I had a chat with Barry Cranford, founder of the LJC, and with Martijn Verburg and John Stevenson, LJC organisers and also involved with other user groups and open source communities. We mentioned to them our idea of having a regular meeting where any topic related to software development could be discussed. Maybe show and write some code, discuss design, compare approaches. Completely language agnostic. We also mentioned to them one thing or two about the Software Craftsmanship movement. They all said that we should go ahead and found our own community instead and offered us LJC's support and blessings. I don't think that any of us was really thinking about founding a community. We just wanted to attend this sort of meetings.

David was always a bit more organised than me. But me, I could barely organise a bbq for my own birthday, let alone run a community. We left the pub that night and while walking to the station we though that actually it could be a good idea. Maybe we should give it a go. Why not?

When I got home that night, I went to the meetup.com website and created the London Software Craftsmanship Community.

Summary of our first year

We had our first meeting on 6th of October, 2010 (video). David and I gave a introductory talk on software craftsmanship and for our surprise we had over 100 people subscribed. That was the first sign that our community would take off. Right after we decided to have a monthly meeting called Software Craftsmanship Round-table

The Round-table meetings

This is the meeting that we always wanted to have and that triggered the whole thing. In general they are limited to 25 people. We get together and attendees write the topics they want to discuss on the whiteboard. Any thing related to software development is valid. Then we take a vote. The most voted topics are discussed. Sometimes we discuss just one or two topics, sometimes we discuss up to five topics. No one needs to be an expert on the topic. It's not a presentation. It's just a friendly group discussion.

During the round-table meetings over the year, we had people showing code they were working on, pieces of design and architecture, testing frameworks, and had discussions about a huge amount of other topics. We had discussions about hiring good developers, distributed agile teams, mentors and apprentices, TDD, legacy code, patterns, PaaS comparisons, programming languages, android testing frameworks, the future of web applications, literate programming, DSLs, BDD frameworks, DDD, anti-patterns, specific technologies like Hamcrest, JUnit theories and Spring Roo and many many others that it would be impossible to describe all.

I absolutely love the roundtables and learned a lot from them. Our latest addition to it is a series of lightning talks at the beginning of the night, when people fancy giving one. Another cool thing is that every meeting is different, depending of who is attending, the topics proposed and the ones people voted on. 

Other meetings

During the year we also had a few other great meetings. One was the Software Craftsmanship Panel Discussion - How can craftsmanship move the industry forwards? | video - when we had the pleasure to have Ade Oshineye, Chris Parsons, Dan North and Dave Hoover in the panel. It was great to see them giving their views about many topics relevant to the future of our industry. We had Jason Huggins, creator of Selenium, giving a talk to us about "how to test 'untestable' applications" | video.

We also cross-promoted the Code Retreat Winchester, organised by Despo and Aimee, and the first Cambridge Dojo Day, organised by Alastair Smith, organiser of the Cambridge User Group - CAMDUG.

Future meetings

We will be keeping the monthly Software Craftsmanship Round-table meetings on every second week of the month. From this month onwards, we will have a monthly hands-on session on the last week of the month. Our first one is the Crafting Object-Oriented Code, on the 30th of August. We will be opening the space to our members to submit proposals for any hands-on session they want run in the following months.

We are also very happy to be having LSCC's First Code Retreat on 10th of September.

Our meetings tend to be fully subscribed, on average, in 24 hours after they are announced. We had round-table meetings being booked up in just 5 hours in the past. So, if you want to attend our meetings, make sure you register as soon as you get the email notification.

Community

Throughout the year, we met many extremely passionate and talented people. I learned things that I was not even aware they existed. And that's what this is all about. That's exactly what we always wanted. We met people from all levels of expertise, different backgrounds, working in different industries and with different technologies. All kind enough to share what they know and humble enough to want to learn from others.

LSCC had a lot of support from LJC and we are committed to support other communities as well. With that in mind, we would like to offer our support to any person or group of people thinking to found a software craftsmanship community in the UK or even abroad. We are more than happy to cross-promote any event to our members - if we judge they are relevant to our community and to the software craftsmanship moment as a whole.

The future of LSCC

We have quite a few things in our heads but I don't want to spoil the surprise and neither make promises I may not live up to. But there are a few things I can say. Besides all the regular meetings (round-tables and hands-on sessions), we want to focus more on the Software Craftsmanship movement itself. There are quite a few principles and values that we need to start focusing on. We are already having discussions about some of them so watch this space.

Another thing I personally would like to see is more software craftsmanship communities around the UK and Europe. We will do the best we can to help and support new communities.

As we grow, we will need to do more but one thing is for sure. We will not compromise the quality of our meetings or things we want to do just to bring more people in.

A big thanks

I would like to thank our sponsors - YouDevise, SkillsMatter and Valtech - for their support, for offering their premisses so we can run our events for free and for helping us get fat with all the pizzas and drinks.

A big thanks to all the kindred spirits that support and promote LSCC and, last but not least, a massive thanks to all LSCC members for their dedication to their craft and for making LSCC a great community. You guys rock!

I'm really proud to be a software craftsman and I'm happy to be able to give something back to this amazing community of developers that gave me so much and that helped me to become the professional I am today. Thank you all.

Thursday 18 August 2011

Here is a frame from the Apple Jack's Great Escape intro, currently being worked on by a nice chap called Neil, who's a copywriter and who recently got married. Wave to Neil everyone!



Sunday 14 August 2011

Drawdle Trailer Released

The official gameplay trailer for Drawdle has been released, check it out:


Friday 12 August 2011

Hmm, not much to report except that designing the levels for this game is taking longer than for the first Apple Jack, for these two reasons:

1)  Most of them are larger.
2)  They are now full of moving objects and often the speed and position of these blocks/ platforms/ switches/ saws has to be worked out using trial and error; changing something in the level editor and then playing the level to see if it works.

On the upside, having gotten everything working, some of the levels are, if I say so myself, very clever and unique. Since level 20 I've started adding switches which 'turn off' blocks of scenery as long as something is pressing them down, be that a block, an enemy, or Jack himself. I'm almost spoilt for choice, which probably isn't helping in terms of a speedy release.




Thursday 11 August 2011

Launched

We've launched.

One Side Software is a independent software company based out of Atlanta, Georgia. Our first title is Drawdle:

Drawdle is a drawing based physics game, where you draw the objects you use to solve puzzles. You've probably never seen anything like it before. Both a free and paid version are available now on the Android Market. Check it out.

As for this blog, I'm planning to post my experience with Drawdle and other games. Posts will cover design and development (which I know) and marketing and PR (which I don't). All of these, I hope, will be interesting in their own right. Stay tuned.

Monday 25 July 2011

SRP: Simplicity and Complexity

Simplicity does not precede complexity, but follows it. - Alan Perlis

The Single Responsibility Principle (SRP) - one of the SOLID principles - is definitely one of my favourites principles in Object-Oriented Design. I find its simplicity and, at the same time, its complexity fascinating. I have known this principle for years and wrote about it for the first time over one year ago. Still, I can't stop thinking about how hard it is to apply it. Speaking to and pairing with many developers over the years, I noticed that every single one of them understands what the principle is about but when it comes to write code, either they forget it or they simply can't find a way to adhere to it. I'll give you my view about the problem and what I've seen happening in many occasions.

The outside view

 Every class and method should have just one responsibility

This is what I call outside view and naming plays a big role here.

This view is generally used when we need to add some totally new code. We think what the new code is about, create a class and/or a method, give it an appropriate name that represents what the new code does and we are done. We also use this outside view when reading code. When looking at a class or method name, it should be clear to us what they do.

I don't think anyone ever had a problem understanding this principle.

However, if it is so simple to understand, why don't we all follow it? Why do we still find classes and methods with hundreds, if not thousands of lines? A few things come to my mind to explain that. Maybe we are just bad at naming classes and methods. Maybe the names we give are too generic or too broad, allowing us to write loads of code in there. Maybe some of us just don't care.

The inside view

Classes and methods should have one, and only one, reason to change

This is what I call inside view and it is the other (often forgotten) side of the Single Responsibility Principle.

This view is generally used when we need to change some existing code or add more code to it. That's when we look inside each class and method to see exactly what they do. More often than not, we get frustrated because they do much more than they should do and we need to go through many lines of frustration and WTFs to understand the bloody thing.

However, it is much easier to adhere to the SRP when we keep the inside view in mind instead of the outside view. That means, always think about the number of reasons to change a class or method instead of thinking purely in their responsibilities.

So, when and where do things go wrong?

NOTE: In general I find more SRP violations in systems where developers are not doing TDD and refactoring.

Here is some food for thought. I'm risking to say that the majority of SRP violations are found in the classes and methods that are closer to the interface of the system. For example, in a web application, it's very common to find large controllers, actions or backing bean classes. For swing applications, we tend to find large event handlers. For systems where the entry point is a queue, we tend to find large methods that are responsible for processing the messages. 

In general, this happens because the classes and methods closer to the interface of the system have a more generic and broader responsibility. Quite often, these methods are responsible to trigger loads of business rules and/or complex workflows.

Imaging that the input to our system is a huge XML file representing a trade. Also imagine that the first method invoked to handle that is called "processTrade(tradeXML)", located in a TradeService class. What is the responsibility of this method? It is to process a trade, right? Should it have a different name? Our system is expected to "process" all trades received so it is fair to say that the first method handling the request (or reading from a queue) should be called processTrade.

In another example, imagine that an user added a few items to her shopping basket (web application), provided some payment details and clicked on the "place order" button. In our back end, we will have a method handling this request that probably will be called something like placeOrder(order). Fair, right?

Developing an idea

In general, the closer the code is to the system's interface, the broader and more generic its responsibility will be. The further away the code is from the system's interface, the narrower and more specific its responsibility will be. 

In both examples above, by their names, you can argue that the methods processTrade and placeOrder have a single responsibility. One processes the incoming trade and the other places a customer order. So, when developers take into account just the outside view of the SRP, they feel comfortable to add as much code as they need to satisfy these responsibilities.

The problem is that processing a trade or placing an order may be extremely complicated tasks, where a huge workflow will be triggered, many business rules and requirements need to be satisfied and we will need to write hundreds, if not thousands, of lines for that. So clearly, adding all these lines to a single method doesn't just simply violates the SRP. It's also plain stupid.

So, in order to make our code compliant to the SRP, we need to have just a single reason to change it. This leads to a complementary idea.

In general, the closer the class is to the system's interface, the more delegation the class will do. The further way the class is from the system's interface, less delegation the class will do.

A general example would be, in a traditional Java web application, the controllers, that are closer to the UI, have a broad responsibility and tend to delegate all the business logic to other objects. They just control the flow. At the other end, we have the DAOs that have a very specific and narrow responsibility, almost never delegating anything to another class. In the middle, we have services, that do some business logic of their own but also delegate work to other collaborator classes. Services tend to have a narrower responsibility when compared to a controller but a broader responsibility when compared to DAOs. Still, each class and method have a single responsibility.

Asking a different question

When mentoring and/or pair-programming with other developers, quite often we end up discussing about the amount of code in a method or methods in a class. Just using the SRP's outside view as an argument sometimes is not enough to convince some developers that the code is doing too much. That's why I find the inside view more useful. Instead of asking how many responsibilities a method or class have, I now ask how many reasons we would have to change them.

Saturday 23 July 2011

cute NMR


Among the many unfinished open source projects, cuteNMR is worth of some attention. It is not usable, but at least it works. One of the high points is the dialog for manual phase correction. Though nothing spectacular or innovative, it is much better than the one you can find inside NPNMR.

Thursday 21 July 2011

The Pleasure of Writing the Truth

We chemists can publish hundreds of figures. Just think at the experimental section of an average article and the part of that section that describes NMR data.
How many times you find the symbol "m" for multiplet? It's a lot of times. Sometimes really there was no viable alternative, other times, however, it was possible to describe that multiplet (or rationalize it) as "ddd" or something similar. It does not happen because of laziness. The values of the coupling constants are not reported in such a case.
Other times the J values are reported, but under the first order approximation. We know that this approximation is often valid. We also know, however, that many times it is not accurate. Modern NMR programs includes analyzers of first-order multiplet. It's unfortunate that their marketing always forgets that second order spectra exist in abundance! Obviously people begin to believe that this ignorance is forgivable ("Everybody is using that pretty multiplet analyzer…").
Methods to simulate a spin system and fit it against a complex experimental spectrum have been available for decades. They aren't completely automatic and require a little of attention and time by the part of the user. This small investment is balanced by the fun of fitting (because normally it's funny).
Last, but not least, when it's time to write your articles you know your figures are as true and accurate as they can be!
Strangely I don't remember any cross-platform program that performs both simulation and fitting. I remember SpinWorks, WinDNMR and Perch for Windows and iNMR for the Mac. Three general methods (algorithms) are known: LAOCOON, Total Line Shape Fitting and manual fitting. The latter is not an algorithm and has no mathematical basis, yet it's often the most practical one. It is very useful to have all the three methods inside the same program, and it should be an all-purpose processing program (you save the effort of moving data between applications).
I have gathered a few links in case you want to practice the art of simulation on your Mac:

http://www.inmr.net/articles/nmrdb.html
http://www.inmr.net/articles/fitab.html
http://www.inmr.net/articles/hobut.html
http://www.inmr.net/articles/dipolar.html
http://www.inmr.net/articles/DNMR.html

Tuesday 19 July 2011

Rather than name the levels after UK towns and villages as in the first game, I'm going to make up names for this one. Scribbled down so far are:

- The Pain Engine
- The Dawn of the Naked Eye
- The Bacon Exchange
- The Sky is Filled with Astronauts
- The Panda Factory

and so on.

I'm taking plenty of inspiration from short stories and chapter headings in J G Ballard books - I really love their pulpy surreal-ness.

PS- To answer Chris Mingay's question in the comment section below, I did set up a My Owl Twitter account but I never used it and I no longer even know where it is or what my password was! Perhaps I'll set another one up nearer the game's release.

Glassy Contours


This is a new concept in the art of plotting. Only one color is used for positive peaks and another color for negative peaks. The difference among the levels is a different value of the alpha channel. Click the picture to enlarge.
This option is featured in iNMR reader 4.1.5 and iNMR 4.1.6.

Sunday 17 July 2011

Testing legacy: Hard-wired dependencies (part 2)

In part one, I showed how to unit test a method that uses a Singleton and makes static calls. So now, let's have a look at common code problems we find in legacy code, using the same example:


How many problems can you see? Take your time before reading the ones I found.. :-)

Refactoring
NOTE: When I've done it, I've done it step by step running the tests after every step. Here I'll just summarise my decisions

The first thing I noticed is that the tripList variable does not need to be created when the logged user is null, since an exception is thrown and nothing else happens. I've decided to invert the outer if and extract the guard clause



Feature Envy

When a class gets data from another class in order to do some calculation or comparison on that data, quite often it means that the client class envies the other class. This is called Feature Envy (code smell) and it is a very common occurrence in long methods and is everywhere in legacy code. In OO, data and the operations on that data should be on the same object. 

So, looking at the code above, clearly the whole thing about determining if an user is friends with another doesn't belong to the TripService class. Let's move it to the User class. First the unit test:


Now, let's move the code to the User class. Here we can use the Java collections API a bit better and remove the whole for loop and the isFriend flag all together.


After a few refactoring steps, here is the new code in the TripService


Right. This is already much better but it is still not good enough.

Layers and dependencies

Some of you may still be annoyed by the protected methods we created in part one in order to isolate dependencies and test the class. Changes like that are meant to be temporary, that means, they are done so we can unit test the whole method. Once we have tests covering the method, we can start doing our refactoring and thinking about the dependencies we could inject.

Many times we would think that we should just inject the dependency into the class. That sounds obvious. TripService should receive an instance of UserSession. Really?

TripService is a service. That means, it dwells in the service layer. UserSession knows about logged users and sessions. It probably talks to the MVC framework and/or HttpSession, etc. Should the TripService be dependant on this class (even if it was an interface instead of being a Singleton)? Probably the whole check if the user is logged in should be done by the controller or whatever the client class may be. In order NOT to change that much (for now) I'll make the TripService receive the logged user as a parameter and remove the dependency on the UserSession completely. I'll need to do some minor changes and clean up in the tests as well.

Naming

No, unfortunately we are not done yet. What does this code do anyway? Return trips from a friend. Looking at the name of the method and parameters, or even the class name, there is no way to know that. The word "friend" is no where to be seen in the TripService's public interface. We need to change that as well.

So here is the final code:


Better, isn't it? We still have the issue with the other protected method, with the TripDAO static call, etc. But I'll leave this last bit for another post on how to remove dependencies on static methods. I'll park my refactoring for now. We can't refactoring the entire system in one day, right? We still need to deliver some features. :-)

Conclusion

This was just a toy example and may not even make sense. However, it represents many of the problems we find when working with legacy (existing) code. It's amazing how many problems we can find in such a tiny piece of code. Now imagine all those classes and methods with hundreds, if not thousands of lines.

We need to keep refactoring our code mercilessly so we never get to a position where we don't understand it any more and the whole business starts slowing down because we cannot adjust the software quick enough.

Refactoring is not just about extracting methods or making a few tweaks in the logic. We need to think about the dependencies, the responsibilities that each class and method should have, the architectural layers, the design of our application and also the names we give to every class, method, parameter and variable. We should try to have the business domain expressed in the code.

We should treat our code base as if it was a big garden. If we want it to be pleasant and maintainable, we need to be constantly looking after it .

If you haven't read it yet, check the part one of this post. If you want to give this code a go or find more details about the implementation, check: https://github.com/sandromancuso/testing_legacy_code