Code Repeating
-
Take a look at the algorithm
function Process()
{
if(error!="")
{
// Some HTML code over 1000 lines with javascript
}
else if(update!="")
{
// Same like above :o with same f-king javascript
}
else
{
// Same 1000 of lines with same javascript.
}
}now my job is to make some change, for new requirements. the file is over 4000 lines. And reading over hour I actually failed to figure out how actually it works. Authority got that reason, I am not good enough. I agreed with them. Oh the reason to change the code was "Performance and incomplete verification"
-
Take a look at the algorithm
function Process()
{
if(error!="")
{
// Some HTML code over 1000 lines with javascript
}
else if(update!="")
{
// Same like above :o with same f-king javascript
}
else
{
// Same 1000 of lines with same javascript.
}
}now my job is to make some change, for new requirements. the file is over 4000 lines. And reading over hour I actually failed to figure out how actually it works. Authority got that reason, I am not good enough. I agreed with them. Oh the reason to change the code was "Performance and incomplete verification"
-
Take a look at the algorithm
function Process()
{
if(error!="")
{
// Some HTML code over 1000 lines with javascript
}
else if(update!="")
{
// Same like above :o with same f-king javascript
}
else
{
// Same 1000 of lines with same javascript.
}
}now my job is to make some change, for new requirements. the file is over 4000 lines. And reading over hour I actually failed to figure out how actually it works. Authority got that reason, I am not good enough. I agreed with them. Oh the reason to change the code was "Performance and incomplete verification"
Following from rob, take the three code blocks and diff them.
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
-
Following from rob, take the three code blocks and diff them.
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
-
Be very careful with code like this. You think it's the same 1000 lines but you may find one line has been changed. Seen this rubbish many times before, if you refractor to make sense of it, you'll miss that one line.
"You get that on the big jobs."
Yep I was worried about that too and I know the differences. And thinking of future I redesigned the entire page. Now even I need to change its only one function.
-
Or even better, throw them away. Rewriting from scratch can be less work in such cases.
And from the clouds a mighty voice spoke:
"Smile and be happy, for it could come worse!"And I smiled and was happy
And it came worse.Thats waht I did
-
Yep I was worried about that too and I know the differences. And thinking of future I redesigned the entire page. Now even I need to change its only one function.
As Rob says, make sure you are entirely sure of any changes between blocks and that they are maintained. I have encountered this many times while translating old classic asp applications to newer dotNet. I found that by splitting each of the cases into a separate text file and then running diffs on them tends to make the job much easier. The good part is that most devs who have done this used copy-paste and then made their modifications, so there is some hope for them yet...
I wasn't, now I am, then I won't be anymore.
-
As Rob says, make sure you are entirely sure of any changes between blocks and that they are maintained. I have encountered this many times while translating old classic asp applications to newer dotNet. I found that by splitting each of the cases into a separate text file and then running diffs on them tends to make the job much easier. The good part is that most devs who have done this used copy-paste and then made their modifications, so there is some hope for them yet...
I wasn't, now I am, then I won't be anymore.