Code Overtones

Tuesday, August 25, 2015

Before fixing performance issues

We, in computing, have come across the phrase "Premature optimization is the root of all evil" one time or another. But sadly we don't seem to internalize it in our work. I'm reminded of this whenever a developer proposes a performance fix in the code.

Before fixing any performance problem, I like to reconsider it because of following two reasons.

1. Performance problems may be easy/difficult to solve depending on the situation, however all of them have one thing in common - they have a very clear goal. There's a number that we have to optimize - be it response time, FPS or memory footprint of the app. This makes the performance problem very rewarding to solve, just like a video game. There's a score to be achieved and we just have to find a way to achieve it. The developer can focus on that single number and forget everything else, in order to get a rush of endorphin. Therefore I think developers are biased towards fixing the performance problems than any other kind of issues.

2. When developers strive to achieve that magic number while fixing the performance problem, they tend to sacrifice a lot of other important things. Software design principles, coding guidelines, readability of code, documentation - all are considered secondary during the exercise. As a result, even though the software might run faster or lighter after the fixes, the maintainability of the code has been sacrificed during the process, which is a greater loss in long term.

I don't want to undermine the importance of performance issues, because the speed and memory footprint of a software are very important for it to be usable. However not all performance fixes achieve the same improvement in software usability. Therefore they should be evaluated carefully before fixing.

I take the advice of Guido Van Rossum, when it comes to evaluating performance issues:
* Are you sure it's too slow? Profile before optimizing!
* The universal speed-up is rewriting small bits of code in C. Do this only when all else fails.

Wednesday, June 17, 2015

No exams, Yes video games

The psychological studies on the subject of self esteem show that when children are criticized at an early age for their behavior, it affects their self esteem negatively for the rest of their lives. If that's the case, what effect does it have on children when they are told that their answers to the questions in the exam were wrong. This obviously leads a child to believe that he/she has done something wrong. Moreover, they find that they have done things "wrong", while others have done them "right". Although, all that has happened is they haven't understood the concept of the subject matter sufficiently. An adult can appreciate how minor this small lack of understanding is; but for a child it could represent a "social status" in their social circle of friends. It could represent their validation in the eyes of their parents. When they are told that they are wrong, it definitely registers as a negative feeling with them. The failure registers more strongly in their mind, than the reason behind that failure. This doesn't help them getting the correct understanding of the subject.

How can we then teach the children in a way that will convey to them that their understanding of the subject is not right, and yet reinforce this in a positive manner?

I look towards the video games for answer to this question.

In a video game, you cannot make progress through a level unless you have gotten the rules of the game right and have beaten the game AI. If these games of rules represent the concepts in academic subjects, then they will be the best replacement for exams. This mechanism of discovering your own mistake doesn't stress on the fact that you were wrong before, it instead highlights the fact that you eventually got it right and lets you proceed to next puzzle/level. Try to remember the excitement you felt, when you beat a game level on your own after failing at it many times. This definitely registers as a positive event in the player's mind. Also while figuring out how to beat the game, the player automatically realizes his/her own mistake thus understanding why he/she was wrong before.

It will take time to creatively translate academic material into a playful and artistic manner, and then design puzzles on top of them. But it is definitely worth doing. It's the right application of the computing technology to further the educational system of our society.

I am very hopeful looking at the games like Dragonbox Elements that in not too distant future video games will rid our educational system of that nightmarish phenomenon called 'Exam'.

Saturday, October 11, 2014

Quotable quotes

Memorable quotes from some books I read in recent past

"It is the spectator, and not life, that art really mirrors"

"You know more than you think you know, just as you know less than you want to know."

"To get back one's youth, one has merely to repeat one's follies"
The Picture of Dorian Gray - Oscar Wilde

“The only thing you have to do in this life is die,... Everything else is a choice.”
The Age of Miracles - Karen Thomson Walker

"Without Pain, How Could We Know Joy? (This is an old argument in the field of Thinking About Suffering, and its stupidity and lack of sophistication could be plumbed for centuries, but suffice it to say that the existence of broccoli does not in any way affect the taste of chocolate.)"

"... all felt Romantic, but not romantic."

"The dead are visible only in the terrible lidless eye of memory."

"You don’t get to choose if you get hurt in this world, old man, but you do have some say in who hurts you."

"quantum entanglement of tubes and bodies"

The Fault in Our Stars - John Green

"A man’s life was five dogs long, Cortland believed. The first was the one that taught you. The second was the one you taught. The third and fourth were the ones you worked. The last was the one that outlived you."
UR - Stephen King

"It is better to be lucky. But I would rather be exact. Then when luck comes you are ready."
Old Man And the Sea - Earnest Hemingway

"No one in the world ever gets what they want and that is beautiful"

"People who live in glass houses should shut the fuck up"

"I’d come to see my rig for what it was: an elaborate contraption for deceiving my senses, to allow me to live in a world that didn’t exist. Each component of my rig was a bar in the cell where I had willingly imprisoned myself"

Ready Player One - Ernest Cline

"magic formula of a great game — easy to learn, difficult to master"
Masters of Doom - David Kushner

"You’d be happy, in the same pitiful way someone like our friend Ritchie is. Nothing affects you, and you affect nothing."

"Maybe she’s afraid that if I can’t have her, I won’t want her."

I Am the Messenger - Markus Zusak

"I’m reminded of a wise man who once said that he would never want to join a club that would have him for a member."
The Ghost Brigades - John Scalzi

"Because substitutes that cannot be substituted are generally called identities"

"Bobby seems to be asking, in bold Helvetica type and in all earnestness"

Self-Reference Engine - Toh EnJoe

"... you’ve seen a room where the gravity has failed twice in different directions"

"You love because you want to need someone the way you did when you were a child, and have them need you too."

"It struck me that if you could train your mind to operate when awake as it does in your sleep, then you could dream while you were awake, and see a different world"

Only Forward - Michael Marshall Smith

"No one ever sees what is behind the mirror."

"That which, being added to another does not make it greater, and being taken away from another does not make it less, is nothing"
The History of Calculus and its conceptual development - Carl Boyer

"People thought languages were just substitution puzzles"
Damocles - S. G. Redling

"The only way to beat the competition is to stop trying to beat the competition."
Blue Ocean Strategy - W. Chan Kim, Renee Mauborgne

"Alicia made her mouth into a ~"

"Immortality is a mass event"

"Anticlimax is the currency of mortality"

Anticopernicus - Adam Robers

"... number-one goal of all computer users is to not feel stupid."

"The essence of good interaction design is to devise interactions that let users achieve their practical goals without violating their personal goals."

The Inmates are running the Asylum - Alan Cooper

Sunday, April 06, 2014


There is a Men's restroom right across the Service Canada office in Guy-Favrau complex in downtown Montreal. I happened to visit it one morning. As I was washing my hands, a shabbily dressed man besides me tried to get my attention. He asked if I speak English. As usual my first instinct was to ignore the man who looked like a homeless bum. But if this guy was asking for help just because he couldn't speak french, I didn't see any harm talking to him. We just stepped out of the restroom after drying our hands under the hot air blower. Suddenly he started speaking in very good English. That's not usual on the streets of Montreal.

He said, "I arrived last night by a bus from Halifax, Nova Scotia. My bus arrived at Berry UQAM and I was supposed to go to Boston on a connecting bus as soon as I arrived. But the bus got cancelled and they misplaced my luggage. So my bags haven't arrived yet. I'm going to Boston to do a procedure on the tumor in my stomache." This is where it got confusing to me. He opened his jacket, pulled up his sweatshirt and showed a big tumor sticking out of his stomache. It was big. The size of his head maybe. I tried my best to not show my disgust. He covered it up and continued telling his story.

"I need to get my medications. The pharmacist here told me that my Insurance provider in Halifax will not work here. Since I didn't expect getting stranded in Montreal, I didn't bring much money with me. I had $120 with me. The pharmacist asked for $148."

All this time, he was showing me a paper, which had something written on it in blue pen. I could make out words like 'Berry UQAM', timings, the sum total of some dollar figures, etc. Everything else was in very illegible handwriting.

"I'm running $28 short."

... At this point, I found myself confused. Since the beginning I assumed this is a homeless man trying to get some money from me. But I wasn't prepared for such an elaborate story, certainly not one substantiated so well. Turning down a homeless man is pretty easy, but ignoring a stranded sick traveler can definitely make you feel guilty.

I tried to rationalize the situation. To begin with, I cannot say whether this man is lying or saying the truth. The probability that a given unknown person would lie or tell the truth will be 50%. Then in my mind I drew a table. On the left all the things that indicated he was lying and on the right all the things that could prove he wasn't. I was filling this table as he was presenting me his story. The actual tumor (or what he showed me of it), was a big entry in the right column. Eventually I decided that even if there is a possibility that he is telling the truth and I walk away; I'll always feel guilty for being a skeptic and valuing $28 more than the helplessness of a sick person. After I seeing the situation in this way, I knew what to do. I wasn't as worried about being fooled for $28 as I was about being irrational. Also, I wanted to know the truth.

So I took out my wallet and gave him $30. He asked for my phone number to return the money, which of course I didn't give. And then I started looking for his reaction to get a hint of the truth.

He said, "Thank you. It's good to know there are people.. blah blah" I cut him short and made my exit.

To me it appeared textbook response. If you are asking strangers for money to treat the pain from an illness, because you are stranded in a foreign city, then you are in a very stressful situation. And then you find a person who just solves that problem by giving you all the money you need. ...and you don't show any emotion. You give a boilerplate response. It was at this moment that I thought I had enough data to prove to myself that he was lying.

Later, I tried to put myself in his shoes as a conman and tried to imagine how such situation could be set up.

It is easy to gain sympathy as a stranded Anglophone in Montreal who can't speak or understand french. Showing someone a big tumour in your stomach, increases your credibility a lot and gains you lot of sympathy instantly. Moreover, anyone would want to avoid looking at an abnormal growth in someone's body, so most people won't tend to overanalyse it, if at all. Putting everything he was saying on a piece of paper, somehow made it more credible. I overlooked the fact that all of it was written by hand and in illegible handwriting. He could have scribbled all of it on his own. Furthermore, the price he was asking was just right. Not too small, to raise the doubt that he was just a petty beggar. Not too large, to outweigh my conscience.

Yes, most likely I was conned. ... I would never know.