Showing posts with label Software. Show all posts
Showing posts with label Software. Show all posts

19 October 2011

Threads Question

I heard a question this week, and I thought it would be nice sharing it here, I did solve it, however, I'm not 100% sure I did it right :), so here it is:
What is the maximum value the variable i can get in each case below, assuming that it's a global int initialized by zero (int i=0) and the code in each case is running on 2 threads?

case1:
while(i < 1000)
{
    i++;
}
case2:
while(i < 1000)
{
    ++i;
}

case3:
while(i++ < 1000);

case4:
while(++i < 1000);

09 July 2010

Code Smells

I believe that writing a well structured code is one of the hardest important capabilities that a programmer should develop to achieve high quality code, however, sometimes we are forced to code dirtily since time equals money, not to mention how hard is it to understand and modify someone's code who didn't think that others would read it.
Code Smells are some rule thumbs that helps pin-pointing to a location of weak code, some code smells are contradictory, but learning them will help pointing to a code which needs improvements, and more important, keeping them in mind will prevent you from writing stinky code in the first place.
Here you can find a list of the most frequent code smells, simply and well explained, and here you may find some more detailed info.