Code Comments

by John Turner

Posted on December 20, 2011


I remember when I started commercial coding in early 1999. The developers that I worked with would constantly remind me of the value of commenting code. The main reason they would give was that it reduces the cost of maintenance by making it easier to return to the code at a later date.

Now, I wanted to write code and not comments so this did not come naturally but on my best days I would diligently comment every class/method declaration and adorn non-trivial methods with a liberal spattering of the same. After a while I noticed the amount of noise produced by comments that added no value or that were no longer relevant was a considerable distraction. In fact, this distraction was increasing the maintenance cost rather than reducing it as I had previously been told.

Since then much has changed and the publication of books such as The Pragmatic Programmer, Clean Code and The Clean Coder has changed the perceived wisdom surrounding the commenting of code. The authors of these books suggested that better code maintainability will come from writing better code (who would have thought!). By better code they meant code that is easier to understand but how do we write code that is easier to understand. A good start is to:

  • Use descriptive class and method names.
  • Do Not Repeat Yourself
  • Write SOLID code.

Given the way in which modern logging frameworks work, using descriptive class and method names also increases the value of your application logs.

Bob Martin said that ‘The proper use of comments is to compensate for our failure to express yourself in code. Note that I used the word failure. I meant it. Comments are always failures.’’. I’m a little more open to comments and still see the value in class and public method comments (please, no bean accessor and mutator commenting!) but regardless of each individuals personal preferences for comments its is good that people are thinking about the subject and doing what makes most sense for them rather than blindly commenting everything.


Arduino Starter Kit - Day 1

by John Turner

Posted on December 20, 2011


My wife recently bought me an Arduino Starter Kit from Earthshine Electronics and I have been keen to start playing around with it. Despite doing some electronics in university I have absolutely no idea where to start but there was a free book (downloadable PDF) that accompanied the kit. I downloaded the book and followed the instructions to install the Arduino IDE and verify that the Arduino board was functioning.

Project 1 in the book involved connecting an LED and resistor to the board (using a breadboard) and writing a short sketch to make the LED blink every second. While it was pretty straight forward, I was quite pleased when it all went to plan (I think trouble shooting would be beyond me at this stage) and the little red LED started to flash when I uploaded the sketch to the Arduino. The book then reviews the C code (which I skimmed over) before providing an overview of the hardware for the project. Its on the hardware side that I will find my challenge so I needed to read this section carefully.

Project 2 used the same hardware configuration but changes the sketch to signal S.O.S in Morse Code via the LED. Given this only involved a rather simple sketch and the same hardware configuration I did not find this interesting. On to the next project.

Project 3 simulates the light sequence on a set of UK traffic lights; that is, red, red-amber, amber and green. Given the two previous projects this was pretty straight forward. Different resisters were used this time so that the LED’s were not as bright as in the previous projects. Given the additional components, I can see now why a strong table lamp is a necessity for this type of activity. Anyway, I’ll press on without one.

Project 4 adds a set of pedestrian lights (red and green) and a push button to the previous project. Steady state shows the traffic green and the pedestrians red. On pushing the button, the traffic is shown amber then red. The pedestrians are then shown green. After a little time passes the green pedestrian light flashes before changing to red. The traffic lights then transition to amber and then green thus completing the sequence and returning to the steady state. The circuit was straight forward although given the number of components I had to recheck the connections a couple of times. I also made the mistake of placing and LED the wrong way around thus it did not illuminate. This was easy to detect and diagnose. The code itself was fairly straight forward.

Project 5 creates a LED chase effect. Both the hardware and sketch are straight forward but given it uses 10 LEDs and 10 resistors it is fairly time consuming. I worked through it anyway for completeness.

So far it has been fun learning about the Arduino and I’m looking forward to working my way through the other projects in the accompanying book. It’s getting late so time to pack up for today. Hopefully I’ll get some time over the Christmas holidays to tackle the rest of the projects.


SpringOne 2GX: Messaging for Modern Applications

by John Turner

Posted on December 10, 2011


I’ve spent much of my career working on application integration projects and the technologies and techniques have changed much in that short period of time. I’ve used a variety of transports, message formats and protocols and these are continuing to change with the requirements from modern applications.

The Messaging for Modern Applications session at SpringOne 2GX starts by talking about the trends in modern applications. Much of this reiterated the information in the key note session by discussing the diversifying of user platforms and applications, massive scale of data requirements and the continuing emergence of Cloud computing. Tom McCuch points out that synchronous communication protocols have often led to brittle architectures that evolve slowly. Much of this is due to the fact that often components are coupled in time, their release cycles require significant co-ordination etc. Components are typically stateful leading to scalability challenges that can be met by asynchronous architectures that retain state within messages passed between components. I tend to agree with this assertion (generally!).

Moving on, Tom speaks about Spring Integration and its ability to simplify building of messaging application components. I’ve used Spring Integration many times before and found its alignment to the Enterprise Integration Patterns catalog (see www.eaipatterns.com) and the messaging DSL meant a reasonably gentle learning curve for what is a very powerful framework. Coupled with Spring Bean Profiles this creates a great mechanism for decoupling the messaging implementation so that different implementations can be used in different environments (particularly useful for integration testing). The tried and tested Coffee Shop demo was adapted and wheeled out to demonstrate many of the concepts.

I was particularly interested in the section focusing on AMQP and its support within Spring Integration and RabbitMQ. As with the rest of the Spring portfolio, Spring Source are working to make it easier to deliver applications using these technologies from concept to production. This all encompassing approach is one of the reasons Spring has become so popular and it’s good to see that this has not changed.

One of the slides presented contained a statement that really rang true for me. It was that “Existing middleware impacts agility by tightly

coupling applications to underlying application server and other middleware components”. Again, I would agree that there are few exceptions to this statement. Of course, Spring Integration aims to reduce this coupling through its many abstractions in the same way that Spring did for J2EE.

Tom finished up this session by discussing RabbitMQ. He briefly covered its support for AMQP, clustering, federation etc. It peaked my interest enough to look into it further.

Thoughts

Similar to the key note session, I found the content really interesting. For such as session I think the pace was a little slow and Tom could have rattled through the material a little faster. Worth a watch if you can spare the 90 minutes it runs for.


SpringOne 2GX Keynote: Next Generation Applications

by John Turner

Posted on December 10, 2011


I found the recent Next Generation Applications session at SpringOne 2011 covered a lot of ground and provided a solid view on where application architecture and design is headed in the not too distant future.

The session was introduced by Ben Alex who discussed 4 key computing trends:

  • Diversification of user devices.
  • Increase of internet bandwidth and stagnation in network latency.
  • Reducing cost of data storage.
  • Reduction in clock speed and increase in number of processor cores.

These trends are having a significant impact on how we are developing applications today and will increase in relevance into the future. This paved the way for a number of discussions on how to exploit these trends to deliver tomorrows applications.

Next Generation Clients

Because of the increasing diversification of user devices developers must find a way to bring the ‘Write Once, Run Anywhere’ philosophy to the client. Spring Source are working on delivering this promise by supporting development using Html 5 and JavaScript while using bridging frameworks such as Phone Gap to ensure these applications have access to native features and are available through existing app stores.

Keith Donald demonstrated a reference architecture (expense application) built using Html 5, CSS, JavaScript and Phone Gap on the client. Authorisation utilised OAuth while services were exposed using a RESTful API. He also did a demo of pushing application updates. Compelling stuff!

Next Generation Authorisation

Craig Walls and Roy Clarkson then presented on authentication which focused on the utilisation of OAuth and Spring Security. Interesting in the context of access control for RESTful services but fairly typical application of OAuth to provide SSO.

Next Generation Data

Html 5 application caching was touched upon and a demo of the previous expense application was performed using a disconnected device. Big Data was then discussed and placed in the context of the Spring Data project and its sub-modules. I’ve not looked at Spring Data in any great depth but really liked some approaches adopted by the Spring JPA sub-module (which was not covered in this session).

Next Generation Architecture

Finally, Tim Fox closed by discussing the adoption of asynchronous application architectures to deliver the massive scale that today’s applications are expected to achieve.

Thoughts

It was a really enjoyable session that was interesting and informative. A broad range of topics were covered by presenters who are clearly very knowledgeable.

I think overall, a really compelling vision of how developers will meet the challenge of delivering tomorrows applications was provided.


Continuous Integration

by John Turner

Posted on November 17, 2011


I have been building and maintaining continuous integration (CI) environments for several years now and would consider myself well versed in the practice. There really is a wealth of information on CI and people such as Martin Fowler and John Smart do a great job as advocates by providing a solid understanding and practical advice. Due to the amount of freely distributable software supporting the establishment of CI environments, acquiring knowledge of the subject is the biggest entry cost.

For that reason, it was with much anticipation that ‘Continuous Integration’ was published back in 2007 (shame on me for only reading it now!).

Getting Started

The book starts of with a gentle introduction to the subject providing a preview of the material to come. Chances are that if you have purchased this book that you already know roughly what CI comprises and how it works so you won’t learn a lot here. Still though, its good to lay some ground work and review that activities that typically occur as part of a CI system.

Read More
About - MonkeyLittle

Thoughts on Software Engineering, Infrastructure and everything in between.

Twitter Feed