|
Not a coding horror as such, but I fondly remember being given a 250 page software specification which ended
"Then a miracle occurs"
Cheers Phil!
|
|
|
|
|
|
Bed Time Story:
Once up on a time, there was
OriginalGriff wrote: 250 page software specification
who lived on paper happily, then it got transferred to code and ...
OriginalGriff wrote: "Then a miracle occurs"
The End!
Good Night
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
No, that's not a horror. That is someone giving stating what really needs to happen in order for the project to work.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
If the worst horror you could find in my company is ranked 10 and a moderate horror is ranked 1, I think I could rank this with 5:
Dim key As String
key= "N"
key= "linatipedi=" + "'" + key+ "'"
Dim rR As DataRow() = t.Select(key)
If rR.Length() = 0 Then
i = 0
Else
Try
For Each r In rR
i += 1
Next r
Catch
If i = 0 Then
Return True
Else
Return False
End If
End Try
End If
If i = 0 Then
Return True
Else
Return False
End If
|
|
|
|
|
adgonz wrote: I think I could rank this with 5
That is because VB's scale starts at 5
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 2 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
so one couldn't do any better in VB?
|
|
|
|
|
C#:
string[] codes = { "bad", "good" };
int rating = Array.IndexOf(codes, "bad") * 5;
Now do the VB one!
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 2 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
modified on Wednesday, April 15, 2009 11:05 AM
|
|
|
|
|
Um, the Array.IndexOf method looks a little off. Shouldn't it be Array.IndexOf(codes, "bad") ?
|
|
|
|
|
Yeah, now fixed, my brain needs rest now!
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 2 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
leppie wrote: Yeah, now fixed, my brain needs rest now!
...too much VB code for that one
|
|
|
|
|
I wouldn't know where to start, except for tossing out all those fancy brackets and semi-colons...
|
|
|
|
|
Leppie, I think you need to step away from the computer and get some rest.
|
|
|
|
|
Doesn't this actually gives a rating of 0 ("bad" is the first element, and 0 * anything = 0)?
Dybs
|
|
|
|
|
Looks like VB is scoring better,...
Dim codes() As String = New String(){"bad", "good"}
Dim rating As Integer = (Array.IndexOf(codes, "bad") + 1) * 5
It feels good to learn and achieve
|
|
|
|
|
Ah the expressive powers of VB and its native speakers
|
|
|
|
|
Oh, come on... Even VB can do this in one line plus exception handling...
Try
Return t.Select("linatipedi='N'").Length = 0
Catch
Return False
End Try
Man, if this is a 5, I'd really hate to see a 10...
Translation: Post one of the 10's! Heheh
|
|
|
|
|
Ian Shlasko wrote: Translation: Post one of the 10's! Heheh
A 6 or 7 (I'm not sure) is this code is from a function that should never had been called / written, so your better implementation is useless.
|
|
|
|
|
Ian Shlasko wrote: // *resists urge to type two ='s*
'Couldn't resist the temptation to use C++-style comments though.
|
|
|
|
|
Ack! I totally missed that...
Well, shows how much I've tried to get away from VB.
|
|
|
|
|
public static int GetAge(string birthDate)
{
DateTime birth;
try
{
birth = DateTime.Parse(birthDate);
}
catch (Exception ex)
{
throw new ApplicationException("Unable to read birth date.", ex);
}
if (DateTime.Today.Month < birth.Month)
{
return DateTime.Today.Year - birth.Year - 1;
}
else if (DateTime.Today.Month > birth.Month)
{
return DateTime.Today.Year - birth.Year;
}
else
{
if (DateTime.Today.Day < birth.Day)
{
return DateTime.Today.Year - birth.Year - 1;
}
else
{
return DateTime.Today.Year - birth.Year;
}
}
}
To be seen @ http://msdn.microsoft.com/en-us/library/bb126477.aspx[^]
UPDATE:
I was under the impression, Timespan had a TotalYears property. But now, looking at the logic, I can see why it does not have one.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 2 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
modified on Wednesday, April 15, 2009 10:40 AM
|
|
|
|
|
Yes. Ok. This is a bit easier on the eye...
public static int GetAge(string birthDate)
{
DateTime birth;
try
{
birth = DateTime.Parse(birthDate);
}
catch (Exception ex)
{
throw new ApplicationException("Unable to read birth date.", ex);
}
DateTime now = DateTime.Today;
if (now.DayOfYear < birth.DayOfYear)
{
return now.Year - birth.Year - 1;
}
return now.Year - birth.Year;
}
Oh, and it works around midnight, too...
|
|
|
|
|
Oh dear!
Another one bites the dust!
bad hint: TimeSpan
UPDATE:
Sorry
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 2 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
modified on Wednesday, April 15, 2009 10:58 AM
|
|
|
|
|
Part of the ugly code is due to the fact that TimeSpan does not have Months or Years properties;
[EDITED]
while it's MaxValue corresponds to more than 10 million days, without knowing the reference it can't decide on how many days fit in a month, and how leap years need handled.
[/EDITED]
modified on Wednesday, April 15, 2009 9:52 AM
|
|
|
|
|
Arggh, I could swear TimeSpan had those properties! Now I feel like the fool!
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 2 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|