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. Extract from the code I'm working on

Extract from the code I'm working on

Scheduled Pinned Locked Moved The Weird and The Wonderful
lounge
7 Posts 4 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.
  • S Offline
    S Offline
    Super Lloyd
    wrote on last edited by
    #1

    I think that's the most stupid code I refactored today! But barely, and there is a lot more! :sigh:

    public XYZ()
    {
    _xyz = "0 , 0 , 0";
    string[] parts = _xyz.Split(',');
    Double.TryParse(parts[0], out x);
    Double.TryParse(parts[1], out y);
    Double.TryParse(parts[2], out z);
    }

    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

    B K N 3 Replies Last reply
    0
    • S Super Lloyd

      I think that's the most stupid code I refactored today! But barely, and there is a lot more! :sigh:

      public XYZ()
      {
      _xyz = "0 , 0 , 0";
      string[] parts = _xyz.Split(',');
      Double.TryParse(parts[0], out x);
      Double.TryParse(parts[1], out y);
      Double.TryParse(parts[2], out z);
      }

      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

      B Offline
      B Offline
      Brisingr Aerowing
      wrote on last edited by
      #2

      :doh:

      public void WriteCode(ICodeContent ctx)
      {
      throw new BrainNotFoundException();
      }

      Super Lloyd wrote:

      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....

      Where the work stops. Right?

      Bob Dole

      The internet is a great way to get on the net.

      :doh: 2.0.82.7292 SP6a

      S 1 Reply Last reply
      0
      • B Brisingr Aerowing

        :doh:

        public void WriteCode(ICodeContent ctx)
        {
        throw new BrainNotFoundException();
        }

        Super Lloyd wrote:

        A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....

        Where the work stops. Right?

        Bob Dole

        The internet is a great way to get on the net.

        :doh: 2.0.82.7292 SP6a

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

        You nailed it! Both remarks! ;P

        A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

        1 Reply Last reply
        0
        • S Super Lloyd

          I think that's the most stupid code I refactored today! But barely, and there is a lot more! :sigh:

          public XYZ()
          {
          _xyz = "0 , 0 , 0";
          string[] parts = _xyz.Split(',');
          Double.TryParse(parts[0], out x);
          Double.TryParse(parts[1], out y);
          Double.TryParse(parts[2], out z);
          }

          A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

          K Offline
          K Offline
          KP Lee
          wrote on last edited by
          #4

          Super Lloyd wrote:

          public XYZ() { _xyz = "0 , 0 , 0";...

          Looks like someone was planning on getting a string feed and forgot to feed the string or forgot to stop destroying the string. So what did you do to refactor it? Change code to x=0;y=0;z=0;? And keep _xyz = "0 , 0 , 0";? Remove _xyz = "0 , 0 , 0"; and verify the split causes at least 3 parts? Add error checking on the tryparses? Remove XYZ and all references?

          S 1 Reply Last reply
          0
          • K KP Lee

            Super Lloyd wrote:

            public XYZ() { _xyz = "0 , 0 , 0";...

            Looks like someone was planning on getting a string feed and forgot to feed the string or forgot to stop destroying the string. So what did you do to refactor it? Change code to x=0;y=0;z=0;? And keep _xyz = "0 , 0 , 0";? Remove _xyz = "0 , 0 , 0"; and verify the split causes at least 3 parts? Add error checking on the tryparses? Remove XYZ and all references?

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

            I got rid of the '_xyz' string, it was only used internally (in addition to x,y,z double) and parse every now and then, to get the value of 'x,y,z'

            A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

            1 Reply Last reply
            0
            • S Super Lloyd

              I think that's the most stupid code I refactored today! But barely, and there is a lot more! :sigh:

              public XYZ()
              {
              _xyz = "0 , 0 , 0";
              string[] parts = _xyz.Split(',');
              Double.TryParse(parts[0], out x);
              Double.TryParse(parts[1], out y);
              Double.TryParse(parts[2], out z);
              }

              A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

              N Offline
              N Offline
              Nemanja Trifunovic
              wrote on last edited by
              #6

              There is a design pattern for that: Stringly typed code[^]

              utf8-cpp

              S 1 Reply Last reply
              0
              • N Nemanja Trifunovic

                There is a design pattern for that: Stringly typed code[^]

                utf8-cpp

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

                Ho... I'm learning new power pattern every day!!! ;P

                A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                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