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. A bad Case of comparison

A bad Case of comparison

Scheduled Pinned Locked Moved The Weird and The Wonderful
databaseperformancequestionlounge
7 Posts 5 Posters 1 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.
  • J Offline
    J Offline
    Julien Villers
    wrote on last edited by
    #1

    I'm tasked, as many of us are, with maintaining a codebase that was written by my predecessor. I'm finding some parts disgusting, and other, more like... fun? Like the use of 'ToLower()' to make string comparison more safe...

    if (someString.ToLower().StartsWith("text", StringComparison.OrdinalIgnoreCase))

    -> Nice way to waste some cycles and memory for the Garbage Collector to play with!

    if (someString.Substring(lastMarkend - 3, 3).ToLower() == "<Index>")

    -> My little finger tells me, the functionality under this if must have been tested quite thoroughly. NB: I've only changed the string names.

    'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood

    T R 2 Replies Last reply
    0
    • J Julien Villers

      I'm tasked, as many of us are, with maintaining a codebase that was written by my predecessor. I'm finding some parts disgusting, and other, more like... fun? Like the use of 'ToLower()' to make string comparison more safe...

      if (someString.ToLower().StartsWith("text", StringComparison.OrdinalIgnoreCase))

      -> Nice way to waste some cycles and memory for the Garbage Collector to play with!

      if (someString.Substring(lastMarkend - 3, 3).ToLower() == "<Index>")

      -> My little finger tells me, the functionality under this if must have been tested quite thoroughly. NB: I've only changed the string names.

      'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood

      T Offline
      T Offline
      thoiness
      wrote on last edited by
      #2

      Oh oh! I've got the answer: #2 is false :laugh:

      J 1 Reply Last reply
      0
      • T thoiness

        Oh oh! I've got the answer: #2 is false :laugh:

        J Offline
        J Offline
        Jeroen De Dauw
        wrote on last edited by
        #3

        #1, if you start counting at the first number.

        Jeroen De Dauw (blog | Twitter | Identi.ca)

        1 Reply Last reply
        0
        • J Julien Villers

          I'm tasked, as many of us are, with maintaining a codebase that was written by my predecessor. I'm finding some parts disgusting, and other, more like... fun? Like the use of 'ToLower()' to make string comparison more safe...

          if (someString.ToLower().StartsWith("text", StringComparison.OrdinalIgnoreCase))

          -> Nice way to waste some cycles and memory for the Garbage Collector to play with!

          if (someString.Substring(lastMarkend - 3, 3).ToLower() == "<Index>")

          -> My little finger tells me, the functionality under this if must have been tested quite thoroughly. NB: I've only changed the string names.

          'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood

          R Offline
          R Offline
          RCoate
          wrote on last edited by
          #4

          Shouldn't #2 be:

          if (someString.Substring(lastMarkend - 3, 3).ToLower() == ("").ToLower())

          J F 2 Replies Last reply
          0
          • R RCoate

            Shouldn't #2 be:

            if (someString.Substring(lastMarkend - 3, 3).ToLower() == ("").ToLower())

            J Offline
            J Offline
            Julien Villers
            wrote on last edited by
            #5

            That would work better for sure ;) BTW, the string literal is just that, a string literal, when there are several 'consts'* defined some lines above * without any const specifier or special naming of course!

            'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood

            1 Reply Last reply
            0
            • R RCoate

              Shouldn't #2 be:

              if (someString.Substring(lastMarkend - 3, 3).ToLower() == ("").ToLower())

              F Offline
              F Offline
              Freak30
              wrote on last edited by
              #6

              #2 is even worse. The literal on the right is 7 characters long, the string on the left only 3.

              J 1 Reply Last reply
              0
              • F Freak30

                #2 is even worse. The literal on the right is 7 characters long, the string on the left only 3.

                J Offline
                J Offline
                Julien Villers
                wrote on last edited by
                #7

                Well spotted, I did stop at the case mismatch there!

                'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood

                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