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. Why String.Format?

Why String.Format?

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
14 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.
  • S SoMad

    I came across many of those in our code years ago from programmers that have since moved on. The first time I saw it I was thinking "Hmmm. This probably used to have some parameters in it and got modified for some reason". After seeing 5-10 more like that I was just thinking "Hmmm." :omg: Soren Madsen

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

    Well, I know the programmer who did this in our software. When asked why he did that he said "I thought that would be useful in case the string ever needed parameters". He was basically making our software 'future proof' :laugh:

    It's an OO world.

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

    S M K 3 Replies Last reply
    0
    • Sander RosselS Sander Rossel

      Well, I know the programmer who did this in our software. When asked why he did that he said "I thought that would be useful in case the string ever needed parameters". He was basically making our software 'future proof' :laugh:

      It's an OO world.

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

      S Offline
      S Offline
      SoMad
      wrote on last edited by
      #6

      Did you slap him or punch him in the stomach? :laugh: Soren Madsen

      Sander RosselS 1 Reply Last reply
      0
      • S SoMad

        Did you slap him or punch him in the stomach? :laugh: Soren Madsen

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

        Nope, that would have been very unwise. That guy is my boss! :laugh:

        It's an OO world.

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

        F 1 Reply Last reply
        0
        • F FireDog31262

          Just ran across some code today that makes me wonder about the caliber of programmers we have: value = String.Format("{0}", funcThatReturnsAString()); :confused::confused::confused::confused:

          No matter where you go, there you are...~?~

          R Offline
          R Offline
          RobCroll
          wrote on last edited by
          #8

          Was the code ported from C++? I haven't seen this one before but definitely seen stuff like this when using a tool to convert from one language to another.

          "You get that on the big jobs."

          F 1 Reply Last reply
          0
          • Sander RosselS Sander Rossel

            Nope, that would have been very unwise. That guy is my boss! :laugh:

            It's an OO world.

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

            F Offline
            F Offline
            FireDog31262
            wrote on last edited by
            #9

            Thing about this code is it was written very recently and by a so called senior developer.:confused::confused::confused:

            No matter where you go, there you are...~?~

            1 Reply Last reply
            0
            • R RobCroll

              Was the code ported from C++? I haven't seen this one before but definitely seen stuff like this when using a tool to convert from one language to another.

              "You get that on the big jobs."

              F Offline
              F Offline
              FireDog31262
              wrote on last edited by
              #10

              This was newly written code under an existing ASP.NET C# code base. It was written by a "supposedly" senior developer. :confused:

              No matter where you go, there you are...~?~

              1 Reply Last reply
              0
              • Sander RosselS Sander Rossel

                Well, I know the programmer who did this in our software. When asked why he did that he said "I thought that would be useful in case the string ever needed parameters". He was basically making our software 'future proof' :laugh:

                It's an OO world.

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

                M Offline
                M Offline
                Moshe Katz
                wrote on last edited by
                #11

                Right. Because adding

                String.Format

                later would be just too hard. Really, you actually might have to use the arrow keys or the mouse to select in the middle of the line. In truth, I know someone who would erase and retype the entire line to add something to the middle of it. I am fairly happy to report that he is now out of code and in management instead.

                1 Reply Last reply
                0
                • Sander RosselS Sander Rossel

                  Well, I know the programmer who did this in our software. When asked why he did that he said "I thought that would be useful in case the string ever needed parameters". He was basically making our software 'future proof' :laugh:

                  It's an OO world.

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

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

                  Would that be 80 proof to match the future whiskey needed to stomach it? :-D

                  1 Reply Last reply
                  0
                  • J jhunley

                    I've been maintaining a C++ codebase for several years now that has this type of thing all through it:

                    if (someErrorCondition)
                    {
                    char *msg = "Error 404\n";
                    char s[100];
                    sprintf(s, "%s", msg);
                    PrintErrorMessage(s);
                    }

                    as opposed to just:

                    if (someErrorCondition)
                    PrintErrorMessage("Error 404\n");

                    And this was in an embedded system, where they were constantly having to eliminate features because they had exceeded the limited code space or overflowed the stack!

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

                    I know the guy who wrote those... Gotta be the same guy....

                    1 Reply Last reply
                    0
                    • F FireDog31262

                      Just ran across some code today that makes me wonder about the caliber of programmers we have: value = String.Format("{0}", funcThatReturnsAString()); :confused::confused::confused::confused:

                      No matter where you go, there you are...~?~

                      R Offline
                      R Offline
                      Rahul Rajat Singh
                      wrote on last edited by
                      #14

                      Tell the original developer to use this

                      StringBuilder sb = new StringBuilder();
                      sb.Append(string.empty);
                      sb.Append(funcThatReturnsAString());
                      sb.Append(string.empty);

                      value = sb.ToString();

                      Tell him this is the standard way of doing this kind of stuff :laugh:

                      Every now and then say, "What the Elephant." "What the Elephant" gives you freedom. Freedom brings opportunity. Opportunity makes your future.

                      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