Click here to Skip to main content
15,880,392 members

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: Threading horror Pin
geoffs16-Dec-08 19:43
geoffs16-Dec-08 19:43 
GeneralIterating an Enum? Pin
justastupidgurl13-Dec-08 5:05
justastupidgurl13-Dec-08 5:05 
GeneralRe: Iterating an Enum? Pin
PIEBALDconsult13-Dec-08 5:54
mvePIEBALDconsult13-Dec-08 5:54 
GeneralRe: Iterating an Enum? Pin
justastupidgurl13-Dec-08 20:24
justastupidgurl13-Dec-08 20:24 
GeneralRe: Iterating an Enum? Pin
PIEBALDconsult14-Dec-08 5:44
mvePIEBALDconsult14-Dec-08 5:44 
GeneralRe: Iterating an Enum? [modified] Pin
notmasteryet15-Dec-08 4:11
notmasteryet15-Dec-08 4:11 
GeneralRe: Iterating an Enum? Pin
PIEBALDconsult15-Dec-08 11:01
mvePIEBALDconsult15-Dec-08 11:01 
GeneralHow to be popular among your colleagues PinPopular
notmasteryet11-Dec-08 15:30
notmasteryet11-Dec-08 15:30 
1. Always repeat obvious things twice.
Enum NumberSize
    Bit_8 = 8
    Bit_16 = 16
    Bit_32 = 32
    Bit_64 = 64
    Bit_128 = 128
End Enum

2. Hide all comments behind visible portion of screen - your co-workers do not need them.
Public Function CBin_Number(ByVal InputNumber As Double, ByVal InputNumberSize As NumberSize) As String 'converts large numbers into strings 8, 16,32, 64, or 128 characters long
    Dim FinalBinNumber As String

3. Show that 128 zeros and ones can be easily fit in 48 bits mantissa.
Dim TempNumber As Double = InputNumber
Dim PlaceCounter As Integer

4. Always remind that computer cannot be trusted even with simple operation of subtraction.
Select Case InputNumberSize
    Case NumberSize.Bit_8
        PlaceCounter = 7
    Case NumberSize.Bit_16
        PlaceCounter = 15
    Case NumberSize.Bit_32
        PlaceCounter = 31
    Case NumberSize.Bit_64
        PlaceCounter = 63
    Case NumberSize.Bit_128
        PlaceCounter = 127
End Select

5. Do not listen anybody (even yourself) and choose most interesting way to handle the task.
If (TempNumber - (2 ^ PlaceCounter)) > 0 Then
    PlaceCounter = 127
End If

6. Be simple – the String class is the best thing since sliced bread.
Do Until (PlaceCounter < 0)
    If (TempNumber - (2 ^ PlaceCounter)) >= 0 Then
        FinalBinNumber = FinalBinNumber & "1"
        TempNumber = TempNumber - (2 ^ PlaceCounter)
    ElseIf (TempNumber - (2 ^ PlaceCounter)) < 0 Then
        FinalBinNumber = FinalBinNumber & "0"
    End If
    PlaceCounter = PlaceCounter - 1
Loop

7. Always add checks for weird cases
    If FinalBinNumber = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" Then
        FinalBinNumber = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 or Error: Number Too Large"
    End If
    Return FinalBinNumber
End Function

Public Shared Function ReaderRev(ByVal BinString As String) As String 'converts strings into ASCII character string

8. Show that you are bilingual, e.g. by using QBASIC and VB.NET constructs
Dim tempstring As String = Replace(BinString, " ", "")
Dim tempbinstr As String
Dim TempChar As Char

9. Do not reveal variable types: SByte can be to small, ULong can be to big.
Dim BinValue As Object
Dim counter As Integer = 0
Dim counter2 As Integer = 1
Dim i As Integer, n As Integer
Dim finalstring As String

10. Hide bugs behind complex computation.
    Do Until counter = ((Len(tempstring) \ 8) + 1)
        counter = counter + 1
        tempbinstr = Mid(tempstring, counter2, 8)
        For i = 0 To 7
            TempChar = Mid(tempbinstr, (i + 1), 1)
            If TempChar = "1" Then
                BinValue = BinValue + (2 ^ (7 - i))
            End If
        Next
        finalstring = finalstring & Chr(BinValue)
        BinValue = 0
        counter2 = counter2 + 8
    Loop
    Return finalstring
End Function

GeneralRe: How to be popular among your colleagues Pin
Thomas Weller11-Dec-08 20:15
Thomas Weller11-Dec-08 20:15 
GeneralRe: How to be popular among your colleagues Pin
Mycroft Holmes11-Dec-08 21:58
professionalMycroft Holmes11-Dec-08 21:58 
GeneralRe: How to be popular among your colleagues Pin
QuiJohn12-Dec-08 3:18
QuiJohn12-Dec-08 3:18 
GeneralRe: How to be popular among your colleagues Pin
Krirk26-Jan-09 23:09
Krirk26-Jan-09 23:09 
JokeRe: How to be popular among your colleagues Pin
notmasteryet27-Jan-09 5:55
notmasteryet27-Jan-09 5:55 
GeneralDo not trust a computer... PinPopular
notmasteryet11-Dec-08 12:51
notmasteryet11-Dec-08 12:51 
GeneralRe: Do not trust a computer... Pin
Lutosław12-Dec-08 9:57
Lutosław12-Dec-08 9:57 
GeneralAvoid return statement in the middle - horror or not? Pin
Georgi Atanasov5-Dec-08 12:01
Georgi Atanasov5-Dec-08 12:01 
GeneralRe: Avoid return statement in the middle - horror or not? PinPopular
Robert.C.Cartaino5-Dec-08 14:32
Robert.C.Cartaino5-Dec-08 14:32 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
John M. Drescher11-Dec-08 8:24
John M. Drescher11-Dec-08 8:24 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
PIEBALDconsult5-Dec-08 15:07
mvePIEBALDconsult5-Dec-08 15:07 
General[Message Deleted] Pin
Robert.C.Cartaino6-Dec-08 5:47
Robert.C.Cartaino6-Dec-08 5:47 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
harold aptroot6-Dec-08 6:48
harold aptroot6-Dec-08 6:48 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
Robert.C.Cartaino6-Dec-08 11:52
Robert.C.Cartaino6-Dec-08 11:52 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
harold aptroot6-Dec-08 12:10
harold aptroot6-Dec-08 12:10 
GeneralRe: Avoid return statement in the middle - horror or not? PinPopular
PIEBALDconsult6-Dec-08 13:44
mvePIEBALDconsult6-Dec-08 13:44 
GeneralRe: Avoid return statement in the middle - horror or not? PinPopular
Graham Bradshaw6-Dec-08 7:43
Graham Bradshaw6-Dec-08 7: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.