Qt's Home

The Story of a french guy discovering the world

Day 3 - Data Structures/types, Testing, and a Brain-teaser

| Comments

Data Structures/types

Yesterday was the optionnal solo day, the day when we choose if we pair or not and work on some challenges. The code of the day was about Data Structures. I wont go as far as to try and explain all of that in detail in this blogpost but the idea is that you have all these data types in languages.
For example, a String is a chain of characters. It has a length, characters at specified index, and methods to compare Strings together, to change some character, and all the other operations you would want to do on such an object.
Once you get that far, it is what you call Abstract Data Structure. Then you implement it into a Data type, or a Data structure, according to if this ADT is a chain of separable elements, or an element in itself.

So, in short, we spent most of the day working to understand that 100%
And if you are curious about if I chose to work alone, I did not. I chose to work with the “Brother from another mother”, Armando.

Testing

In our lunch talks, Shadi introduced us to Test-driven development. The idea is that when you have an idea about what you want to do, and no matter how strong the feeling that you can code that is, you will just write tests to verify all that first.
Your algorithm will not work (Duh… You did not write any code yet), but you then just launch your script, and jump from error to error, deciphering and correcting them on the way, one by one, never thinking about the big picture. Then when you finish that, you check if the code does exactly what you want. If not, you write more specific tests.

Contrary to popular beliefs, people are really bad at multitasking, and so doing that allows you to complete simple tasks one by one, without multitasking, and empowering your debugging skills on the way.

So, Test driven development, I love you. (Not as much as my fiance of course, but we’re getting close)

A brain teaser

So, we worked on data structures, while using test-driven-development. While doing that we ended up redefining a method whose syntax is recognized and transformed by ruby’s Syntaxic sugar :

1
2
def []= (index, data)
end

which transforms into :

1
thing[3] = 4

So far so good.
Now, the problem we find is that in Ruby, even if you make that method return something, the second expression, the after-SS one, is returning 4.
I will tell you more when I realize what happens and why, but let’s say other cohorts did not know, coaches did not know, Sherif did not know, and we have to know… So let’s hunt for that!