My own Private WTF
I've always wanted to submit something to The Daily WTF (come to think of it, I think I did but that was a long time ago) but today it just made me cry as I experienced my own private WTF. We had a developer leaving today and as I was doing a code sweep (looking at what was there, how the domain was shaping up, etc.) I came across this gem:
5 private enum DumbLevel
6 {
7 Dumb,
8 Dumber,
9 Dumbest,
10 Not
11 }
Then of course my curiosity was piqued and I just had to know how this enum was being used. This led me to this snippet:
19 if (cableCount == 0)
20 {
21 if (cableCount == 1)
22 {
23 if (PassesCount > 1)
24 {
25 if (i <= (_segments.Count - 2)) //for all but last
26 dumbLevel = DumbLevel.Dumbest;
27 else dumbLevel = DumbLevel.Dumb; //last segment
28 }
29 else dumbLevel = DumbLevel.Dumb;
30 }
31 else dumbLevel = DumbLevel.Dumber;
32 }
33 else
34 {
35 dumbLevel = DumbLevel.Not;
36 }
37
38 //calculate cable count and heat segment voltage based on the segment configuration
39 switch (dumbLevel)
40 {
41 case DumbLevel.Dumb:
42 cableCount = segment.GetCableCount(); //use # of tracers to determine cable count
43 AuditStep("Cable Count: {0} (based on count of Tracers identified)", cableCount);
44 AuditStep("");
45 heatSegmentVoltage = SupplyVoltage*Project.VoltageDrop*segmentPercentage;
46 AuditStep("Supply Voltage ({0}) * Voltage Drop ({1}) * Segment Percentage ({2})", SupplyVoltage,
47 Project.VoltageDrop, segmentPercentage);
48 break;
49
50 case DumbLevel.Dumber:
// code omitted for sanity
51 break;
52 }
This was by far the ugliest code I've seen on this project. The if statements alone started my blood to boil, but then when I started to see the case statements my brain turned to mush and that was my day done.
Sigh. Oh well, next week I'll introduce the team to the concept of inheritance so they can see how to make the case statements (and the craziest set of Enum values I've ever seen) go away. And Donald thinks he has it rough hiring new guys?
NOTE: sorry about the formatting, my VS settings are just hosed today.