Click here to Skip to main content
12,066,952 members (55,156 online)

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: The most creative log ever Pin
Freak307-Oct-13 23:44
memberFreak307-Oct-13 23:44 
GeneralRe: The most creative log ever Pin
Fredrik Bornander10-Oct-13 5:40
professionalFredrik Bornander10-Oct-13 5:40 
GeneralRe: The most creative log ever Pin
Kornfeld Eliyahu Peter7-Oct-13 2:58
memberKornfeld Eliyahu Peter7-Oct-13 2:58 
GeneralRe: The most creative log ever Pin
Guy Lavi7-Oct-13 3:11
memberGuy Lavi7-Oct-13 3:11 
GeneralRe: The most creative log ever Pin
Brisingr Aerowing7-Oct-13 5:36
professionalBrisingr Aerowing7-Oct-13 5:36 
GeneralRe: The most creative log ever Pin
Rage11-Oct-13 1:18
memberRage11-Oct-13 1:18 
GeneralRe: The most creative log ever Pin
Guy Lavi12-Oct-13 21:39
memberGuy Lavi12-Oct-13 21:39 
JokeRedundancy at its finest Pin
Edward Giles5-Oct-13 22:49
memberEdward Giles5-Oct-13 22:49 
I found this code in the My.Power extension for Visual Studio:
Public ReadOnly Property BatteryPercent()
            ' This code will retrieve the BatteryLifePercent property and convert it to a percent.
            Get
                If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
                    Return "100%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
                    Return "99%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
                    Return "98%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
                    Return "97%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
                    Return "96%"
...
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then
            Return "6%"
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then
            Return "5%"
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then
            Return "4%"
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then
            Return "3%"
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then
            Return "2%"
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then
            Return "1%"
        Else
            Return "NA"
        End If
    End Get
End Property
What idiot would write this?
How about:
If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
   SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
   IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
   Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
   Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
   Return "NA"
Else
   Return FormatNumber(SystemInformation.PowerStatus.BatteryLifePercent * 100, 0) & "%"
End If
P.S. Code shortened by about 96%

modified 6-Oct-13 3:59am.

GeneralRe: Redundancy at its finest Pin
Kornfeld Eliyahu Peter6-Oct-13 10:03
memberKornfeld Eliyahu Peter6-Oct-13 10:03 
GeneralRe: Redundancy at its finest Pin
Brisingr Aerowing6-Oct-13 15:33
professionalBrisingr Aerowing6-Oct-13 15:33 
GeneralRe: Redundancy at its finest Pin
RyanDev7-Oct-13 3:32
memberRyanDev7-Oct-13 3:32 
GeneralRe: Redundancy at its finest Pin
Bernhard Hiller6-Oct-13 23:14
professionalBernhard Hiller6-Oct-13 23:14 
GeneralRe: Redundancy at its finest Pin
Edward Giles12-Nov-13 0:34
memberEdward Giles12-Nov-13 0:34 
GeneralRe: Redundancy at its finest Pin
OriginalGriff6-Oct-13 23:29
protectorOriginalGriff6-Oct-13 23:29 
GeneralRe: Redundancy at its finest Pin
RyanDev7-Oct-13 3:33
memberRyanDev7-Oct-13 3:33 
GeneralRe: Redundancy at its finest Pin
0bx8-Oct-13 0:48
member0bx8-Oct-13 0:48 
GeneralRe: Redundancy at its finest Pin
MacSpudster5-Nov-13 6:47
memberMacSpudster5-Nov-13 6:47 
JokeHow to zero-pad a number? Pin
SortaCore1-Oct-13 1:27
memberSortaCore1-Oct-13 1:27 
GeneralRe: How to zero-pad a number? Pin
Nagy Vilmos1-Oct-13 1:49
professionalNagy Vilmos1-Oct-13 1:49 
GeneralRe: How to zero-pad a number? Pin
SortaCore1-Oct-13 1:55
memberSortaCore1-Oct-13 1:55 
GeneralRe: How to zero-pad a number? Pin
PIEBALDconsult1-Oct-13 5:18
professionalPIEBALDconsult1-Oct-13 5:18 
GeneralRe: How to zero-pad a number? Pin
Richard Deeming1-Oct-13 5:27
professionalRichard Deeming1-Oct-13 5:27 
GeneralRe: How to zero-pad a number? Pin
PIEBALDconsult1-Oct-13 7:27
professionalPIEBALDconsult1-Oct-13 7:27 
GeneralRe: How to zero-pad a number? Pin
Richard Deeming1-Oct-13 8:09
professionalRichard Deeming1-Oct-13 8:09 
GeneralRe: How to zero-pad a number? Pin
PIEBALDconsult1-Oct-13 11:43
professionalPIEBALDconsult1-Oct-13 11:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 8 Feb 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid