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. When Poor Design Gets Baked Into a File Format

When Poor Design Gets Baked Into a File Format

Scheduled Pinned Locked Moved The Weird and The Wonderful
designquestion
11 Posts 7 Posters 39 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.
  • K Kevin Li Li Ken un

    Found this nugget in the constructor of a class that’s supposed to represent a structure in a binary file:

    var isNamed = reader.ReadBoolean(); // This byte indicates whether the object has a name.
    if (isNamed) // If the object has a name, read the remaining bytes.
    {
    var nameLength = reader.ReadByte(); // This byte indicates the length of the name.
    this.Name = new string(reader.ReadChars(nameLength));
    }

    The property setter for ``Name`` checks the length of the string—and it forbids zero-length strings. :wtf: Wouldn’t a name length value of ``0`` suffice to indicate the absence of a name?

    P Offline
    P Offline
    phil o
    wrote on last edited by
    #2

    But, if nameLength is zero, this means that isNamed is true. A man has no name. That's why.

    "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

    S 1 Reply Last reply
    0
    • K Kevin Li Li Ken un

      Found this nugget in the constructor of a class that’s supposed to represent a structure in a binary file:

      var isNamed = reader.ReadBoolean(); // This byte indicates whether the object has a name.
      if (isNamed) // If the object has a name, read the remaining bytes.
      {
      var nameLength = reader.ReadByte(); // This byte indicates the length of the name.
      this.Name = new string(reader.ReadChars(nameLength));
      }

      The property setter for ``Name`` checks the length of the string—and it forbids zero-length strings. :wtf: Wouldn’t a name length value of ``0`` suffice to indicate the absence of a name?

      honey the codewitchH Offline
      honey the codewitchH Offline
      honey the codewitch
      wrote on last edited by
      #3

      The only reason i can think of for this is that Name can be specified but empty, which seems silly. I wonder if there was a design issue further downstream that required support for empty names?

      Real programmers use butterflies

      Greg UtasG 1 Reply Last reply
      0
      • honey the codewitchH honey the codewitch

        The only reason i can think of for this is that Name can be specified but empty, which seems silly. I wonder if there was a design issue further downstream that required support for empty names?

        Real programmers use butterflies

        Greg UtasG Offline
        Greg UtasG Offline
        Greg Utas
        wrote on last edited by
        #4

        Or ReadBoolean masks a bit and they put the other 7 bits to good use. :laugh:

        Robust Services Core | Software Techniques for Lemmings | Articles

        <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
        <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

        honey the codewitchH 1 Reply Last reply
        0
        • Greg UtasG Greg Utas

          Or ReadBoolean masks a bit and they put the other 7 bits to good use. :laugh:

          Robust Services Core | Software Techniques for Lemmings | Articles

          honey the codewitchH Offline
          honey the codewitchH Offline
          honey the codewitch
          wrote on last edited by
          #5

          If that were the case I would be skinning someone come code review time.

          Real programmers use butterflies

          Greg UtasG 1 Reply Last reply
          0
          • honey the codewitchH honey the codewitch

            If that were the case I would be skinning someone come code review time.

            Real programmers use butterflies

            Greg UtasG Offline
            Greg UtasG Offline
            Greg Utas
            wrote on last edited by
            #6

            But but but...it's a binary file. :((

            Robust Services Core | Software Techniques for Lemmings | Articles

            <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
            <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

            1 Reply Last reply
            0
            • K Kevin Li Li Ken un

              Found this nugget in the constructor of a class that’s supposed to represent a structure in a binary file:

              var isNamed = reader.ReadBoolean(); // This byte indicates whether the object has a name.
              if (isNamed) // If the object has a name, read the remaining bytes.
              {
              var nameLength = reader.ReadByte(); // This byte indicates the length of the name.
              this.Name = new string(reader.ReadChars(nameLength));
              }

              The property setter for ``Name`` checks the length of the string—and it forbids zero-length strings. :wtf: Wouldn’t a name length value of ``0`` suffice to indicate the absence of a name?

              K Offline
              K Offline
              kalberts
              wrote on last edited by
              #7

              Database people have been discussing variants of non-existing, empty and zero-length strings for at least 30-40 years. There is a difference between not knowing whether a value for the attribute exists, knowing positively that it is void, and knowing that there is a defined value, but it is of zero length. The strangest passport I ever saw was for the son of friends of mine: It stated birthdate as unknown, sex unknown, name unknown, no photo or fingerprint available. When the mother, US citizen living in Norway, is pregnant with a baby, and plans a trip abroad with the baby a few weeks after the delivery, you must start the process of applying for a passport before those details are known. So for this baby's middle name, before his birth, nothing was known, not even if he would have a middle name at all. If he has one, I do not know it, so I could treat it as a defined name attribute with unknown value. If I learn that he certainly does not have a middle name, it would be a known value of zero length. There may be better examples to illustrate various null/empty/… values; this is just the first one dropping into my mind. There may be cases where there is no semantic difference between optional omitted, included but unknown, included with a known length of zero and included with a positive length value. Yet there are other cases where the semantic difference may be very significant.

              L 1 Reply Last reply
              0
              • P phil o

                But, if nameLength is zero, this means that isNamed is true. A man has no name. That's why.

                "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

                S Offline
                S Offline
                Super Lloyd
                wrote on last edited by
                #8

                Valar Morghulis! :)

                A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                1 Reply Last reply
                0
                • K Kevin Li Li Ken un

                  Found this nugget in the constructor of a class that’s supposed to represent a structure in a binary file:

                  var isNamed = reader.ReadBoolean(); // This byte indicates whether the object has a name.
                  if (isNamed) // If the object has a name, read the remaining bytes.
                  {
                  var nameLength = reader.ReadByte(); // This byte indicates the length of the name.
                  this.Name = new string(reader.ReadChars(nameLength));
                  }

                  The property setter for ``Name`` checks the length of the string—and it forbids zero-length strings. :wtf: Wouldn’t a name length value of ``0`` suffice to indicate the absence of a name?

                  S Offline
                  S Offline
                  Super Lloyd
                  wrote on last edited by
                  #9

                  mmmm... while you are arguing for 1 wasted byte at offset 0, did you noticed the wasted 1MB at offset 43512?! ;P

                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                  K 1 Reply Last reply
                  0
                  • S Super Lloyd

                    mmmm... while you are arguing for 1 wasted byte at offset 0, did you noticed the wasted 1MB at offset 43512?! ;P

                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                    K Offline
                    K Offline
                    Kevin Li Li Ken un
                    wrote on last edited by
                    #10

                    I’m sure the serialization inefficiencies could be waved away with a layer of arithmetic coding compression using a specialized model trained on the wasted bits of this format, but I worry that this is just basically sweeping technical dust under the rug …and overengineering for such a trivial problem. :(

                    1 Reply Last reply
                    0
                    • K kalberts

                      Database people have been discussing variants of non-existing, empty and zero-length strings for at least 30-40 years. There is a difference between not knowing whether a value for the attribute exists, knowing positively that it is void, and knowing that there is a defined value, but it is of zero length. The strangest passport I ever saw was for the son of friends of mine: It stated birthdate as unknown, sex unknown, name unknown, no photo or fingerprint available. When the mother, US citizen living in Norway, is pregnant with a baby, and plans a trip abroad with the baby a few weeks after the delivery, you must start the process of applying for a passport before those details are known. So for this baby's middle name, before his birth, nothing was known, not even if he would have a middle name at all. If he has one, I do not know it, so I could treat it as a defined name attribute with unknown value. If I learn that he certainly does not have a middle name, it would be a known value of zero length. There may be better examples to illustrate various null/empty/… values; this is just the first one dropping into my mind. There may be cases where there is no semantic difference between optional omitted, included but unknown, included with a known length of zero and included with a positive length value. Yet there are other cases where the semantic difference may be very significant.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      Empty is not the same as "unknown". If it is unknown, then that is what it should state.

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                      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