In last Saturday I was on Global Day of Coderetreat in Krakow. Coderetreat is one day in year when programmers focus not on delivery new functionality but focus on good code quality. I think this is very important to stop for a moment and think how to be better programmer. And Coderetreat is that moment.
How looks this Coderetreat day?
All day is divide for 6-7 sessions of coding. In our case it was 6 sessions. In each session we try resolved Game of life problem. This is very simple problem but in Coderetreat main goal is not solving this problem but focus on process and code quality. One session take 45 minutes and then we have 15 minutes to discuss and sum what we did and how we did. Through all sessions we do ping pong pair programing with some constrains. Pair programming because we work in pairs, ping pong because we change keyboard between people. One person writes test, second writes code and first one does refactoring. Now it is time to say something about constrains. They can be very different. Some of them are easy, some are very hard. Below are all constrains form Coderetreat day in this year.
No primitives – Wrap all primitives and strings
In this session you don’t sent any primitive type between objects. So everything must be some kind of more complex object. On beginning is easy to put primitive types to our code. In future this behavior can cost us much more then we expect (not only our time). Now I will be thinking twice before I use primitives in my code. This first session was for me very productive, especially sharing my thought and conceptions about this problem with other woman.
All code is not mutable. Every method get some argument and return results – like function in math. In this case methods cannot modifies object state. For me this session was session out of my comfort zone. First time in my life I wrote code in LiveScript. This language is very similar to CoffeeScript, so it was nice to try other alternative. After this session I realized how easy was testing code like that. You call methods and only check if result equal to something.
Tell don’t ask – No getter, no setter, no properties
This time methods don’t ask for data from other object but tell this object do something. Each method in your code is void type (don’t return anything). This code is very hard to test. You have black box and you don’t know what is inside your object. Code is as much as possible encapsulate. Objects do only things, which are in they responsibility. There was one more think very interesting about this session. I wrote Ruby code with Java developer. It was experience which opened my mind. When we work in one technology (language) we think through this technology. Our mind focus on what we can do in this technology. And we don’t know that it is other solution, other way. So learning new thing, go out of your comfort zone helps us thinking out of the box. This is true, not only in coding but also in our lives. Big respect for my pair programming partner for trying new things.
3 minutes circles
We had only 3 minutes for finish one TDD circle. Test, code, refactoring. If we don’t finish at time we must remove all code for this one circle. This session helps me to understand that in work we sometime think about one big problem. We have lot of useless code, which don’t work because “it is not finished yet”. I can say that in this session we worked in small MVP (Minimum Viable Product) session. After each 3 minutes we have working functionality. It was small functionality but it’s working.
No loops, no conditions
This was last session. This time we could not speak to each other. Even more. We could not write and show anything. Only tests and code can talk to us. And really, we do this everyday in work. You don’t have person which write code all the time available to ask about something. You need to figure out through code and tests of course, how this part of application work. In this session I worked with my best friend. I thought that we know each other so good, so we can read in our minds. But when we can not talk, we can not also choose one way to resolve problem. Each of us was thinking about this problem in different way. Only good, descriptive test and good, descriptive code can help us in this situation. All names, comments, tests are very important. This is must have!
Ok, this is it. This was very productive day for me. I learn new things. Coderetreat one more time open my eyes how important is good quality code. I wish every programmer to be part of this event. See you soon. All best! Bye.