The Perfect Loop
-
I was doing a code review last week for a simple change which I had asked one of my team member to do. We were looping through the details of the File we downloaded and doing processing depending up whether it's type A or type B (This code was already there)
foreach(MyfileInfo fil from files)
{
switch (fil.MyFileType)
{
case A:
//Do some work for file A
break;case B: //Do some work for file B break;
}
}All That I had asked that person to do was to to change the way File B was processed. And this is what I got. :(
foreach(MyfileInfo fil from files)
{
switch (fil.MyFileType)
{
case A:
//Do some work for file A
break;case B: **foreach(MyfileInfo fil2 from files) { switch (fil2.MyFileType) { case A: break; case B: //Do new work for File B. break; } }** break
}
}So if there were 50 files downloaded of type B the processing was happening 50*50= 2500 times :(( :((
- Richard Menezes
-
I was doing a code review last week for a simple change which I had asked one of my team member to do. We were looping through the details of the File we downloaded and doing processing depending up whether it's type A or type B (This code was already there)
foreach(MyfileInfo fil from files)
{
switch (fil.MyFileType)
{
case A:
//Do some work for file A
break;case B: //Do some work for file B break;
}
}All That I had asked that person to do was to to change the way File B was processed. And this is what I got. :(
foreach(MyfileInfo fil from files)
{
switch (fil.MyFileType)
{
case A:
//Do some work for file A
break;case B: **foreach(MyfileInfo fil2 from files) { switch (fil2.MyFileType) { case A: break; case B: //Do new work for File B. break; } }** break
}
}So if there were 50 files downloaded of type B the processing was happening 50*50= 2500 times :(( :((
- Richard Menezes
Why is he copying the code?! He could just call the function this stuff is in again, and have it be properly recursive as a bonus.
Jeroen De Dauw (blog | Twitter | Identi.ca)
-
I was doing a code review last week for a simple change which I had asked one of my team member to do. We were looping through the details of the File we downloaded and doing processing depending up whether it's type A or type B (This code was already there)
foreach(MyfileInfo fil from files)
{
switch (fil.MyFileType)
{
case A:
//Do some work for file A
break;case B: //Do some work for file B break;
}
}All That I had asked that person to do was to to change the way File B was processed. And this is what I got. :(
foreach(MyfileInfo fil from files)
{
switch (fil.MyFileType)
{
case A:
//Do some work for file A
break;case B: **foreach(MyfileInfo fil2 from files) { switch (fil2.MyFileType) { case A: break; case B: //Do new work for File B. break; } }** break
}
}So if there were 50 files downloaded of type B the processing was happening 50*50= 2500 times :(( :((
- Richard Menezes
-
That is a really brilliant bit of code. :rolleyes:
Just because the code works, it doesn't mean that it is good code.
Completely agree to you. And am the one responsible for their deliverables, as I am their lead. :(
Richard Menezes
-
Completely agree to you. And am the one responsible for their deliverables, as I am their lead. :(
Richard Menezes
Don't mention that there's an error, just show him the code and ask him why he shouldn't be fired for being a total moron! If he is actually any good, he'll laugh about it and say, "Oh yeah, you're right, maybe you'll have to let me go!"