Looking over an open source library I found the following code:
The code would be equivalent with:
interval void SomeMethodName(FooIncoming that)
if (that.numAnswers > 0)
{
SupportClass.IListSupport.AddAll(this.answers, this.numAnswers, (IList) ((ArrayList) that.answers).GetRange(0, that.numAnswers - 0));
this.numAnswers += that.numAnswers;
}
if (that.numAuthorities > 0)
{
SupportClass.IListSupport.AddAll(this.answers, this.numAnswers + this.numAuthorities, (IList) ((ArrayList) that.answers).GetRange(that.numAnswers, that.numAnswers + that.numAuthorities - that.numAnswers));
this.numAuthorities += that.numAuthorities;
}
if (that.numAdditionals > 0)
{
SupportClass.ICollectionSupport.AddAll(this.answers, (IList) ((ArrayList) that.answers).GetRange(that.numAnswers + that.numAuthorities, that.numAnswers + that.numAuthorities + that.numAdditionals - (that.numAnswers + that.numAuthorities)));
this.numAdditionals += that.numAdditionals;
}
...
}
What I loved in this code was:that.numAnswers – 0
that.numAnswers + that.numAuthorities - that.numAnswers
that.numAnswers + that.numAuthorities + that.numAdditionals - (that.numAnswers + that.numAuthorities)
I don’t understand why a developer would make something like this. Any number subtracted with 0 will have the same value like before. Also if you add a number and after that you subtract that same value you will get the original value.The code would be equivalent with:
that.numAnswers
that.numAuthorities
that.numAdditionals
The second thing that I noticed is the ‘that’ argument. I’m not a fan of this kind of names. Maybe a name like ‘incoming’ or something similar would be better.
Even Java programmers sometimes get drunk.. :)
ReplyDelete