|
hmm... The only thing I'd argue with is doing all that then adding the adding the "Add" method to the end. Being used to the ternary operator, I could read it fairly quickly, but to make it more human readable, perhaps an assignment a variable should have been assigned to the chosen list, then the second line should have implemented the Add method.
In ANSI C in college, they encouraged this type of stacking behavior. In fact, they demanded it, but it was more of a performance issue than simply being "clever."
|
|
|
|
|
Came across this piece of code in a source library
string sParam1 = _param1;
string sParam2 = _param2;
int iOut1 = -1, iOut2 = -1;
if (Int32.TryParse(sParam1, out iOut1) && Int32.TryParse(sParam2, out iOut2))
{
Int32.TryParse(sParam1, out iOut1);
Int32.TryParse(sParam2, out iOut2);
}
Me and my colleague ended up !! believe me or not this piece is written recently by the one known as the lead!!
|
|
|
|
|
Nothing unusual to see here. He's just checking twice to make sure it's really parsable.
It's like when I'm just about to exit my flat and close the door behind me, I check if I have the keys with me. It doesn't really matter that I already checked that before embarking on my way to the door. I just need to make sure.
You know? Like really, really sure. Sometimes checking only once is just not enough.
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925
|
|
|
|
|
Why do you think it's called "double-checking"?
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Exactly what I was trying to say, I guess!
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925
|
|
|
|
|
The person who wrote this code is probably suffering from OCD[^].
|
|
|
|
|
That poor guy got very confused with terrible threading issues!
|
|
|
|
|
Bad enough its VB, they are even using a select for two cases when an Or would have sufficed.
Select Case stringvalue.ToLower
Case "a", "b"
rslt = Format(CDbl(AmountB), "#,0.00")
GoTo skpy
If CheckPPSO Or CheckPRS Then
If DownPayment >= Downpayment_Cutoff Then
If CountryAbbr = "CA" Then
rslt = Format(GetPrice(CodeLetter, "XYZ"), "#,0.00")
Else
rslt = Format(GetPrice(CodeLetter, "X"), "#,0.00")
End If
End If
skpy:
End If
End Select
This was in the middle of a larger switch with 246 case statements. Good thing it's Friday, I've stopped processing data after coming to this.
Why are people who do this even allowed near computers
No comment
|
|
|
|
|
Ooh, nice, the "comment out code using a goto" pattern!
|
|
|
|
|
At least the compiler should have shown you where this one was (warning: unreachable code detected). But yes that is pretty bad!
|
|
|
|
|
I don't code in VB, so I could be well off the mark here, but isn't that GoTo also going to take you to a point where your next statment is "End If", without having actually executed the corresponding "If"? Couldn't that have "interesting" effects?
|
|
|
|
|
Its probably safe in that sense, the compiler will most likely just put make the End If the target of a Jump instruction.
For a loop, it would be horrible. In C++, that could cause RAII to break, but in VB its probably safe. No guarantees though (but where GOTO's are used, most guarantees are probably invalid anyway).
|
|
|
|
|
It's a long time since I've used "proper" C or C++, but in C#, it won't even compile as the label is out of scope of the goto
|
|
|
|
|
String amount = "123";
var actualAmount = Convert.ToDecimal(String.Format(CultureInfo.InvariantCulture ,"{0:N2}",
Convert.ToDecimal(amount, CultureInfo.InvariantCulture)),CultureInfo.InvariantCulture);
|
|
|
|
|
You've got more chance of peeing on JSOP's porch than you have of understanding why the developer did this.
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
|
|
|
|
|
I think the developer was unhappy with the performance of Decimal.Round so decided to implement it using strings, as we know computers prefer working with text rather than numbers...
|
|
|
|
|
Rounding is a hard, let's go shopping!
|
|
|
|
|
I can sort of understand the point.
It looks like it is trying to round the amount down to 2 decimal places.
Odd way to go about it though.
Reminds me of the old "man with a hammer" quote.
|
|
|
|
|
Unfortunately the original code monkey was using the hammer on his own skull.
Software Zen: delete this;
|
|
|
|
|
public virtual object DeepCopy(object value)
{
return value;
}
|
|
|
|
|
|
Or just give the method a decent name, like DeepCopyIfNeeded .
|
|
|
|
|
Manfred R. Bihy wrote: Looks like the coder should have thrown a NotImplementedException[^] here instead.
One of the most underused exceptions when developing software. I use it all the time when I am scoping out classes, but not ready to implement the inner code yet.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
It's a great way to detect that something isn't quite done yet.
Cheers!
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925
|
|
|
|
|
Yes, but if he used a NotImplementedException then it wouldn't be a coding horror. Unless, of course, it was still there when released to customers.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|