The importance of the comma (and TDD)
April 7, 2010
Today I was improving some code switching (inmutable) lists to tuples, after the change I run the tests, one fails and triying to find the error I discover that the tuples are not really the same than an inmutable list, at least if they have one element. The example:
>>> t = ('ES')
>>> for i in t:
... print i
...
E (this is one element)
S (this is another element but I were expected both together, 'ES')
And:
>>> t = ('ES',) (Notice the comma)
>>> for i in t:
... print i
...
ES (one element, what I expected)
I don’t know if it’s a bug…, in lists is the same if you write or not the comma if only has one element.
Probably I had not discovered it until my app breaks, so remember, on tuples and lists with one element EVER use the comma too, and of course, TDD.
April 7, 2010 at 7:21 pm
I believe it is not a bug. There is some part in our code where we have documented something about that. I think it is in the callbacks module. Take a look at it
Thanks to TDD we have a good design and a great test battery
Keep on writing this blog mate!
April 9, 2010 at 2:55 pm
Oh my god, commas are devil guys my friend.
.
April 9, 2010 at 3:39 pm
Jey tio!!! Como va todo?? Como es que llegaste aqui??
Nos vemos!!!!
April 10, 2010 at 10:54 am
Trough migranpipa network ! You have a link on your blogroll …
.
See you !
April 10, 2010 at 11:07 am
Ahmsss… wow and you read it… it’s a little outdated
Cheers