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. Nesting level: 9001

Nesting level: 9001

Scheduled Pinned Locked Moved The Weird and The Wonderful
13 Posts 9 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Found this in code I wrote a long time ago. Not the stupidest code ever perhaps, but it's just, well, see for yourself.

    size = 29;
    if (width > 11 || height > 4)
    {
    size++;
    if (width > 13 || height > 5)
    {
    size++;
    if (width > 15 || height > 6)
    {
    size++;
    if (width > 18 || height > 7)
    {
    size++;
    if (width > 19 || height > 8)
    {
    size++;
    if (width > 21 || height > 10)
    {
    // 7x6 compressed
    SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
    }
    else
    {
    // 7x6
    Spread(width, 8, 7, xpos, ypos);
    }
    }
    else
    {
    // 8x8
    Spread(width, 9, 9, xpos, ypos);
    }
    }
    else
    {
    // 8x9
    Spread(width, 9, 10, xpos, ypos);
    }
    }
    else
    {
    // 10x11
    Spread(width, 11, 12, xpos, ypos);
    }
    }
    else
    {
    // 12x13
    Spread(width, 13, 14, xpos, ypos);
    }
    }
    else
    {
    // 14x15
    Spread(width, 15, 16, xpos, ypos);
    }

    L C P A Sander RosselS 7 Replies Last reply
    0
    • L Lost User

      Found this in code I wrote a long time ago. Not the stupidest code ever perhaps, but it's just, well, see for yourself.

      size = 29;
      if (width > 11 || height > 4)
      {
      size++;
      if (width > 13 || height > 5)
      {
      size++;
      if (width > 15 || height > 6)
      {
      size++;
      if (width > 18 || height > 7)
      {
      size++;
      if (width > 19 || height > 8)
      {
      size++;
      if (width > 21 || height > 10)
      {
      // 7x6 compressed
      SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
      }
      else
      {
      // 7x6
      Spread(width, 8, 7, xpos, ypos);
      }
      }
      else
      {
      // 8x8
      Spread(width, 9, 9, xpos, ypos);
      }
      }
      else
      {
      // 8x9
      Spread(width, 9, 10, xpos, ypos);
      }
      }
      else
      {
      // 10x11
      Spread(width, 11, 12, xpos, ypos);
      }
      }
      else
      {
      // 12x13
      Spread(width, 13, 14, xpos, ypos);
      }
      }
      else
      {
      // 14x15
      Spread(width, 15, 16, xpos, ypos);
      }

      L Offline
      L Offline
      loctrice
      wrote on last edited by
      #2

      I used to have a flash drive with code projects on it from my first semester in college. It was a unique set of code :D Flash drive died though, and I never had a backup.

      If it moves, compile it

      1 Reply Last reply
      0
      • L Lost User

        Found this in code I wrote a long time ago. Not the stupidest code ever perhaps, but it's just, well, see for yourself.

        size = 29;
        if (width > 11 || height > 4)
        {
        size++;
        if (width > 13 || height > 5)
        {
        size++;
        if (width > 15 || height > 6)
        {
        size++;
        if (width > 18 || height > 7)
        {
        size++;
        if (width > 19 || height > 8)
        {
        size++;
        if (width > 21 || height > 10)
        {
        // 7x6 compressed
        SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
        }
        else
        {
        // 7x6
        Spread(width, 8, 7, xpos, ypos);
        }
        }
        else
        {
        // 8x8
        Spread(width, 9, 9, xpos, ypos);
        }
        }
        else
        {
        // 8x9
        Spread(width, 9, 10, xpos, ypos);
        }
        }
        else
        {
        // 10x11
        Spread(width, 11, 12, xpos, ypos);
        }
        }
        else
        {
        // 12x13
        Spread(width, 13, 14, xpos, ypos);
        }
        }
        else
        {
        // 14x15
        Spread(width, 15, 16, xpos, ypos);
        }

        C Offline
        C Offline
        Chris Meech
        wrote on last edited by
        #3

        This is a good example of even when there are a lot of nesting levels, the code can be formatted so that it is readable and understandable. :)

        Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

        L 1 Reply Last reply
        0
        • C Chris Meech

          This is a good example of even when there are a lot of nesting levels, the code can be formatted so that it is readable and understandable. :)

          Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

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

          Yes, and I can't remember why I wrote it this way. It should never even have happened in the first place.

          1 Reply Last reply
          0
          • L Lost User

            Found this in code I wrote a long time ago. Not the stupidest code ever perhaps, but it's just, well, see for yourself.

            size = 29;
            if (width > 11 || height > 4)
            {
            size++;
            if (width > 13 || height > 5)
            {
            size++;
            if (width > 15 || height > 6)
            {
            size++;
            if (width > 18 || height > 7)
            {
            size++;
            if (width > 19 || height > 8)
            {
            size++;
            if (width > 21 || height > 10)
            {
            // 7x6 compressed
            SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
            }
            else
            {
            // 7x6
            Spread(width, 8, 7, xpos, ypos);
            }
            }
            else
            {
            // 8x8
            Spread(width, 9, 9, xpos, ypos);
            }
            }
            else
            {
            // 8x9
            Spread(width, 9, 10, xpos, ypos);
            }
            }
            else
            {
            // 10x11
            Spread(width, 11, 12, xpos, ypos);
            }
            }
            else
            {
            // 12x13
            Spread(width, 13, 14, xpos, ypos);
            }
            }
            else
            {
            // 14x15
            Spread(width, 15, 16, xpos, ypos);
            }

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            So what's the alternative?

            L 1 Reply Last reply
            0
            • P PIEBALDconsult

              So what's the alternative?

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

              Well I could have done this:

              if (width <= 11 && height <= 4)
              {
              size = 29;
              Spread(width, 15, 16, xpos, ypos);
              }
              else if (width <= 13 && height <= 5)
              {
              size = 30;
              Spread(width, 13, 14, xpos, ypos);
              }
              else if (width <= 15 && height <= 6)
              {
              size = 31;
              Spread(width, 11, 12, xpos, ypos);
              }
              else if (width <= 18 && height <= 7)
              {
              size = 32;
              Spread(width, 9, 10, xpos, ypos);
              }
              else if (width <= 19 && height <= 8)
              {
              size = 33;
              Spread(width, 9, 9, xpos, ypos);
              }
              else if (width <= 21 && height <= 10)
              {
              size = 34;
              Spread(width, 8, 7, xpos, ypos);
              }
              else
              {
              size = 34;
              SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
              }

              Not great either, but still better I would say. At least the width and height requirements are actually grouped together with what should happen if they're met, instead of in a weird inverted way moved as far apart as possible.

              J 1 Reply Last reply
              0
              • L Lost User

                Found this in code I wrote a long time ago. Not the stupidest code ever perhaps, but it's just, well, see for yourself.

                size = 29;
                if (width > 11 || height > 4)
                {
                size++;
                if (width > 13 || height > 5)
                {
                size++;
                if (width > 15 || height > 6)
                {
                size++;
                if (width > 18 || height > 7)
                {
                size++;
                if (width > 19 || height > 8)
                {
                size++;
                if (width > 21 || height > 10)
                {
                // 7x6 compressed
                SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
                }
                else
                {
                // 7x6
                Spread(width, 8, 7, xpos, ypos);
                }
                }
                else
                {
                // 8x8
                Spread(width, 9, 9, xpos, ypos);
                }
                }
                else
                {
                // 8x9
                Spread(width, 9, 10, xpos, ypos);
                }
                }
                else
                {
                // 10x11
                Spread(width, 11, 12, xpos, ypos);
                }
                }
                else
                {
                // 12x13
                Spread(width, 13, 14, xpos, ypos);
                }
                }
                else
                {
                // 14x15
                Spread(width, 15, 16, xpos, ypos);
                }

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #7

                It's over 9,000!!!!!! I assume you have been waiting for that. ;)

                Thou mewling ill-breeding pignut!

                1 Reply Last reply
                0
                • L Lost User

                  Found this in code I wrote a long time ago. Not the stupidest code ever perhaps, but it's just, well, see for yourself.

                  size = 29;
                  if (width > 11 || height > 4)
                  {
                  size++;
                  if (width > 13 || height > 5)
                  {
                  size++;
                  if (width > 15 || height > 6)
                  {
                  size++;
                  if (width > 18 || height > 7)
                  {
                  size++;
                  if (width > 19 || height > 8)
                  {
                  size++;
                  if (width > 21 || height > 10)
                  {
                  // 7x6 compressed
                  SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
                  }
                  else
                  {
                  // 7x6
                  Spread(width, 8, 7, xpos, ypos);
                  }
                  }
                  else
                  {
                  // 8x8
                  Spread(width, 9, 9, xpos, ypos);
                  }
                  }
                  else
                  {
                  // 8x9
                  Spread(width, 9, 10, xpos, ypos);
                  }
                  }
                  else
                  {
                  // 10x11
                  Spread(width, 11, 12, xpos, ypos);
                  }
                  }
                  else
                  {
                  // 12x13
                  Spread(width, 13, 14, xpos, ypos);
                  }
                  }
                  else
                  {
                  // 14x15
                  Spread(width, 15, 16, xpos, ypos);
                  }

                  Sander RosselS Offline
                  Sander RosselS Offline
                  Sander Rossel
                  wrote on last edited by
                  #8

                  harold aptroot wrote:

                  code I wrote a long time ago

                  You dare admit that here? ;p Although I must admit I've written something like five nested if's just today... :-O

                  It's an OO world.

                  public class Naerling : Lazy<Person>{
                  public void DoWork(){ throw new NotImplementedException(); }
                  }

                  1 Reply Last reply
                  0
                  • L Lost User

                    Well I could have done this:

                    if (width <= 11 && height <= 4)
                    {
                    size = 29;
                    Spread(width, 15, 16, xpos, ypos);
                    }
                    else if (width <= 13 && height <= 5)
                    {
                    size = 30;
                    Spread(width, 13, 14, xpos, ypos);
                    }
                    else if (width <= 15 && height <= 6)
                    {
                    size = 31;
                    Spread(width, 11, 12, xpos, ypos);
                    }
                    else if (width <= 18 && height <= 7)
                    {
                    size = 32;
                    Spread(width, 9, 10, xpos, ypos);
                    }
                    else if (width <= 19 && height <= 8)
                    {
                    size = 33;
                    Spread(width, 9, 9, xpos, ypos);
                    }
                    else if (width <= 21 && height <= 10)
                    {
                    size = 34;
                    Spread(width, 8, 7, xpos, ypos);
                    }
                    else
                    {
                    size = 34;
                    SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
                    }

                    Not great either, but still better I would say. At least the width and height requirements are actually grouped together with what should happen if they're met, instead of in a weird inverted way moved as far apart as possible.

                    J Offline
                    J Offline
                    JackDingler
                    wrote on last edited by
                    #9

                    Perhaps a map with a key class for width and height, and a value class for the passed parameters. Use std::map::upper_bound() to find the element you're looking for.... then it'll be dynamic with no hard coding...

                    1 Reply Last reply
                    0
                    • L Lost User

                      Found this in code I wrote a long time ago. Not the stupidest code ever perhaps, but it's just, well, see for yourself.

                      size = 29;
                      if (width > 11 || height > 4)
                      {
                      size++;
                      if (width > 13 || height > 5)
                      {
                      size++;
                      if (width > 15 || height > 6)
                      {
                      size++;
                      if (width > 18 || height > 7)
                      {
                      size++;
                      if (width > 19 || height > 8)
                      {
                      size++;
                      if (width > 21 || height > 10)
                      {
                      // 7x6 compressed
                      SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
                      }
                      else
                      {
                      // 7x6
                      Spread(width, 8, 7, xpos, ypos);
                      }
                      }
                      else
                      {
                      // 8x8
                      Spread(width, 9, 9, xpos, ypos);
                      }
                      }
                      else
                      {
                      // 8x9
                      Spread(width, 9, 10, xpos, ypos);
                      }
                      }
                      else
                      {
                      // 10x11
                      Spread(width, 11, 12, xpos, ypos);
                      }
                      }
                      else
                      {
                      // 12x13
                      Spread(width, 13, 14, xpos, ypos);
                      }
                      }
                      else
                      {
                      // 14x15
                      Spread(width, 15, 16, xpos, ypos);
                      }

                      O Offline
                      O Offline
                      Oscar0
                      wrote on last edited by
                      #10

                      How about something along the lines of:

                      size = 29;
                      if(width > 11 || height > 4) size++;
                      if(width > 13 || height > 5) size++;
                      if(width > 15 || height > 6) size++;
                      if(width > 18 || height > 7) size++;
                      if(width > 19 || height > 8) size++;
                      if(width > 21 || height > 10) size++;

                      switch(size) {
                      case 29: Spread(width, 15, 16, xpos, ypos); break;
                      case 30: Spread(width, 13, 14, xpos, ypos); break;
                      case 31: Spread(width, 11, 12, xpos, ypos); break;
                      case 32: Spread(width, 9, 10, xpos, ypos); break;
                      case 33: Spread(width, 9, 9, xpos, ypos); break;
                      case 34: Spread(width, 8, 7, xpos, ypos); break;
                      case 35: SpreadCompressed(width, width > 21, height > 10, xpos, ypos); break;
                      }

                      L 1 Reply Last reply
                      0
                      • O Oscar0

                        How about something along the lines of:

                        size = 29;
                        if(width > 11 || height > 4) size++;
                        if(width > 13 || height > 5) size++;
                        if(width > 15 || height > 6) size++;
                        if(width > 18 || height > 7) size++;
                        if(width > 19 || height > 8) size++;
                        if(width > 21 || height > 10) size++;

                        switch(size) {
                        case 29: Spread(width, 15, 16, xpos, ypos); break;
                        case 30: Spread(width, 13, 14, xpos, ypos); break;
                        case 31: Spread(width, 11, 12, xpos, ypos); break;
                        case 32: Spread(width, 9, 10, xpos, ypos); break;
                        case 33: Spread(width, 9, 9, xpos, ypos); break;
                        case 34: Spread(width, 8, 7, xpos, ypos); break;
                        case 35: SpreadCompressed(width, width > 21, height > 10, xpos, ypos); break;
                        }

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

                        There is no size 35 though, so I'm afraid case 34 would have to be a bit ugly..

                        O 1 Reply Last reply
                        0
                        • L Lost User

                          Found this in code I wrote a long time ago. Not the stupidest code ever perhaps, but it's just, well, see for yourself.

                          size = 29;
                          if (width > 11 || height > 4)
                          {
                          size++;
                          if (width > 13 || height > 5)
                          {
                          size++;
                          if (width > 15 || height > 6)
                          {
                          size++;
                          if (width > 18 || height > 7)
                          {
                          size++;
                          if (width > 19 || height > 8)
                          {
                          size++;
                          if (width > 21 || height > 10)
                          {
                          // 7x6 compressed
                          SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
                          }
                          else
                          {
                          // 7x6
                          Spread(width, 8, 7, xpos, ypos);
                          }
                          }
                          else
                          {
                          // 8x8
                          Spread(width, 9, 9, xpos, ypos);
                          }
                          }
                          else
                          {
                          // 8x9
                          Spread(width, 9, 10, xpos, ypos);
                          }
                          }
                          else
                          {
                          // 10x11
                          Spread(width, 11, 12, xpos, ypos);
                          }
                          }
                          else
                          {
                          // 12x13
                          Spread(width, 13, 14, xpos, ypos);
                          }
                          }
                          else
                          {
                          // 14x15
                          Spread(width, 15, 16, xpos, ypos);
                          }

                          E Offline
                          E Offline
                          englebart
                          wrote on last edited by
                          #12

                          Is size used elsewhere? I would have probably calculated a widthSize and a heightSize separately and then size = max(widthSize, heightSize) This approach basically replaces six || operators with one compare in the max() function. You could have used an array, switch statement, collection or even if statements for calculating/looking up widthSize and heightSize. switch would probably be most readable (and fastest for these datapoints).

                          1 Reply Last reply
                          0
                          • L Lost User

                            There is no size 35 though, so I'm afraid case 34 would have to be a bit ugly..

                            O Offline
                            O Offline
                            Oscar0
                            wrote on last edited by
                            #13

                            Then I would amend it to:

                            size = 29;
                            if(width > 11 || height > 4) size++;
                            if(width > 13 || height > 5) size++;
                            if(width > 15 || height > 6) size++;
                            if(width > 18 || height > 7) size++;
                            if(width > 19 || height > 8) size++;
                            if(width > 21 || height > 10) size++;

                            switch(size) {
                            case 29: Spread(width, 15, 16, xpos, ypos); break;
                            case 30: Spread(width, 13, 14, xpos, ypos); break;
                            case 31: Spread(width, 11, 12, xpos, ypos); break;
                            case 32: Spread(width, 9, 10, xpos, ypos); break;
                            case 33: Spread(width, 9, 9, xpos, ypos); break;
                            case 34: Spread(width, 8, 7, xpos, ypos); break;
                            case 35:
                            SpreadCompressed(width, width > 21, height > 10, xpos, ypos);
                            size--; //back to 34 for you
                            break;

                            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