Click here to Skip to main content

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, embarrasing 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 PinprotectorOriginalGriff6-Oct-13 23:25 
GeneralRe: The most creative log ever PinmemberGuy Lavi7-Oct-13 0:01 
GeneralRe: The most creative log ever PinprotectorOriginalGriff7-Oct-13 0:07 
GeneralRe: The most creative log ever PinmemberGuy Lavi7-Oct-13 0:54 
GeneralRe: The most creative log ever PinprotectorOriginalGriff7-Oct-13 0:57 
GeneralRe: The most creative log ever PinmemberGuy Lavi7-Oct-13 1:01 
GeneralRe: The most creative log ever PinmemberFreak307-Oct-13 23:44 
GeneralRe: The most creative log ever PinprofessionalFredrik Bornander10-Oct-13 5:40 
GeneralRe: The most creative log ever PinmemberKornfeld Eliyahu Peter7-Oct-13 2:58 
GeneralRe: The most creative log ever PinmemberGuy Lavi7-Oct-13 3:11 
GeneralRe: The most creative log ever PinprofessionalBrisingr Aerowing7-Oct-13 5:36 
GeneralRe: The most creative log ever PinmemberRage11-Oct-13 1:18 
GeneralRe: The most creative log ever PinmemberGuy Lavi12-Oct-13 21:39 
JokeRedundancy at its finest [modified] PinmemberEdward 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 PinmemberKornfeld Eliyahu Peter6-Oct-13 10:03 
GeneralRe: Redundancy at its finest PinprofessionalBrisingr Aerowing6-Oct-13 15:33 
GeneralRe: Redundancy at its finest PinmemberRyanDev7-Oct-13 3:32 
GeneralRe: Redundancy at its finest PinprofessionalBernhard Hiller6-Oct-13 23:14 
GeneralRe: Redundancy at its finest PinmemberEdward Giles12-Nov-13 0:34 
GeneralRe: Redundancy at its finest PinprotectorOriginalGriff6-Oct-13 23:29 
GeneralRe: Redundancy at its finest PinmemberRyanDev7-Oct-13 3:33 
GeneralRe: Redundancy at its finest Pinmember0bx8-Oct-13 0:48 
GeneralRe: Redundancy at its finest PinmemberMacSpudster5-Nov-13 6:47 
JokeHow to zero-pad a number? PinmemberSortaCore1-Oct-13 1:27 
GeneralRe: How to zero-pad a number? PinprofessionalNagy Vilmos1-Oct-13 1:49 
GeneralRe: How to zero-pad a number? PinmemberSortaCore1-Oct-13 1:55 
GeneralRe: How to zero-pad a number? PinprofessionalPIEBALDconsult1-Oct-13 5:18 
GeneralRe: How to zero-pad a number? PinprofessionalRichard Deeming1-Oct-13 5:27 
GeneralRe: How to zero-pad a number? PinprofessionalPIEBALDconsult1-Oct-13 7:27 
GeneralRe: How to zero-pad a number? PinprofessionalRichard Deeming1-Oct-13 8:09 
GeneralRe: How to zero-pad a number? PinprofessionalPIEBALDconsult1-Oct-13 11:43 
GeneralRe: How to zero-pad a number? PinprofessionalRichard Deeming1-Oct-13 11:57 
GeneralRe: How to zero-pad a number? PinmemberBig Daddy Farang1-Oct-13 12:23 
GeneralRe: How to zero-pad a number? [modified] PinprofessionalPIEBALDconsult1-Oct-13 14:44 
GeneralRe: How to zero-pad a number? PinprofessionalRichard Deeming2-Oct-13 2:44 
GeneralRe: How to zero-pad a number? PinmemberSortaCore2-Oct-13 3:07 
GeneralRe: How to zero-pad a number? PinprofessionalPIEBALDconsult2-Oct-13 4:12 
GeneralRe: How to zero-pad a number? PinprofessionalRichard Deeming2-Oct-13 4:19 
GeneralRe: How to zero-pad a number? PinprofessionalPIEBALDconsult2-Oct-13 4:28 
GeneralRe: How to zero-pad a number? PinmemberSortaCore2-Oct-13 10:21 
GeneralRe: How to zero-pad a number? PinmemberSortaCore1-Oct-13 11:48 
GeneralRe: How to zero-pad a number? PinprofessionalGrimlock3-Oct-13 0:19 
GeneralThat really makes a difference Pinmembermav.northwind26-Sep-13 21:51 
GeneralRe: That really makes a difference PinmemberGuyThiebaut2-Oct-13 6:31 
GeneralRe: That really makes a difference PinprofessionalAthari7-Oct-13 7:50 
GeneralCan I copy that? PinmemberBotCar25-Sep-13 3:32 
GeneralRe: Can I copy that? PinprotectorPete O'Hanlon25-Sep-13 3:46 
GeneralRe: Can I copy that? PinmemberNicholas Marty25-Sep-13 5:12 
GeneralWhy is my code so slow?? Pinprofessionalvonb24-Sep-13 2:39 
GeneralRe: Why is my code so slow?? PinprofessionalJörgen Andersson24-Sep-13 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web04 | 2.8.150327.1 | Last Updated 27 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid