Well, try to debug a piece of code where all the variables are named Pippo01, Pippo02, Pippo03... I guess you will change your idea ;P
Bye By(t)e ;-)
Well, try to debug a piece of code where all the variables are named Pippo01, Pippo02, Pippo03... I guess you will change your idea ;P
Bye By(t)e ;-)
In Pisa University (The most important Computer Science faculty in Italy) we still use to name variables of examples and simple code snippets "Pippo" from the Italian name of "Goofy", the Disney's Character... :-D This is a really old habit since my CS teacher at the high school used to do so when she was studying at the university :laugh: But the best part is that when I do code review or debug on old code I usually found that programmers that comes from Pisa's University uses this habit in their professional life :laugh:
Bye By(t)e ;-)
modified on Thursday, September 16, 2010 12:15 PM
This is my first job: Ten years of services just few moths ago. Still a long long time before retirement... ...If I ever reach the Retirement age. ...And if "Retirement" will be still available here in Italy at that time. (OMG) :doh:
Bye By(t)e ;-)
That is exactly what he said when I've told him to add the argument check :laugh: .
Bye By(t)e ;-)
Yes, as you said, the code snippet I've posted is not complete (As I told I've not posted the actual code) However the coder was NOT minding to use the 'if' form to ensure return 'true' or 'false' independently from what value is in m_bUsed (moreover this is guarantee to be 'ture' or 'false' only by the code that modify it). A more rational implementation using the 'if; form could be the following:
bool IsUsed ( int iHandle )
{
if ( iHandle < MAX_CFG )
return ( true == g_vConfigurations[iHandle ].m_bUsed );
else // iHandle >= MAX_CFG
return false;
}
or (in a more 'compact' form someone can like):
bool IsUsed ( int iHandle )
{
retrun ( iHandle < MAX_CFG )? ( true == g_vConfigurations[iHandle ].m_bUsed ) : false;
}
Someone can complain about the logic of returning false when parameter is out of range instead of an exception but we can use them (that is a portion of code that recently ported to C++ from C using an "incremental" approach) and stating that "you cannot be using something you don't have" is not so wrong ;P
Bye By(t)e ;-)
I found this pearl while doing a peer code review. This is not the actual code but it gave the "idea"...
typedef struct
{
// Lot of stuffs..
bool m_bUsed;
} CONFIG;
#define MAX_CFG 10
static CONFIG g_vConfigurations[MAX_CFG];
...
bool IsUsed ( int iHandle )
{
if ( g_vConfigurations[iHandle ].m_bUsed == true )
return true;
else
return false;
}
A logic genius... And notice the lack of argument value check before using iHandle in IsUsed() function ;P .
Bye By(t)e ;-)
if(guess == random && !(guess != random)) Can we call it an example of "psychotic" programming? :laugh: :laugh: :laugh:
Bye By(t)e ;-)
well... maybe the coder wished to cover ALL cases... :laugh: :laugh: :laugh:
Bye By(t)e ;-)