Tagged: book

Test Driven Development

Another book from my huge TOREAD pile is Test Driven Development: By Example from Kent Beck. I learned about this method of development from the Extreme Programming book (also from Kent Beck) and I tried to take advantage of it during the coding phase of my thesis for bachelor’s. It’s a great way to develop software! Having your software covered by unit tests, you are way more confident with it. Along with this comes an assurance, that you didn’t break some part of your software when you add or change something. Without proper testing (either regression or unit) you just try stuff and see what happens. And it’s usually accompanied by glass shattering sounds and echoes of screaming people.

There is a metaphor (according to Steve McConnell in Code Complete) for software development that describes the process as drowning in tar pits with dinosaurs. I was a bit skeptical towards this metaphor at first, but it’s damn accurate when you code, but don’t test.

TDD Book Cover

Test Driven Development: By Example book cover

What exactly can you find in the book? In the first hundred pages, Mr. Beck explains test driven development on a case study of  WyCash — some software that handles money. It’s a step-by-step (and by step I mean really small steps) guide through the whole process. To be honest, I didn’t like this part of the book. It explains how exactly TDD should be done, but it’s sooo annoying to read about copying methods from one place to another and replacing return 5; by return x+y;.

The second part gets a little more interesting. It’s about xUnit — the family of widely used frameworks for unit testing (sUnit for Smalltalk, jUnit for Java, CppUnit for C++ etc). In this part, you will learn how the framework works with test cases, test suits and fixtures, the setUp() and tearDown() methods etc. Kent Beck is actually the original author of sUnit, the first framework from this family, so all information you get here comes directly from the source. He actually explains how to implement such a framework using TDD method.

And the last part covers TDD method in general, answers some questions that might spring to mind, usage of design patterns together with TDD and explains some situations you might find yourself in while using test driven development method.

RedGreen-Refactor

I’d like to point out one last principle — the Red-Green-Refactor. It’s a sort of mantra that will guide you through the whole book. It explains pretty much the whole routine of TDD in three steps (but you have to read the book to understand it properly!).

  1. Write a test — a test for some new functionality, that will obviously fail (hence the red sign)
  2. Make it work — write as little code as possible to make the test execute correctly (copy some code, fake the implementation, whatever, just make it work, turn the red to green)
  3. Refactor — at this point, the functionality is already done, so let’s focus only on the quality of design and implementation

It’s surprisingly easy, but extremely powerful, if you think about that in broader terms. I definitely recommend this book, maybe along with the Extreme Programming from the same author.

Advertisements

Brief History of Time

I finished all my exams a little early this term (and thank god for that!), so I could dive right into the huge pile of book that always emerges on my desk through the semester. The first one was Brief History of Time from Stephen Hawking which is a very interesting book.

Mr. Hawking talks about some interesting topics ranging from the very foundation of physics, it’s history and how our understanding of the universe evolved over time. There was Aristotle, who thought, that everything consists of the five  elements (earth, water, fire, air and aether – a divine substance that makes up the stars and planets). Then came Sir Isaac Newton with his laws and gravitation, Albert Einstein with theory of general relativity. Now we have quantum mechanics and string theory, that are based on the wave-particle duality.

The physicists went through all this in search of a grand unified theory, a theory of everything, one concept that will define the whole universe. The thing is, we’re not there yet and it might take some time. There are still things, that cannot be accurately described by the current principles of quantum mechanics or string theory.

The book also explores black holes and their role the big bang (as the beginning of the universe). I must admit, that I couldn’t understand it all when I read the book for the first time. Shame on me, I’ll have to give it a shot another time.

(In)finite Space-time

Another interesting thing, that was introduced in the book is a concept of a finite space with no beginning or end and how to imagine such a situation. You see, in life, everything has a beginning and everything, at some point eventually comes to an end. So it comes very hard to us to think in terms of a space that is not infinitely large, but has no beginning nor ending. Well, the example is right there! We live on it! Take for instance the surface of planet Earth. It’s definitely not infinitely large, but have you seen an end of the world somewhere? 2D surface of a 3D sphere is an example of space of finite size, but with no distinguished points of beginning or end. But how to extend it by one coodrinate to 3D/4D? Can we apply this principle to the space-time continuum or the time itself? Does it mean that our universe doesn’t neccessarily have a begining or end, that it just is?

Entropy

Another interesting principle concerns closed systems’ entropy. According to the second law of thermodynamics, entropy of an isolated system increases over time, it never decreases. Sounds familiar? Well, in case you’re a software engineer, I’m sure it does :-). By this law, code degrades and we cannot do anything about it — it’s physics! Unfortunatelly, for all spagheti-code producers, enthropy can also be reduced by increasing entropy somewhere else e.g. (surprisingly) putting some work to the system ;-).

It’s good!

There’s a lot more interesting theorems, thoughts and principles from physics, philosophy and many others areas of human knowledge. I think it’s definitely worth reading. Give it a shot!

Brief History of Time book cover

Book Cover