Wednesday, 8 August 2012

Book - Software Craftsmanship: The New Imperative

As you probably know, I recently joined a new community called Cambridge Software Craftsmanship. I finished to read one of the movement inspiring book and in this post I would like to share the most interesting things I found in it.


Even if the book is quite old considering the speed at which the world of the computer programming change, I have to say that the book is still very actual.

The book start introducing the definition of software engineering from IEEE:
IEEE - Software engineering is the application of a systematic, disciplined, quantifiable approach to development, operation, and maintenance of software; that is, the application of engineering to software
The most successful project using a complete and robust software engineering approach was the space shuttle software. 
Space shuttle software was 420000 lines long with 1 error. It last 11 versions with a total of 17 errors. Commercial programs of equivalent complexity would have 5000 errors.
This is a proof that using a rigid and structured approach is very effective at developing safety critical systems. However the cost are usually exorbitant and in the average software development this approaches does not work very well. It is in this context the the term Craftsmanship has been introduced and compared/contrasted with the term software engineering.
Craftsmanship is a solution to the problem of delivering robust, high-quality applications to users in a relatively short time for reasonable cost. 
Software engineering is a solution to a different set of problems, involving life or safety-critical systems, real-time and embedded systems, and systems engineering projects. In these types of problems craftsmanship approach is not the best one. Incremental development and evolutionary delivery are not feasible strategies.
Other sentences about this topic:
Good enough software is a logical extension of the ideas of software engineering
Software engineering makes us forget that what really matters on a project is the skill, knowledge and experience of the individual software developers.
Craftsmanship is not a rejection of science and engineering, but rather a subtle blending of man, machine, and knowledge to create useful artifacts.
Software craftsmanship is a mindset and an attitude, rather than a body of knowledge.

This is the main point. At the foundation of everything, regardless of if you consider yourself a craftsman or engineer, there is the constant interest in improving yourself, in becoming better in what you do and learn from others and share with others. 

Learning and mentoring is a big topic and the following are significant sentences:
Working with masters is the best way to learn a craft.
Learning from each other is an essential part of software development.
Learn how to collaboratively deliver software is one of the key challenges new developers face when they start working on real projects.
Software development works best when the developer has a deep understanding of the requirements, design and source code.
Claims that good developers can pass the certification exams are made, but the hidden implication that passing the exam means you are a good developer is really the classical problem of confusing correlation with causality. The fact that a developer has passed a certification exam says nothing about that person's ability to develop a useful application, only that he has learnt how to pass the exam.
The concept of a single, responsible engineer signing off the complete work is not feasible for software.
If a person became an apprentice to a great developer instead of studying for a degree, maybe the outcome would be even better.
Rather than being known for their degrees, memberships, or certificates, the real credentials for developers consist of the applications on which they have worked.
Enthusiastic beginners not only renew the craftsmen, but also challenge the craftsmen by bringing in new ideas from outside. The power of this synergy has to be felt to be believed.
One of the traits associated with true mastery of any craft has been humility. Master craftsmen are always willing to learn and are able to admin their own mistakes.
Master practitioners ask lots of questions and then deliver what you really need (as opposed to what you actually asked for).
The key questions is: "Has he infected his colleagues with his enthusiasm and passion for the craft of software development?".
By reading and asking intelligent questions, apprentices will be able to pick up most skills without being formally taught.
Maintaining and enhancing live applications give journeymen the best environment for improving their craft.
Experiences developers should be involved in the creation of training courses for other developers.
Practise without feedback just reinforces errors.
In found particular interesting and challenging the following:
Software craftsmanship rejects the software engineering notion that it is impossible for one person to know the entire system. Instead, it celebrates virtuosity and talent.
One of the keys to high productivity is in-depth knowledge of the entire application
It is actually a fact that the most effective people on a team are usually the people that know a lot about the system. The problem here is how can you achieve this, how can you improve the communication across developers in order to achieve more productivity. The following sentences is an answer to this question but is it feasible?
Working in a closely knit team where everyone reviews one another's work on a daily basis means that, even without trying, a journeyman will gain a real breadth of experience about software development.
The software engineering metaphor makes us believe that software development is manual labor. It makes us believe that the division of labor is a good thing that should be used in software development. It makes us believe that there are standard best practises that everyone should adopt. This notion is not true, however.
By creating artificial specialities with narrow skill sets, software engineering makes it impossible for one person to understand the entire application. Rather than encouraging developers to cross-train so that they can understand all of an application, software engineering promotes the myth that what is needed instead is good documentation. Unfortunately, although documentation is very good for recording decisions and agreements, it is a very ineffective way of preserving and communicating detailed knowledge of how a software application actually works. Software engineering has given documentation a very bad name. Many projects practically run without any documentation because inexperienced developers rebel against this software engineering view.
I understood that the key here is to have small teams of great and passionate developers that are usually much more effective that a huge team with average developers.
Small teams produce better software.
Journeymen prefer to work in small team. There is little value in being part of a very large team, because their contributions are unlikely to stand out.
Software engineering fails to pay attention to the most important component of the software development process - the people. The most likely reason for this omission is that individuals show up only in small teams.
Technical knowledge is mush less important than the ability to integrate well with the rest of the development team. 
If co-location is impossible for your project as it often is for truly global projects, you need to pay special attention to communication. Make sure that you take the time to gather people together so that they can get to know one another. Although travel costs may be high, they will be offset by fewer misunderstandings and much smoother communication when people return to their normal locations.
One really good developer is more valuable to your project than five average developers.
It is a good practice to reward exceptionally productive developers, because they make the difference between success and failure.
An another important topic in the book is the relationship between users and developers:
It might seem counter-intuitive, but designing for a single user is the most effective way to satisfy a broad audience. Develop a close working relationship with a small number of users, and then create the best possible application for these users. Then the application will be ready for release to the mass market.
Customers just have to start insisting on high-quality, robust software and choosing their developers based on their reputation for delivering that kind of software.
Craftsmen enjoy being able to delight their users with the speed with which they can make changes.
A professional care about the quality of his job and base his reputation on that:
Craftsmen build their reputations based on the quality of what they deliver to their customers.
It is better to have a functional, rock-solid, minimal-feature release than an unstable, buggy release with features that don't quite work properly.
Good developers know how long things take and are rarely willing to sign up for delivering the impossible.
It is hard to find developers with 30 or more years of experience. Few remain as developers for a long time. This exodus is a real problem.
You should encourage you developers to get involved in local user groups and technical associations.
Once a developer is confortable presenting locally, the next step is to start presenting at conferences.
Technology is an another important topic related to the application lifecycle management:
Software craftsmanship values long-lived technologies and programming languages.
Very few applications have a planned life of less than five years, whereas few software development tools are designed to be stable over that time frame.
Why don't developers focus their attention on becoming really good at using the existing tools?
Think long and hard about why you want to use a new technology.
Treat software as capital. Make maintenance a priority during the initial development.
Start making your applications testable.
If you are going to build in flexibility, make sure that it will be needed. If you cannot predict how much flexibility will be needed, then make the application as easy to change as possible.
Consider whether your development tools are likely to remain stable for the lifetime of the application.
The major challenge when designing for testing and maintenance is to build sufficient diagnostics and instrumentation into an application.
The challenge the software craftsmen face is one of keeping up with all of the evolving technology so that they can create high-quality, robust applications even when using bleeding-edge technologies.
I would like to finish with some extra general sentences:
Good developers are more valuable than their managers.
Craftsmen take pride in completion.
Trust the craftsmen you know to recommend other craftsmen.
Evaluate Craftsmen based on their reputations and portfolio.
Creating an orphan application is not a good way to enhance one's reputation.
This book inspired me and I hope you found this summary useful and interesting. Everyone of this sentences is a good starting point for a discussion so feel free to add comments. I am eager to know your opinions on this topics.










Tuesday, 24 July 2012

My Green Band: Clean Code

Today, my green band is arrived :)




Do you know what is it?

The famous Uncle Bob (Robert C. Martin) wrote two brilliant books:

  • Clean Code
  • The Clean Coder

He is mission is to help raising the level the profession of the Software Engineers and surely one of the most important thing is learning how to write clean code.


He suggests to dress the green band as a way to remind yourself about the importance of writing clean code so that all the time you are in the process of submitting crap code you can feel bad about it. Evil? I will find out.


It is a little bit too tight but I hope will become more comfortable after a while.


You can "buy" the band and other gadgets at the following address:
http://butunclebob.com/ArticleS.UncleBob.GreenWristBand

Happy coding :)



Wednesday, 4 July 2012

Cambridge Software Craftsmanship community was born


Yesterday, a new great local community was born!


It is a pleasure for me to have taken part of the inaugural event and I would like to thanks the organizer Alastair Smith to believe in this initiative. I am a strong believer that communication, sharing of knowledge is a key part to be a better professional and a better person in any fields and for this reason I strongly believe that any initiative oriented in this direction can only be a success.

The main idea of the community is to follow the principles of the Software Craftsmanship movement and organize events in order to learn and master the craft. 

If you want to learn more about the movement Wikipedia is a great resource:

A another must is the interview to Robert C Martin:


Finally, there are some books that inspired the movement:

I still have to read the last two books but I will do it relatively soon.

The plan of the group is to organize every first Tuesday of the month a round table in order to discuss about various topics. We usually select various topics, we prioritize and then we discuss them.

In the future, once located a suitable venue, we would like to organize hands on lab when we can actually code in pairs. This is by far what I am most interested about. 

If you live in Cambridge or around the city and you would like to be involved in these initiatives please don't hesitate and join us. The more we are, the better.

This is a community for those who believe that being average is just not good enough.

Wednesday, 27 June 2012

A Snake game entirely written in assembler

Snake is always been for me my hello world program. I implemented it in many different languages Basic, C, C++, Java and Javascript. But I didn't limited myself at high level languages. At the second year of university (something like 7 years ago) I actually implemented it entirely in assembler MASM in roughly 600 lines of code. It is so old that the variables and the comments are in italian :)


Unfortunately I can't run it (and provide a screenshot of the game) because is using a library called compatib that I am not able to find. Friends can confirm that this code actually worked at the time :)



This is the main procedure:



This is the game loop:


This is the procedure that print the snake on the screen:


The entire code is available in my repository on copeplex.

This program is very old but I still remember the feeling after I implemented it in one evening and in particular the satisfaction of the following day when I showed it to my class mates. They were shocked!

This is what I call fun!



Sunday, 17 June 2012

BigInteger multiplication - A recursive approach

Recently in the Coursera course "Algorithms: Design and Analysis, Part I" I come across to an interesting introduction of the divide and conquer technique using the multiplication between big integers as an example. My hands started to itch immediately. I would have to try to write an implementation!

The Problem

Given two integers x and y of any size return the product of them.

The Idea

The simplest algorithm is what we are all used to do, writing down all the products and then add them together. This is know as the "Long Multiplication" algorithm.

Using a simple calculus is easy to understand that the problem can be solved using a recursive approach. 

It is always possible to write x and y in the following way:



So the product can be calculated as:


This means that we can calculate the product xy calculating 4 small products (ac, ad, bc, bd) in a recursive way.

More info:

The Implementation

For simplicity, I decided to represent a number using a string encapsulated in a class called MyBigInteger.

This is the implementation of the multiplication algorithm in C#:


In order to implement the algorithm I also had to implement the sum between two big numbers using the classic mathematical way:


The full code is available in my personal repository (BigIntegerMultiplication).

Tests


Improvements

In this example, we have a recursive tree with 4 branches. In reality it is possible to have only 3 branches using a simple trick (Karatsuba multiplication).

Instead of calculating ac and bd directly it is possible to calculate first:


and then calculate (ad + bc) using a subtraction:


In order to implement this slightly improved version of the algorithm is necessary to implement the subtraction of two big integers. I didn't wanted to do it, so I don't have an implementation to share.

Conclusion

The purpose of the exercise was to prove to myself that I was able to build the algorithm based on the original idea presented in the course. I would like to let the reader aware that the .NET framework already implement a comprehensive class that implement the operations on big integers in a quick way: BigInteger.


Saturday, 26 May 2012

.NET Debugging in Visual Studio 2010

Everyone involved with .NET programming know how to use the basics of the powerful debugger available in Visual Studio 2010. It is pretty easy to use and very useful. However, very few people explore all the tools available and sometimes you can be very surprised to discover something truly amazing that you was completely unaware of. This post want introduce some of that things.

Show Next Statement

When you are in the middle of a debugging session it can be easy to get lost. You can switch back to the next statement using the "Show Next Statement" option.


Debugging .NET Code

You can debug the .NET Framework code. You need to check "Enable .NET Framework source stepping" and "Enable source server support." in the debugging options and you need to add a specific symbol file server.



Pinning the Data Tips
Everyone know that when you hold the mouse on a variable during the debugging you can explore the value inside a data tip. However, nobody knows (me included), that this data tip can be pinned. This is very useful in some circumstances!



Immediate Windows and Intellisense

A another important thing to consider is the immediate windows. You can run complex code and update variables during the debugging session and there is full
Intellisense support (using CTRL + SPACE to activate it).


Intellitrace

Intellitrace is a very sophisticated debugging tool that allow you to go backward in time and reduce the number of times you have to restart your application for the debugging. This is a feature only available in Visual Studio 2010 Ultimate.


More information on MSDN.

Thread Support

In Visual Studio 2010 there is a specific windows (Thread Windows) that allow you to explore the various threads that are running at the specific point of time and easily switch between them. You can even give a name to a thread in order to be able to later recognise it.




It is also possible to see in which line of code each thread is, using the "Show Thread in Source" option.



Debugger Canvas

This is available only for Visual Studio 2010 Ultimate. I never tried it but I have to say that it looks awesome. It allows to see the context of the debugging session in a much broader way as a set of interconnected code balls. This tools is extremely powerful and support also 
multi-threading applications where each thread is represented by balls of the same colour. Finally, it is possible to export the diagram as an XPS file.




Tuesday, 22 May 2012

DotNetToscana and Gadgeteer

Saturday 12 May there was a DotNetToscana event about Gadgeteer and .NET Micro Framework. I was in Italy that time and I participated. I really have to say that the event was great. Gadgeteer represent a very interesting platform for creating prototypes and simply for having fun. The various modules are still quite expensive but in the future I could maybe try to do something in this area especially to put under test some of my new knowledge about artificial intelligence.

The most interesting part of the day was when we moved a rover.

We saved that moment in a video :)


Here few pictures:





For other pictures, videos, material about the event you can visit the following page:
http://www.dotnettoscana.org/net-micro-framework-presenta-gadgeteer.aspx

A big thanks to Marco Minerva and Marco Dal Pino for preparing and running this brilliant event.


Friday, 4 May 2012

Book - Code Simplicity

This book is awesome !!!

It is very short (less than 100 pages) but contains a lot of truth about software design in a very condensed way. At the end, it defines a list of laws and rules that any good software engineer or architect need to know and follow constantly to create really valuable and long-term software.



It starts with a comparison that I believe is very effective to underline how complex the software is:
Windows 2000 was 30 million lines of code, something like writing a book of 200 million of words - over five times the size of the Encyclopedia Britannica.
Everyone can easy agree with the following sentence:
The average computer program is so complex that no person could comprehend how all the code works in its entirely
The author believe that the software design can be defined as a science. Even if you don't agree with him, the list of laws and rules presented in the books are still extremely helpful and important.

The most important foundational law of the book is:
The purpose of software is to help people
This fundamental law bring towards the three goals of a science of software:
  • To allow us to write software that is as helpful as possible
  • To allow our software to continue to be as helpful as possible
  • To design systems that can be created and maintained as easily as possible by their programmers, so that they can be - and continue to be - as helpful as possible
The book then define the Equation of Software Design that the author call the Primary Law of Software Design:

D = V / E

This equation should help to prioritise the work and can be summarised in this way:
The desirability of any change (D) is directly proportional to the value of the change (V) and inversely proportional to the effort involved in making the change (E)
that can be reduced to:
It is more important to reduce the effort of maintenance than it is to reduce the effort of implementation.
So, nearly all decisions in software design reduce entirely to measuring the future value of a change versus its effort of maintenance. The quality level of your design should be proportional to the length of future time in which your system will continue to help people.

Then, the book introduce the Law of change:
The longer your program exists, the more probable it is that any piece of it will have to change
explaining the typical mistakes that software designers make when attempting to cope with this law:
  • writing code that isn't needed
  • not making the code easy to change
  • being too generic (Over-engineering)
Perfect easy of maintenance is impossible but it should be the ultimate goal.

Finally, the Law of Testing:
The degree to which you know how your software behaves is the degree to which you have accurately tested it
I strongly recommend this book. I definitely insert it in my restricted list of favourites books.