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. The Lounge
  3. Do you Program in Paragraphs or Sentences?

Do you Program in Paragraphs or Sentences?

Scheduled Pinned Locked Moved The Lounge
comdebuggingquestionlearning
55 Posts 26 Posters 9 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.
  • R RandyBuchholz

    This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

    // Not me
    string Foo(int x)
    {
    if(x == 1)
    {
    return "one";
    }
    else
    {
    return "not one";
    }
    }
    }

    // sometimes me
    string Foo(int x){
    if (x == 1) {
    return "one";
    } else {
    return "not one";
    }
    }

    // usually me
    string Foo(int x) => (x == 1) ? "one" : "not one";

    // often me
    string Foo(this int x) => (x == 1) ? "one" : "not one";

    I do things like this. (Not really this weird though :)).

    public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
    public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
    public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

    So I can write in sentences

    var list = new List {"a", "Hello", "c"};

    list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

    Instead of paragraphs. (something like (methods would be a little different))

    var list = new List {"a", "Hello", "c"};
    if(list.count > 0){
    foreach(var i in list){
    var (condition, temp) = Prepare(i);
    if(condition != null){
    Manipulate(temp);
    }
    }
    }

    Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

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

    Sentences. I use Linq, extension methods, and fluent style, meaning methods often return this rather than a value, which can be accessed through a getter property if necessary. And tuples! I love tuples! Again, a useful, common to other languages not just C#, that the juniors have never seen. The result looks a lot more like F# with its continuation and partial closure syntax. Sadly, even though the code "reads" easily enough, it boggles the mind of the junior devs. And the really sad thing is, the junior devs don't even know about the null continuation operator, so the first question I get is, WTF is ?. As per my previous post, there's dumbing down, and then there's just lobotomy dumb. The null continuation operator is such a nice shorthand vs. cluttering code with if-else statements. So you'll see a lot of my code that looks like GetXmlElement(Constants.MyElement)?.Value ?? Constants.MyElementDefaultValue); but again, the junior devs are totally flustered by the ?. ?? notation. Oh well, they need to learn. This notation (or equivalent) is common enough in other languages nowadays, so LEARN, GFD!!!! [edit]And worse, the juniors have never been mentored to NOT code literal strings, so their code is littered with literals. X| And of course, when something needs changing, you have to search the entire code base for all references. X| X| [edit] For example, I find this totally readable:

            new List<Control>()
            {
                tbCashDrawerOnes,
                tbCashDrawerTwos,
                tbCashDrawerFives,
                tbCashDrawerTens,
                tbCashDrawerTwenties,
                tbCashDrawerFifties,
                tbCashDrawerHundreds
            }.ForEach(ctrl => ctrl.TextChanged += (\_, \_\_) => ignoreCashDrawerTextBoxEvents.Else(() => UpdateCashDrawer()));
    

    But it is esoteric, I suppose.

    Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript 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

    1 Reply Last reply
    0
    • D dbrenth

      I think the difference is in debugging. If there is an error in your "Sentence" code, the debugger stops at that line and you have at least 5 points of failure on that line to check. You might end up turning it back into a paragraph before you figure it out. With the "paragraph", the debugger stops at the specific line with the error. I usually prefer the paragraph method, for that reason.

      Brent

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

      dbrenth wrote:

      I think the difference is in debugging.

      This is true. Happily the VS2017 debugger is much better (than previous versions of VS) about being able to step into (and even set breakpoints on) anonymous methods. The problem I tend to encounter with complex lambda expressions is, one misplaced , or paren or other typo and the whole expression syntax-errors with really no clue as to what the parser is actually annoyed about.

      Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript 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

      1 Reply Last reply
      0
      • R RandyBuchholz

        This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

        // Not me
        string Foo(int x)
        {
        if(x == 1)
        {
        return "one";
        }
        else
        {
        return "not one";
        }
        }
        }

        // sometimes me
        string Foo(int x){
        if (x == 1) {
        return "one";
        } else {
        return "not one";
        }
        }

        // usually me
        string Foo(int x) => (x == 1) ? "one" : "not one";

        // often me
        string Foo(this int x) => (x == 1) ? "one" : "not one";

        I do things like this. (Not really this weird though :)).

        public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
        public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
        public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

        So I can write in sentences

        var list = new List {"a", "Hello", "c"};

        list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

        Instead of paragraphs. (something like (methods would be a little different))

        var list = new List {"a", "Hello", "c"};
        if(list.count > 0){
        foreach(var i in list){
        var (condition, temp) = Prepare(i);
        if(condition != null){
        Manipulate(temp);
        }
        }
        }

        Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

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

        Technically: list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r)); Would work as well as: list.ForEach(s => s.Prepare(out var r)?.Manipulate(r)); Given that an empty list is, well, empty. But again, to rant more about junior devs vs. experienced devs, IMO (as an experienced dev) a list should never be null. It should be empty or have content. But I see so many "if null" checks because nobody initializes their collections in the constructor, for example. And since the juniors are stuck in the dark ages because they don't get training, even: list?.ForEach(s => s.Prepare(out var r)?.Manipulate(r)); is unknown to them, though I'd still squawk at them for having a null list. Then again, I've also seen the null continuation operator abused in ways that tell me the programmer really had no right to be writing code: [Code Review - What You Can Learn From a Single Line of Code](https://www.codeproject.com/Articles/1223338/Code-Review-What-You-Can-Learn-From-a-Single-Line)

        Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript 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

        Richard DeemingR R 2 Replies Last reply
        0
        • E Eric Lynch

          Personally, when chaining method calls, I like the LINQ convention of each method call in the chain on a separate line. So the following, from your example:

          list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

          Becomes:

          list
          .WhenNotEmpty()?
          .ForEach(s => s
          .Prepare(out var r)?
          .Manipulate(r));

          Might just be me, but I find it easier to read that way. That said, not sure I completely follow the sentence / paragraph analogy :)

          S Offline
          S Offline
          Slacker007
          wrote on last edited by
          #18

          Eric Lynch wrote:

          Might just be me,

          I do it too.

          1 Reply Last reply
          0
          • M Marc Clifton

            Technically: list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r)); Would work as well as: list.ForEach(s => s.Prepare(out var r)?.Manipulate(r)); Given that an empty list is, well, empty. But again, to rant more about junior devs vs. experienced devs, IMO (as an experienced dev) a list should never be null. It should be empty or have content. But I see so many "if null" checks because nobody initializes their collections in the constructor, for example. And since the juniors are stuck in the dark ages because they don't get training, even: list?.ForEach(s => s.Prepare(out var r)?.Manipulate(r)); is unknown to them, though I'd still squawk at them for having a null list. Then again, I've also seen the null continuation operator abused in ways that tell me the programmer really had no right to be writing code: [Code Review - What You Can Learn From a Single Line of Code](https://www.codeproject.com/Articles/1223338/Code-Review-What-You-Can-Learn-From-a-Single-Line)

            Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript 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

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #19

            Marc Clifton wrote:

            a list should never be null

            There's one feature of C# 8 you'll like, then! :) csharplang/nullable-reference-types.md at master · dotnet/csharplang · GitHub[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            M 1 Reply Last reply
            0
            • M Marc Clifton

              Technically: list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r)); Would work as well as: list.ForEach(s => s.Prepare(out var r)?.Manipulate(r)); Given that an empty list is, well, empty. But again, to rant more about junior devs vs. experienced devs, IMO (as an experienced dev) a list should never be null. It should be empty or have content. But I see so many "if null" checks because nobody initializes their collections in the constructor, for example. And since the juniors are stuck in the dark ages because they don't get training, even: list?.ForEach(s => s.Prepare(out var r)?.Manipulate(r)); is unknown to them, though I'd still squawk at them for having a null list. Then again, I've also seen the null continuation operator abused in ways that tell me the programmer really had no right to be writing code: [Code Review - What You Can Learn From a Single Line of Code](https://www.codeproject.com/Articles/1223338/Code-Review-What-You-Can-Learn-From-a-Single-Line)

              Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript 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

              R Offline
              R Offline
              RandyBuchholz
              wrote on last edited by
              #20

              Interesting comment. I was returning the null to abuse the nullco and short circuit the chain, even though the (actual) list itself isn't null, just empty. But you make a good point about things that shouldn't be null. Returning a null when empty does (though only shortly until the nullco) create a null list. Not using the nullco immediately after would turn a null list loose.

              1 Reply Last reply
              0
              • R RandyBuchholz

                Maintenance can definitely be harder. Sometimes when I do it this way I have to expand the code to debug and then collapse it back down. I think reading it is a little like shorthand. Once you get used to it, you get a lot of information in a small package.

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #21

                I'm with Slacker on this, maintenance is the highest cost of software, make it readable and as simple as possible. Spell it out, let me know why you did something not just what you did. Convoluted, over engineered code is a nightmare for someone else to work with.

                Never underestimate the power of human stupidity RAH

                1 Reply Last reply
                0
                • R RandyBuchholz

                  This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

                  // Not me
                  string Foo(int x)
                  {
                  if(x == 1)
                  {
                  return "one";
                  }
                  else
                  {
                  return "not one";
                  }
                  }
                  }

                  // sometimes me
                  string Foo(int x){
                  if (x == 1) {
                  return "one";
                  } else {
                  return "not one";
                  }
                  }

                  // usually me
                  string Foo(int x) => (x == 1) ? "one" : "not one";

                  // often me
                  string Foo(this int x) => (x == 1) ? "one" : "not one";

                  I do things like this. (Not really this weird though :)).

                  public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
                  public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
                  public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

                  So I can write in sentences

                  var list = new List {"a", "Hello", "c"};

                  list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                  Instead of paragraphs. (something like (methods would be a little different))

                  var list = new List {"a", "Hello", "c"};
                  if(list.count > 0){
                  foreach(var i in list){
                  var (condition, temp) = Prepare(i);
                  if(condition != null){
                  Manipulate(temp);
                  }
                  }
                  }

                  Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

                  M Offline
                  M Offline
                  Munchies_Matt
                  wrote on last edited by
                  #22

                  Your coding style sucks.

                  1 Reply Last reply
                  0
                  • R RandyBuchholz

                    This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

                    // Not me
                    string Foo(int x)
                    {
                    if(x == 1)
                    {
                    return "one";
                    }
                    else
                    {
                    return "not one";
                    }
                    }
                    }

                    // sometimes me
                    string Foo(int x){
                    if (x == 1) {
                    return "one";
                    } else {
                    return "not one";
                    }
                    }

                    // usually me
                    string Foo(int x) => (x == 1) ? "one" : "not one";

                    // often me
                    string Foo(this int x) => (x == 1) ? "one" : "not one";

                    I do things like this. (Not really this weird though :)).

                    public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
                    public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
                    public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

                    So I can write in sentences

                    var list = new List {"a", "Hello", "c"};

                    list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                    Instead of paragraphs. (something like (methods would be a little different))

                    var list = new List {"a", "Hello", "c"};
                    if(list.count > 0){
                    foreach(var i in list){
                    var (condition, temp) = Prepare(i);
                    if(condition != null){
                    Manipulate(temp);
                    }
                    }
                    }

                    Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

                    G Offline
                    G Offline
                    GenJerDan
                    wrote on last edited by
                    #23

                    Paragraphs, then collapse all the functions I'm not actively messing around with.

                    We won't sit down. We won't shut up. We won't go quietly away. YouTube, VidMe and My Mu[sic], Films and Windows Programs, etc. and FB

                    K 1 Reply Last reply
                    0
                    • R RandyBuchholz

                      This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

                      // Not me
                      string Foo(int x)
                      {
                      if(x == 1)
                      {
                      return "one";
                      }
                      else
                      {
                      return "not one";
                      }
                      }
                      }

                      // sometimes me
                      string Foo(int x){
                      if (x == 1) {
                      return "one";
                      } else {
                      return "not one";
                      }
                      }

                      // usually me
                      string Foo(int x) => (x == 1) ? "one" : "not one";

                      // often me
                      string Foo(this int x) => (x == 1) ? "one" : "not one";

                      I do things like this. (Not really this weird though :)).

                      public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
                      public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
                      public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

                      So I can write in sentences

                      var list = new List {"a", "Hello", "c"};

                      list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                      Instead of paragraphs. (something like (methods would be a little different))

                      var list = new List {"a", "Hello", "c"};
                      if(list.count > 0){
                      foreach(var i in list){
                      var (condition, temp) = Prepare(i);
                      if(condition != null){
                      Manipulate(temp);
                      }
                      }
                      }

                      Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

                      S Offline
                      S Offline
                      soulesurfer
                      wrote on last edited by
                      #24

                      In your example:

                      list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                      The WhenNotEmpty()?. isn't really needed, is it?

                      R 1 Reply Last reply
                      0
                      • R RandyBuchholz

                        This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

                        // Not me
                        string Foo(int x)
                        {
                        if(x == 1)
                        {
                        return "one";
                        }
                        else
                        {
                        return "not one";
                        }
                        }
                        }

                        // sometimes me
                        string Foo(int x){
                        if (x == 1) {
                        return "one";
                        } else {
                        return "not one";
                        }
                        }

                        // usually me
                        string Foo(int x) => (x == 1) ? "one" : "not one";

                        // often me
                        string Foo(this int x) => (x == 1) ? "one" : "not one";

                        I do things like this. (Not really this weird though :)).

                        public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
                        public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
                        public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

                        So I can write in sentences

                        var list = new List {"a", "Hello", "c"};

                        list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                        Instead of paragraphs. (something like (methods would be a little different))

                        var list = new List {"a", "Hello", "c"};
                        if(list.count > 0){
                        foreach(var i in list){
                        var (condition, temp) = Prepare(i);
                        if(condition != null){
                        Manipulate(temp);
                        }
                        }
                        }

                        Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

                        M Offline
                        M Offline
                        maze3
                        wrote on last edited by
                        #25

                        Ah good, learnt something new first thing in the morning, now the rest for the day. the this class extensions parameter looks interesting. Might see if can use a bit of it. thanks

                        1 Reply Last reply
                        0
                        • R RandyBuchholz

                          This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

                          // Not me
                          string Foo(int x)
                          {
                          if(x == 1)
                          {
                          return "one";
                          }
                          else
                          {
                          return "not one";
                          }
                          }
                          }

                          // sometimes me
                          string Foo(int x){
                          if (x == 1) {
                          return "one";
                          } else {
                          return "not one";
                          }
                          }

                          // usually me
                          string Foo(int x) => (x == 1) ? "one" : "not one";

                          // often me
                          string Foo(this int x) => (x == 1) ? "one" : "not one";

                          I do things like this. (Not really this weird though :)).

                          public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
                          public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
                          public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

                          So I can write in sentences

                          var list = new List {"a", "Hello", "c"};

                          list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                          Instead of paragraphs. (something like (methods would be a little different))

                          var list = new List {"a", "Hello", "c"};
                          if(list.count > 0){
                          foreach(var i in list){
                          var (condition, temp) = Prepare(i);
                          if(condition != null){
                          Manipulate(temp);
                          }
                          }
                          }

                          Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

                          J Offline
                          J Offline
                          Jacquers
                          wrote on last edited by
                          #26

                          I prefer funnels ;P [Modern Art: The Funnel - The Daily WTF](https://thedailywtf.com/articles/modern-art-the-funnel)

                          K 1 Reply Last reply
                          0
                          • R RandyBuchholz

                            This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

                            // Not me
                            string Foo(int x)
                            {
                            if(x == 1)
                            {
                            return "one";
                            }
                            else
                            {
                            return "not one";
                            }
                            }
                            }

                            // sometimes me
                            string Foo(int x){
                            if (x == 1) {
                            return "one";
                            } else {
                            return "not one";
                            }
                            }

                            // usually me
                            string Foo(int x) => (x == 1) ? "one" : "not one";

                            // often me
                            string Foo(this int x) => (x == 1) ? "one" : "not one";

                            I do things like this. (Not really this weird though :)).

                            public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
                            public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
                            public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

                            So I can write in sentences

                            var list = new List {"a", "Hello", "c"};

                            list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                            Instead of paragraphs. (something like (methods would be a little different))

                            var list = new List {"a", "Hello", "c"};
                            if(list.count > 0){
                            foreach(var i in list){
                            var (condition, temp) = Prepare(i);
                            if(condition != null){
                            Manipulate(temp);
                            }
                            }
                            }

                            Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

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

                            The one problem I have with the everything-on-one-line approach style of programming (which I also do a lot) is that it's impossible to debug. You don't get intermediate values and you don't get to set breakpoints at specific functions. The readability aspect is not that big of a deal, I can read it just fine (usually). However, since you write code only once and read and debug it a gazillion times I prefer to write my code so I can step through it. Sometimes I put it back together for readability afterwards. For example:

                            // Debuggable
                            var filtered = myList.Where(...);
                            var ordered = filtered.OrderBy(...);
                            var result = ordered.ToList();
                            return result;

                            // Readable
                            return myList
                            .Where(...)
                            .OrderBy(...)
                            .ToList();

                            Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                            K 1 Reply Last reply
                            0
                            • R RandyBuchholz

                              This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

                              // Not me
                              string Foo(int x)
                              {
                              if(x == 1)
                              {
                              return "one";
                              }
                              else
                              {
                              return "not one";
                              }
                              }
                              }

                              // sometimes me
                              string Foo(int x){
                              if (x == 1) {
                              return "one";
                              } else {
                              return "not one";
                              }
                              }

                              // usually me
                              string Foo(int x) => (x == 1) ? "one" : "not one";

                              // often me
                              string Foo(this int x) => (x == 1) ? "one" : "not one";

                              I do things like this. (Not really this weird though :)).

                              public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
                              public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
                              public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

                              So I can write in sentences

                              var list = new List {"a", "Hello", "c"};

                              list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                              Instead of paragraphs. (something like (methods would be a little different))

                              var list = new List {"a", "Hello", "c"};
                              if(list.count > 0){
                              foreach(var i in list){
                              var (condition, temp) = Prepare(i);
                              if(condition != null){
                              Manipulate(temp);
                              }
                              }
                              }

                              Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

                              K Offline
                              K Offline
                              KBZX5000
                              wrote on last edited by
                              #28

                              This I can parse and validate, at a glance, without trying:

                              string Foo(int x)
                              {
                              if(x == 1)
                              {
                              return "one";
                              }
                              else
                              {
                              return "not one";
                              }
                              }
                              }

                              This requires me to actually read the words on screen and consciously think about them:

                              string Foo(this int x) => (x == 1) ? "one" : "not one";

                              It's not "more clear" on a macro level. It's "more clear" to you personally. If you were one of my juniors, I'd reprimand you for using an esoteric personal style at work. If you were a senior colleague, I'd just skip all formalities and just stab you with a kitchen knife. :)

                              K 1 Reply Last reply
                              0
                              • L Lost User

                                missing a close brace in your first // sometimes me example. and yeah, sometimes I do the same with similar (obvious) crap.

                                This internet thing is amazing! Letting people use it: worst idea ever!

                                S Offline
                                S Offline
                                S Houghtelin
                                wrote on last edited by
                                #29

                                Lopatir wrote:

                                missing a close brace in your first // sometimes me example.

                                Definitely me sometimes. :laugh:

                                It was broke, so I fixed it.

                                1 Reply Last reply
                                0
                                • S soulesurfer

                                  In your example:

                                  list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                                  The WhenNotEmpty()?. isn't really needed, is it?

                                  R Offline
                                  R Offline
                                  RandyBuchholz
                                  wrote on last edited by
                                  #30

                                  No, not really in this case. Something like `.When(predicate)` that might have been better. Or following it with something where it did matter.

                                  S 1 Reply Last reply
                                  0
                                  • R RandyBuchholz

                                    No, not really in this case. Something like `.When(predicate)` that might have been better. Or following it with something where it did matter.

                                    S Offline
                                    S Offline
                                    soulesurfer
                                    wrote on last edited by
                                    #31

                                    I was saying that you can use an empty collection with foreach, which will basically do nothing. You shouldn't need anything there.

                                    R 1 Reply Last reply
                                    0
                                    • S soulesurfer

                                      I was saying that you can use an empty collection with foreach, which will basically do nothing. You shouldn't need anything there.

                                      R Offline
                                      R Offline
                                      RandyBuchholz
                                      wrote on last edited by
                                      #32

                                      Right. That's what I meant by "following it with something that did matter".

                                      1 Reply Last reply
                                      0
                                      • Richard DeemingR Richard Deeming

                                        Marc Clifton wrote:

                                        a list should never be null

                                        There's one feature of C# 8 you'll like, then! :) csharplang/nullable-reference-types.md at master · dotnet/csharplang · GitHub[^]


                                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

                                        Richard Deeming wrote:

                                        There's one feature of C# 8 you'll like, then!

                                        Quite so. Still, I wonder where they're going with this -- nullable value types are great, and so it makes sense that the complement, non-nullable reference types, should exist, it certainly provides symmetry. But oh boy, there are going to be thousands of warnings in the code base I work with at work when (if ever) they opt-in for this. But it'll probably be a few years before they get their build systems onto the C# 8, which by then they still will probably be several versions behind, as they are now. :^)

                                        Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript 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

                                        1 Reply Last reply
                                        0
                                        • R RandyBuchholz

                                          This was inspired by Marc Clifton's post [Dumbing down code so it can be maintained by junior devs](https://www.codeproject.com/Lounge.aspx?fid=1159&fr=126#xx0xx) I'm a horizontal programmer. I write chainable methods with (short) descriptive names. The top of my methods usually consists of a few "sentences" composed of these "words". If I can put my code on one line, (braces, etc.) I usually do. Eg, simple method:

                                          // Not me
                                          string Foo(int x)
                                          {
                                          if(x == 1)
                                          {
                                          return "one";
                                          }
                                          else
                                          {
                                          return "not one";
                                          }
                                          }
                                          }

                                          // sometimes me
                                          string Foo(int x){
                                          if (x == 1) {
                                          return "one";
                                          } else {
                                          return "not one";
                                          }
                                          }

                                          // usually me
                                          string Foo(int x) => (x == 1) ? "one" : "not one";

                                          // often me
                                          string Foo(this int x) => (x == 1) ? "one" : "not one";

                                          I do things like this. (Not really this weird though :)).

                                          public static List WhenNotEmpty(this List item) => (item.Count > 0) ? item : null;
                                          public static string Prepare(this string item, out string prepared) => ((prepared = item + "Appended") == "HelloAppended") ? "ok" : null ;
                                          public static void Manipulate(this string item, string stuff) => Debug.WriteLine($"{item}:{stuff}");

                                          So I can write in sentences

                                          var list = new List {"a", "Hello", "c"};

                                          list.WhenNotEmpty()?.ForEach(s => s.Prepare(out var r)?.Manipulate(r));

                                          Instead of paragraphs. (something like (methods would be a little different))

                                          var list = new List {"a", "Hello", "c"};
                                          if(list.count > 0){
                                          foreach(var i in list){
                                          var (condition, temp) = Prepare(i);
                                          if(condition != null){
                                          Manipulate(temp);
                                          }
                                          }
                                          }

                                          Getting to the point, (finally :zzz: ) The paragraphs approach is clearer at the micro level (the details are clear), but the sentences is clearer at the macro level (the overall intent is clear). Of course you can wrap this paragraph in a method. But when you don't: Do you tend to write more at the macro/sentence level or micro/paragraph level?

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

                                          Your first example has one great advantage: When your productivity is measured in number of code lines produced, it wins by a large margin. The disadvantage is that to get an overview over even a fairly trivial function that really should fit in a screenful, you have to flip back and forth though a pile of pages. In any sufficiently fancy editor you can split the window so you can correlate various parts of the function logic, but then you can fit half as much logic in each tile, and that may be too little! A second disadvantage: With all that whitespace (frequently, programmers add at least one blank line before and after every loop, after function initialization, ... everywhere!), you have to look really close to see where this function ends and the next function starts. Except that those blank line lovers usually also add a huge comment block before every function to explain that ThePriceOfApplesPerKilogram argument is the price of apples per kilogram, that pi has the value of 3.1415926535897932384626433 and similar essential information. To some of these programmers, "readability" is a synonym for "whitespace percentage". Sort of homeopathic programming: The more diluted, the more powerful. On the other hand: The APL ideal of "There is no programming task so complex that it cannot be solved in a single line of APL" goes too far for my taste. An example from Wikipedia -The game of Life: life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵} I put most regex in the same category. Geek & Poke: Yesterday's regex[^] I'd like to place myself in the middle of the road, but I cannot deny that those homeopatic programmers raises such protests in me that I lean somewhat over to the other side. If you cannot fit every function in its entirety on a single screenful, then you have used too much whitespace.

                                          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