Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. How to be popular among your colleagues

How to be popular among your colleagues

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharphelptutorial
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    notmasteryet
    wrote on last edited by
    #1

    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 re

    T Q K 3 Replies Last reply
    0
    • N notmasteryet

      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 re

      T Offline
      T Offline
      Thomas Weller 0
      wrote on last edited by
      #2

      Hi, horrible indeed... :doh: But why would someone be 'popular among his colleagues' when programming like this? I'd rather think Hey, this is a guy who is not really good in his profession when I read things like that in someone else's code. And this means: Much to do for colleagues (refactoring, hard to read/understand) and much potential trouble (likelihood of errors is high, maintainability is hard) - so he makes his colleagues lifes harder... :confused: Regards Thomas

      www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
      Programmer - an organism that turns coffee into software.

      M 1 Reply Last reply
      0
      • T Thomas Weller 0

        Hi, horrible indeed... :doh: But why would someone be 'popular among his colleagues' when programming like this? I'd rather think Hey, this is a guy who is not really good in his profession when I read things like that in someone else's code. And this means: Much to do for colleagues (refactoring, hard to read/understand) and much potential trouble (likelihood of errors is high, maintainability is hard) - so he makes his colleagues lifes harder... :confused: Regards Thomas

        www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
        Programmer - an organism that turns coffee into software.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        This may help sarcasm[^] It does not always pass through translation.

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • N notmasteryet

          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 re

          Q Offline
          Q Offline
          QuiJohn
          wrote on last edited by
          #4

          #7 is my favorite... brilliant error message. "It's either this 200 digit number, or it's too big"


          He said, "Boy I'm just old and lonely, But thank you for your concern, Here's wishing you a Happy New Year." I wished him one back in return.

          1 Reply Last reply
          0
          • N notmasteryet

            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 re

            K Offline
            K Offline
            Krirk
            wrote on last edited by
            #5

            What wrong with this

            notmasteryet wrote:

            Enum NumberSize Bit_8 = 8 Bit_16 = 16 Bit_32 = 32 Bit_64 = 64 Bit_128 = 128 End Enum

            I think it is good practice. Do you have any better practice ?

            My blog

            N 1 Reply Last reply
            0
            • K Krirk

              What wrong with this

              notmasteryet wrote:

              Enum NumberSize Bit_8 = 8 Bit_16 = 16 Bit_32 = 32 Bit_64 = 64 Bit_128 = 128 End Enum

              I think it is good practice. Do you have any better practice ?

              My blog

              N Offline
              N Offline
              notmasteryet
              wrote on last edited by
              #6

              Enum NumberSize
              EightBits = 8
              SixteenBits = 16
              ThirtyTwoBits = 32
              SixtyFourBits = 64
              HundredTwentyEightBits = 128
              End Enum

              :) IMHO in this particular case, there is no effective use of the enumeration (see #4). There is no checks on invalid enumeration values either; most common call of the CBin_Number function was performed with argument CType(size, NumberSize) where size is an integer. It is hard to find best practices for enumerations since it just grouped constants. Usually all enumeration replaced by the Strategy Pattern during refactoring (see http://sourcemaking.com/refactoring/replace-type-code-with-state-strategy[^] or http://www.jeremyjarrell.com/archive/2007/10/28/64.aspx[^]). Type casting to enumeration datatype does not do validation, so a callie have to validate enumaration value by itself. However, by decalaring enumeration as

              Enum NumberSize
              Bit_8
              Bit_16
              Bit_32
              Bit_64
              Bit_128
              End Enum

              you may perform range (in)validation InputNumberSize < NumberSize.Bit_8 OrElse InputNumberSize > NumberSize.Bit_16, it also allows compliler to optimize Select statement code execution. Do you think change NumberSize to an integer type would introduce more problems?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups