sexta-feira, 22 de julho de 2011

TDD Language Proposal

Introduction

Yesterday  I saw the inspiring The Last Programming Language lecture of Uncle Bob and extracted the following concepts:

  • Languages are always restricting our way to write code.
  • The last big thing in programming was TDD.
Proposal

joining the two concepts, I wondered if we could have a programming language in which we restrict the programmer to do TDD. But how could this language be structured? how could we inject TDD on the language desing?

Doing TDD is doing tests firsts and write only the code necessary for it to pass. What if we could, on the same file, write a unit test and the line that makes it pass? Obviously we would gain a great amount of time from shifting from test file to production file as we do today, but what else?

The main concept of this proposal is to value the test and its connection to the production line of code, in such a way that we would loose the direct control of the final code, the language will compile it for us.

Ok, a bit crazy I know, but it is possible to have such a language? lets wander:

[METHOD] AddTest [TEST_STATEMENT], [PRODUCTION_LINE]

Example:

Buy AddTest "throws if cart is empty", 
             throw if cart.size == 0

ok, simple enough, but where does cart come from? well, it would be inferred by compiler and possibly added  as a parameter of the method Buy.You might ask what about a more complex example, in which different tests are testing the same line? or if we are testing things inside a loop?

This is where Homoiconicity comes along and instead of repeating lines you contextualize the line of code in order to know where it will be inserted on the final code, example:

Buy AddTest "throws if item is not in stock", 
            [Buy.Iteration.cart] throw if item.NotInStock

Writing this line makes the compiler add an "for" on the Buy method that iterates the cart parameter and add the line that checks if its in stock or not.

Conclusion

If we preach "we should only write production code if its to pass an unit test", why not make it a language restriction and say "The only way to write production code is writing its test", and then we would take TDD really seriously and forget frameworks, IDEs tools and metrics that we have build to accommodate a language dysfunction, its the same thing as implementing polymorphism on C.

terça-feira, 5 de julho de 2011

Last Social Responsible Moments

                                                      image source

Software Developers underestimate their profession and should occupy a more responsible role in society. After the Agile Brazil 2011 my mind got hit by several thoughts that leaded to one direction: What's the purpose that drive developers?

So I asked my self that question and expanded to all other activities that motivate me: Physics research, 3D modeling, game developing and Agile. One thing that they have in common is the ability to change things in a powerful manner. Physics do it through facts that change our mental reality, 3D modeling and games through operations that change a fictitious and malleable world and Agile through an effective organization of people.

After a while I concluded that they all where driven by a general frustration. Thinking way back, when I was around 12 years old, I remember that a had the desire to change the world. But as I was growing up this thoughts where demoted to a feeling of naivety, but in fact all I did since then was trying to comply with this primal desire - "Oh well, I can't change the world ... but I can refactor this code to two lines!" . Any developer out there feel the same way?

A common word that we hear in the agile world is local optimization, and I believe the majority of Software developers are doing so in their jobs (me included!). When I work for a company I am constrained to the company's objective, and all my ideas are narrowed down to the profitable ones. But think for a while in what's  your company doing to society? Extracting Oil? Entertaining? Selling cereal? If those are all good to society we are local optimizing the world's problems, think about the worse of them: poverty, education, health and so on. Do you believe that online entertainment is above them?

Making society happy doesn't necessarily mean that it's good to the society, see coca-cola for example. When living in a capitalistic world we can make things that will increase the overall happiness and profit at the same time, looks like a win win case, right? But we can, and did many times, create a society demand where it didn't exist, and creating a new market might not be a healthy solution to the worlds problems.

At the end we might be only giving panem at circenses to the world, developers and entrepreneurs should go deeper then any medium class shallow desires. I believe that society needs a red pill and it could be our job to build them.

Since our alternatives to the classical capitalism are far from reality I still have to make money and try to balance the equation and dedicate time to this, but its getting hard to don't feel guilty about doing nothing.


References:

Joshua Kerievsky - Prioritizing Happiness

Agile Brazil 2011 - Lean Startup Open Space