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. Let's call him J. S. Crypt

Let's call him J. S. Crypt

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpjavascriptpythoncomtools
20 Posts 12 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.
  • M Marc Clifton

    ...because his code (yes, I know it's a "he") and style reminds me of stuff I've seen in Javascript and other script languages.

    public void Foo()
    {
    var SomeList = new ArrayList();
    SomeList = getSomeList();

            if (SomeList.Count != 0)
            {
                foreach (string Item in SomeList)
                {
                    var S = Item.Split(',');
                    var S0 = s\[0\];
                    var S1 = s\[1\];
                    var S2 = s\[2\];
                    var S3 = s\[3\];
                ...
                }
           }
     }
    
     private static ArrayList getSomeList()
     {
        var List = new ArrayList();
        ...
        List.Add(N1 + "," + N2 + "," + N3 + "," + N3);
        ...
        return List;
     }
    

    Variable names have for the most part been changed to protect the innocent. Things that got me laughing, cringing, and crying: 1. Useless initialization of SomeList 2. Well, if the count is 0, the foreach won't execute 3. Obviously never heard of out variables, or even returning a struct/class with the parsed data. Instead, he creates a concatenated string, then parses it back out! And not exactly internationalized, the chaos that would occur if one or more of the numbers was 1234,56 4. Why a static method? It's referenced once, in the above call. And this is just the beginning! (I do believe this code was written in the .NET 2.0 days before generics -- I have other clues to that -- but that's no excuse.) Marc

    V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

    P Offline
    P Offline
    Paulo Zemek
    wrote on last edited by
    #11

    Did you notice this?

    List.Add(N1 + "," + N2 + "," + N3 + "," + N3);

    N3 is added twice. N4 is never added.

    J M 2 Replies Last reply
    0
    • P Paulo Zemek

      Did you notice this?

      List.Add(N1 + "," + N2 + "," + N3 + "," + N3);

      N3 is added twice. N4 is never added.

      J Offline
      J Offline
      Jon McKee
      wrote on last edited by
      #12

      I'm guessing that was a typo by Marc. At least I'm hoping it was... :~

      P 1 Reply Last reply
      0
      • J Jon McKee

        I'm guessing that was a typo by Marc. At least I'm hoping it was... :~

        P Offline
        P Offline
        Paulo Zemek
        wrote on last edited by
        #13

        I thought he copied the code and changed what he wanted to preserve identity... So, it must be part of the real one. I think.

        1 Reply Last reply
        0
        • M Marc Clifton

          ...because his code (yes, I know it's a "he") and style reminds me of stuff I've seen in Javascript and other script languages.

          public void Foo()
          {
          var SomeList = new ArrayList();
          SomeList = getSomeList();

                  if (SomeList.Count != 0)
                  {
                      foreach (string Item in SomeList)
                      {
                          var S = Item.Split(',');
                          var S0 = s\[0\];
                          var S1 = s\[1\];
                          var S2 = s\[2\];
                          var S3 = s\[3\];
                      ...
                      }
                 }
           }
          
           private static ArrayList getSomeList()
           {
              var List = new ArrayList();
              ...
              List.Add(N1 + "," + N2 + "," + N3 + "," + N3);
              ...
              return List;
           }
          

          Variable names have for the most part been changed to protect the innocent. Things that got me laughing, cringing, and crying: 1. Useless initialization of SomeList 2. Well, if the count is 0, the foreach won't execute 3. Obviously never heard of out variables, or even returning a struct/class with the parsed data. Instead, he creates a concatenated string, then parses it back out! And not exactly internationalized, the chaos that would occur if one or more of the numbers was 1234,56 4. Why a static method? It's referenced once, in the above call. And this is just the beginning! (I do believe this code was written in the .NET 2.0 days before generics -- I have other clues to that -- but that's no excuse.) Marc

          V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

          M Offline
          M Offline
          mbb01
          wrote on last edited by
          #14

          Possibly a cut and paste job from the internet by someone not familiar with C#, .NET or programming in general. Could well be a port out of C, C++ or VB6. Things like a private static method and module/global variables could be an artifact of another language.

          1 Reply Last reply
          0
          • M Marc Clifton

            ...because his code (yes, I know it's a "he") and style reminds me of stuff I've seen in Javascript and other script languages.

            public void Foo()
            {
            var SomeList = new ArrayList();
            SomeList = getSomeList();

                    if (SomeList.Count != 0)
                    {
                        foreach (string Item in SomeList)
                        {
                            var S = Item.Split(',');
                            var S0 = s\[0\];
                            var S1 = s\[1\];
                            var S2 = s\[2\];
                            var S3 = s\[3\];
                        ...
                        }
                   }
             }
            
             private static ArrayList getSomeList()
             {
                var List = new ArrayList();
                ...
                List.Add(N1 + "," + N2 + "," + N3 + "," + N3);
                ...
                return List;
             }
            

            Variable names have for the most part been changed to protect the innocent. Things that got me laughing, cringing, and crying: 1. Useless initialization of SomeList 2. Well, if the count is 0, the foreach won't execute 3. Obviously never heard of out variables, or even returning a struct/class with the parsed data. Instead, he creates a concatenated string, then parses it back out! And not exactly internationalized, the chaos that would occur if one or more of the numbers was 1234,56 4. Why a static method? It's referenced once, in the above call. And this is just the beginning! (I do believe this code was written in the .NET 2.0 days before generics -- I have other clues to that -- but that's no excuse.) Marc

            V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

            M Offline
            M Offline
            Mike Marynowski
            wrote on last edited by
            #15

            If you are hyper-optimizing code, you can avoid allocation of an enumerator object by checking the count first if you expect that it will often contain 0 items. That said, it is obvious that this guy probably wouldn't know that, but worth noting. We've done it in very performance sensitive code that might be called many times in a tight loop.

            P 1 Reply Last reply
            0
            • M Mike Marynowski

              If you are hyper-optimizing code, you can avoid allocation of an enumerator object by checking the count first if you expect that it will often contain 0 items. That said, it is obvious that this guy probably wouldn't know that, but worth noting. We've done it in very performance sensitive code that might be called many times in a tight loop.

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

              Better to avoid foreach whenever possible. If there's a Count, it's probably indexable, so use for instead.

              M 1 Reply Last reply
              0
              • P PIEBALDconsult

                Better to avoid foreach whenever possible. If there's a Count, it's probably indexable, so use for instead.

                M Offline
                M Offline
                Mike Marynowski
                wrote on last edited by
                #17

                For performance sensitive code that could be used in long tight loops I agree, but "whenever" I don't agree with. In 95% of code it will make zero difference, so the readability and simplicity of foreach wins.

                1 Reply Last reply
                0
                • M Marc Clifton

                  ...because his code (yes, I know it's a "he") and style reminds me of stuff I've seen in Javascript and other script languages.

                  public void Foo()
                  {
                  var SomeList = new ArrayList();
                  SomeList = getSomeList();

                          if (SomeList.Count != 0)
                          {
                              foreach (string Item in SomeList)
                              {
                                  var S = Item.Split(',');
                                  var S0 = s\[0\];
                                  var S1 = s\[1\];
                                  var S2 = s\[2\];
                                  var S3 = s\[3\];
                              ...
                              }
                         }
                   }
                  
                   private static ArrayList getSomeList()
                   {
                      var List = new ArrayList();
                      ...
                      List.Add(N1 + "," + N2 + "," + N3 + "," + N3);
                      ...
                      return List;
                   }
                  

                  Variable names have for the most part been changed to protect the innocent. Things that got me laughing, cringing, and crying: 1. Useless initialization of SomeList 2. Well, if the count is 0, the foreach won't execute 3. Obviously never heard of out variables, or even returning a struct/class with the parsed data. Instead, he creates a concatenated string, then parses it back out! And not exactly internationalized, the chaos that would occur if one or more of the numbers was 1234,56 4. Why a static method? It's referenced once, in the above call. And this is just the beginning! (I do believe this code was written in the .NET 2.0 days before generics -- I have other clues to that -- but that's no excuse.) Marc

                  V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

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

                  Oh, now I am reminded of some ODBC code (in ANSI C) I had thrust upon me in the late-90s -- query results were returned as CSV strings. :omg: I had to write my own version that at least returned sort of an array of strings.

                  1 Reply Last reply
                  0
                  • P Paulo Zemek

                    Did you notice this?

                    List.Add(N1 + "," + N2 + "," + N3 + "," + N3);

                    N3 is added twice. N4 is never added.

                    M Offline
                    M Offline
                    Marc Clifton
                    wrote on last edited by
                    #19

                    Paulo Zemek wrote:

                    N3 is added twice.

                    That was my typo. ;) Marc

                    V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                    P 1 Reply Last reply
                    0
                    • M Marc Clifton

                      Paulo Zemek wrote:

                      N3 is added twice.

                      That was my typo. ;) Marc

                      V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                      P Offline
                      P Offline
                      Paulo Zemek
                      wrote on last edited by
                      #20

                      Hehe... OK. I thought I was another coding horror... you know, complete lack of testing.

                      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