Sunday, August 28, 2011

The Clean Coder

I enjoyed this tiny book very much. Robert C. Martin lays down here many important issues that many programmers should be aware of.

I will not even try to write a review of the book - I just want to point out some things that influenced me. In general, I like soft-software books, I mean without the code, just mentoring. I like that Mr Martin is recalling the days of his early programming adventures, when he was a high school geek or 2* years old passionate hacker. That means to me that he has a distance to what he does even though he is a passionate and claims himself being a professional. Someone I want to learn from about programming.

Number one (and this an interpretation, not a quote) you don't have to be experienced to be a professional. I know it sounds silly. But there is, I guess, a space for unexperienced-professionals. What I mean is that everyone can behave professionally. Experienced-professionals for me are the ones who tried to behave professionally, they succeed, and they follow their path no matter what. The attitude is the power.

When I was 19 years old I remember working with so called "experienced" programmers. They were supposed to teach me, and I was supposed to learn. Thankfully there are many sources of knowledge and I could take a different path. I can easily see now the difference between an experienced and experienced-professional developer. Thanks to that book I can also define it.

Second thing is about prioritizing and learning. Never more ocasional priority inversion. If there is a task that is more important, don't do other one because it's easier. Don't even follow the internal dialog, about how right is it to work on another task while the most important one can wait a bit.

One sentence was really nice. It was about practicing after work. He recommends 3 hours a day (quite a lot I must admit). I will put it in bold: Practicing is what you do when you aren't getting paid. You do it so that you will be paid, and paid well.

And one more thing. If you don't follow TDD (or any other discipline that is as effective as TDD), you can stop calling yourself a professional. I like that he says that with no illusions, that there may be another way of being a good programmer who doesn't write automated tests for his/her code. No, there is not.

Anyway, I recommend that book a lot. I'm still on my way to be professional, but I guess that this book indicates one of the best ways to succeed.

And the cover is there for a reason, astronomy has a lot to do with programming.

Friday, August 12, 2011

Basic needs of programmers

If anyone thinks that the most important thing for programmers is the ability to code - they're wrong. Even if it is a super interesting project that involves millions of users it will fail if programmers have no possibility to meet their basic needs. And I'd like to stress the word possibility.



How many of us, programmers, were sitting in front of a computer for hours without eating, drinking or going to the toilet? Do you remember this project that you had once, when you just have to finish in three day and one test is not passing or you want to make this query run even faster that it could? Or just refactor the code before pushing it so it shines more that it needs? And you were this hacking-freelancer that will do the best project ever! Yes - a freelancer working from home.

It works completely different in the office. You start working with a coffee, water, little chitchat with everyone. You see people going one after another to the toilet, eating snacks, walking around. And then on of them brings the news: there is no running water in the builiding! OMG!! Panic!! How are we gonna pee after first three coffees? We have to go home!! Everyone needs to pee in the exact same moment! Dear God!! I didn't drink anything but maybe I'll need to pee! I have to go home! There is no water running!! NO WATER!!

Forget about programming. This is not freelancing at home, this is working in the office. Even if you don't have to pee, you will leave just because the toilet is out of order. And there is always that argument of Maslow's pyramid.

BTW. I need to pee (excrete) and I'm the only one left in the office... shit...

Thursday, August 11, 2011

Khan Academy subtitles

Thanks to sharing knowledge and open-community I discovered a very badly page ranked website called Khan Academy. Of course if I had followed TED more carefully I would have known about it before.

I mentioned open-community because it was Melodie, friend from Couch Surfing, who showed me the Academy. Moreover, we found it in a paperback Creative Commons magazine... just saying that I was there because of ECOOP 2011 (programming conference) makes me dizzy. Too much knowledge sharing! I will write a summary of ECOOP soon, but let me get back to Khan Academy now.

The Academy is simply a great place to learn. One teacher, good teacher, trying to explain the magic of math, physics, biology, chemistry, organic chemistry, astronomy, economics, banking and more in a very approachable... especially math. I realize that many people know about it, but I didn't so I'm still under its influence. By now I have gained around 130,000 energy points, and 67 badges! What a great way to make humans want to learn. Shame that I cannot share my rank using some kind of a widget.

As I finished a degree in computer science, I must say that the way this guy explains math is just awesome. Anyway... there are subtitles. Everything is subtitled in English, which is a base language for others. I translated first video to Polish! I was shocked when I saw that this is the first video translated to Polish on the Academy. Ever!

We Polish people need this Academy for our kids! It should be subtitled in Polish to terminate the stagnation of our education system! OK... I don't believe in that, but it can start something, can't it? Why didn't I have a teacher like that when I was in high-school? Or better, why the hell didn't my teachers know about it? It is already 5 years old!

I think I'll write a petition to students' governments of English Philology departments around Poland. Who knows, maybe together we can translate it in one term, cause by myself I'd need 46 years to finish...

Polacy, do roboty! :)

Friday, July 22, 2011

filet gem just released!

We finally found some time to finish the work on the gem for acceptance testing - filet. It's available via our employer github account: https://github.com/xing/filet

filet is a dsl for acceptance testing on top of Test::Unit.


Hope you'll find it useful!

Thursday, July 7, 2011

How to re-implement a cartesian product algorithm

Yes. So did I waste my time, or not? Of course not. I just got a big slap in my programming face. Un pollazo. I over-implemented a cartesian product, without even noticing it. But it's fantastic, I can learn every day :)
I was even showing it around to my friends at work. They didn't notice too! Maybe this algorithm could be used for something else. But I have no fucking clue where :D
Of course I learned a lot, but still, feel a bit stupid. Do not overdo and read more - that is the lesson of today!

Ou programming... my dear...

Fast! iterative algorithm for generating permutations from sets' single elements

I like it. I like this one. Last algorithm for this problem (here) was O(n^3). Now it's O(n). It may mean two things: first one was very shitty, or that the second one is really good. Probably both are true.

I came back home, without a laptop. With one hand holding the Algorithms book (I really recommend that one) and with notebook and a pen in the other. I choose notebook and pen. It did the trick.

I know I masturbate on that issue, but it's fun. After some furious paper programming I got here:


I asked myself 3 questions at the beginning:
  1. How many times "1" will be first?
  2. How many times "4" will be in the result?
  3. How many times "5" will be in the result?"

I wanted to answer that questions without the use of any offset indexes kept in memory in other array. Keep it simple: what do I know about my input data?
So my answers were like that:
  1. If I take all the sizes of following tables and multiply them, I'll get 12.
  2. Always, cause it's a single element array, so 36 (total possible permutations.
  3. The same as answer number one. 6 times in cycle of 3, 18.

The main conclusion was that I can fill the results array column by column instead of row by row. All permutations will be fully calculated at once, at the very end. No gathering the permutation by permutation and then pushing it to the results. No no no, that needs indexes and traveling across the array many times. This idea dropped the complexity from O(n^3) to O(n).

Cycles, subcycles, offsets. The most important thing was to calculate a proper index in the result table and stick the current argument element exactly there (IBID). No more talk, code is below and benchmark is on the gist comment.

Tuesday, July 5, 2011

Iterative algorithm for generating permutations from sets' single elements

My friend asked on facebook for a iterative algorihm that would generate all possible strings from given sets in a way that for ex. given {a,b,c}, {d,e}, {f} should produce {adf, aef, bdf, bef, cdf, cef}.



There is still a recursive call moved to bump_next method. I'm trying to get rid of that one and make it fully iterative.
That was much fun doing it, as it has some tricky parts. Probably faster algorithm for that already exists, but I couldn't find any. Lots of fun.

Sunday, July 3, 2011

Do you find this post helpful?

I remember the last November. I tried to export my photos from Picassa. My requirements were: keep the folders structure and the changes I made with the Picassa tools. Anyone would do it faster than me, because in Picassa you can export only one folder at the time. But I didn't want to do it sequentially. I was looking for an automated tool to handle this process. Unfortunately I didn't found one. Querying Google for an answer showed that many people failed searching for this functionality.

So I expressed my frustration.

It is funny and sad to see that 10 out of 10 people found this answer helpful.
Reasons:
  1. How could my answer possibly help anyone?
  2. If it actually didn't help them, then the functionality of the "Was that helpful?" button is ambiguous. It works more like voting on stackoverflow. Actually, as a side-effect of it's ambiguousness, it works exactly like voting, saying: Yeah! Damn right! We feel the same! which has nothing to do with answering the problem itself.
  3. People frustrated by software seem to solidarize, ready to support someone who expresses their own frustration.

For me, the important conclusion from that silly story is that I would never use "Was that helpful?" on any of my applications. The question, I guess, should be more narrow, for instance Did that answer helped you to solve your problem? or Did this answer your question?. I think it's an issue for social informatics study.

Saturday, July 2, 2011

Croissant equation and Prolog.

Computacional geometry and computer graphics are subjects I rarely play with, but I like their connection with the real matter. Today in CosmoCaixa museum I found mathematical equation for a croissant. That was quite amazing - full exhibition devoted for math and equations describing natural shapes. I see croissants often in Spain and I have to admit that I never thought about their shape as a mathematical expression.


This can be ordered like that:


This can be expressed as:



and be calculated with use of:
I wouldn't recommend to find solutions for this equation in Ruby, so the example is in ECLiPSe CLP. It is a great tool (environment) for solving contraint logic problems. It's also fun. For me.

Friday, July 1, 2011

RSpec like DSL in Test::Unit for acceptance testing.

I have project where I have to use Test::Unit. Fine, but I am used to RSpec DSL, especially when it comes to user stories (features). So, here is simple module that shows how you easily can use RSpec-like expressions in default testing framework.


Just save that module in a file that will be required by your test helper and include in you test unit spec.


With Test::Unit::Feature you have a simple DSL. Soon we'll publish in on github as a gem. Now it works with Ruby 1.8.7 and Rails 2.3.10. I didn't test it with the latest stuff.

Done with Jorge :)

Wednesday, June 29, 2011

I'll try again. Polyrhythms and programming.

Welcome again to my regular blog. Keeping the frequency of one post per year is very difficult. Still, I manage.

I opened myself a door to blog not only about programming. All those posts about JavaScript and "so on" that I did through whole last year... life is much more interesting than that.

Recently I started drumming lessons. I played for two years some time ago and then after another two years gap I picked up the sticks again. This time with a different attitude: regular lessons with a teacher. It's been three months by now that I practice 1,5 hour twice a week + almost everyday exercices on the practice pad. I learned the important lesson: regular practice is the ONLY way. Maybe that will help me to maintain a blog.

I also moved to Barcelona, Spain. I work here as a software developer (mostly doing Ruby on Rails) at XING AG. That also gave me a big possibility to even more regular programming and a new approach to it. I'll leave this subject for later though.

Polyrhythms. Strange rhythms. Transposed rhythms. That is where my head is lately. Many times I practice patterns that at the beginning seem impossible (for me) to follow. I still lame (only three months of classes) but I realized that these practices have a big impact on my analytical part of brain. It is a funny feeling. When I started classes, first thing when I got a new pattern to learn I tried to analyze it somehow. I counted at loud and did the beat with my feet and hands. It worked, but...

...sometimes this approach fails! Once I could feel really hard the limitation of analytical approach to try to grasp a rhythm. Everything was fine until I started to learn bossa nova rhythm with paradiddle on hands. When I tried to analyze it before (or while) playing my brain was just frying. All the programming cells tried to accomplish the parsing of the partiture, but with big red failing dot at the end.

The way was, as my teacher told me, to let it go. Close the eyes, reset the mind. Keep the beat with legs only for half a minute. Slowly. Use the body to understand it. And then do the sticks rudiment on top of it. Without thinking!

I was amazed. It worked just fine, the body knew what to do. I knew the bossa nova, I knew the paradiddle, but I had to let it be to make it happen together...

The great part of this story it that now (after two months from what happened...) I can analyze this rhythm with no single problem. Play it with pure analytical approach, no art-spirit involved. Of course it sounds worse this way, and I prefer go with da flow... I wish to know how all that drumming thing impacts my programming skills... it has to be deeply connected.