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. No your line is too long.

No your line is too long.

Scheduled Pinned Locked Moved The Lounge
comquestionannouncement
45 Posts 20 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.
  • D dandy72

    I have zero problem with that. In fact, I'd much rather see a function's parameters being broken by parameter (one per line) rather than 3 on the first line, 2 on the second line, then 4 on the third line, etc. If it has to be broken down, go all the way. Then if a parameter consists of a function call, and that function needs so many parameters of its own that that line becomes long, then break it into multiple lines too, with an extra indentation level. Seems so logical to me.

    J Offline
    J Offline
    jschell
    wrote on last edited by
    #27

    dandy72 wrote:

    rather than 3 on the first line, 2 on the second line ...

    Same for me.

    1 Reply Last reply
    0
    • K k5054

      I can understand the motivation. I've seen, and perhaps perpetrated, something like:

      string someString = mything.something().somethingElse().foo().bar().bang().whiz().toString()

      Which can sometimes lead to very long lines. But any decent optimizer should be able to elide otherwise unused intermediate object so maybe

      auto something = mything.something();
      auto foobar = something().foo().bar();
      auto whiz = foobar().bang().whiz();
      string someString = whiz.toString();

      is preferable? But if you're going to keep the long version as a single statement, but write it over separate lines do you prefer putting the . at the end or the start of the line? e.g

      mything.something().
      foo().bar().whiz().
      bang().toString()

      vs

      mything.something()
      .foo().bar().whiz()
      .bang().toString()

      "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #28

      k5054 wrote:

      do you prefer putting the . at the end or the start of the line?

      Beginning. Makes it visually obvious when skimming that it is part of a preceding expression.

      1 Reply Last reply
      0
      • B bryanren

        I like that look. I try to write my SQL like that but have been leaving the dot-separators on the previous line in code. My thinking was to indicate that the line (command) was not yet finished. With this style, keeping each line short it is clear that each line is a continuation. With SQL, I have been cheating on that style to keep like fields on a single line: ... , fKey , LastName, FirstName, MidName , AddrLine1, AddrLine2, City, State, Country, Zip --, foo , bar ...

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #29

        bryanren wrote:

        SQL like that but have been leaving the dot-separators on the previous line in code.

        lol ... Really not obvious to me what you meant until I got to your example. I was crunching my brain trying to find when one would have multiple periods. Yes I use exactly that form for SQL also. Unlike with other expressions and even with parameters in C#/Java I still tend (always?) to put the comma at the end of the line rather than the beginning. No real reason although I could state that a comma is not part of an expression. But then I do it that way for SQL. So no way I can justify it.

        1 Reply Last reply
        0
        • M MarkTJohnson

          No, I meant the actual tilted monitor. Some Linux users are elitist looking down their noses at other operating systems, so being able to have a tilted monitor could be another example.

          I’ve given up trying to be calm. However, I am open to feeling slightly less agitated. I’m begging you for the benefit of everyone, don’t be STUPID.

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #30

          MarkTJohnson wrote:

          Some Linux users are elitist

          Not sure I have seen a technology yet where someone would not claim that theirs was better. And they always sputter when I ask what objective criteria they have for that.

          1 Reply Last reply
          0
          • O obeobe

            Diagonal mode wastes so much real estate with these triangles at the edges of the monitor. It just makes zero sense. And the conclusion that 22 degrees is the optimal angle is also not backed by any proof. AFAIR the article just said that "it was researched", which was.. weird.

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #31

            So you are saying that they get maybe three really long lines and then they have to make do with 20 or 30 lines that are maybe 10 characters or less. Sounds like a fitting punishment.

            O 1 Reply Last reply
            0
            • O obeobe

              Diagonal mode wastes so much real estate with these triangles at the edges of the monitor. It just makes zero sense. And the conclusion that 22 degrees is the optimal angle is also not backed by any proof. AFAIR the article just said that "it was researched", which was.. weird.

              J Offline
              J Offline
              Jan Holst Jensen2
              wrote on last edited by
              #32

              obeobe wrote:

              the conclusion that 22 degrees is the optimal angle is also not backed by any proof

              Must depend on the aspect ratio of the particular monitor. When that is known it should be really simple to calculate what angle to tilt the monitor in order to have the diagonal become horizontal. Other than that, I find the concept of diagonal mode hilarious :laugh: . And yes, a complete waste of space on the other parts of the screen.

              O J 2 Replies Last reply
              0
              • J jschell

                From CP newsletter https://www.codeproject.com/News.aspx?ntag=19837497829658814&_z=2928472[^] They want to run their monitors in a diagonal mode because? "Why 22 degrees? At that angle, you get the longest line length (stretching between opposite corners)" My answer to that - your line is too long. Make it shorter. You are not writing code for you but are writing it for the people in the future that must maintain it.

                O Offline
                O Offline
                obermd
                wrote on last edited by
                #33

                If it doesn't fit on a punch card it's too long.

                1 Reply Last reply
                0
                • J jschell

                  From CP newsletter https://www.codeproject.com/News.aspx?ntag=19837497829658814&_z=2928472[^] They want to run their monitors in a diagonal mode because? "Why 22 degrees? At that angle, you get the longest line length (stretching between opposite corners)" My answer to that - your line is too long. Make it shorter. You are not writing code for you but are writing it for the people in the future that must maintain it.

                  S Offline
                  S Offline
                  Shmoken99
                  wrote on last edited by
                  #34

                  Is it April 1 already? Wait. This isn't a joke?

                  1 Reply Last reply
                  0
                  • B bryanren

                    But there is a line from a Brit SciFi to the effect "I'm British, we know how to queue". Dent, Aurthur Dent.

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #35

                    Heh, I actually thought of that line while i typed what I did. But I can't go around quoting hitchhiker's guide to the galaxy all the time, despite having basically memorized the series. Douglas Adams was a regular Mark Twain.

                    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                    1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      At most one line that length. Try a smaller font -- I use 8pt. I also try to limit my line lengths to 112 characters. I used to use VT screens set to 132 characters per line. 132 characters per line ought to be enough for anybody.

                      U Offline
                      U Offline
                      User 11783308
                      wrote on last edited by
                      #36

                      With a readable size font, my maximum line length is 544 characters with 135 lines on the screen. I could do more with a slightly smaller font or perhaps a different font. That is not to say that I have written lines that long, I don't actually know how long that would be. We are not using punched cards anymore, we are not restricted to fan-fold paper -- who actually uses paper anymore? There is no unacceptable maximum for either the number of lines in a method / function or the length of a line. In both cases, I would expect the set of lengths to be a power distribution. Where the vast majority of function / line lengths are very short, and very long lengths would be extremely rare -- but no upper limit. The length of either a function or a line should be considered on a case by case basis. There are many times that the most important information in a line of code occurs in the first 20 or 30 characters. The best readability may be a very, very long line because the majority of the time the remainder of the line is not of interest when reading code. If there is a problem with lines that are too long, get a better monitor. My primary monitor is a 50" 4k monitor (actually TV, but that replaced a failed 48" 4k monitor because it was something like $200 instead of $2000). When available, and when I can afford it, my next monitor will be 55-65" and 8k. Even without a better monitor, just scroll left / right or up / down.

                      J 1 Reply Last reply
                      0
                      • J jschell

                        From CP newsletter https://www.codeproject.com/News.aspx?ntag=19837497829658814&_z=2928472[^] They want to run their monitors in a diagonal mode because? "Why 22 degrees? At that angle, you get the longest line length (stretching between opposite corners)" My answer to that - your line is too long. Make it shorter. You are not writing code for you but are writing it for the people in the future that must maintain it.

                        M Offline
                        M Offline
                        Member_5893260
                        wrote on last edited by
                        #37

                        I do actually find myself trying to stick to 80 lines, but some expressions just end up longer than that, with LINQ and so on - and in some cases, splitting the line makes it less readable. It's like this guy in a bar - the bartender bet him he couldn't drink the contents of the spittoon, so off he went, gagging and choking and turning blue, and kept going long after the bartender told him he could stop - and finally made it - and the bartender said, "Why didn't you stop?" and he replied, "I couldn't: it was all in one solid lump!"

                        J 1 Reply Last reply
                        0
                        • J jschell

                          So you are saying that they get maybe three really long lines and then they have to make do with 20 or 30 lines that are maybe 10 characters or less. Sounds like a fitting punishment.

                          O Offline
                          O Offline
                          obeobe
                          wrote on last edited by
                          #38

                          If it gets too long vertically then we can combine multiple approaches. In my code I don't get to 20 or 30 lines that are part of a single statement.. but if it happened to me, I'd probably split it up into multiple statements. It would probably also make it easier to debug/troubleshoot.

                          1 Reply Last reply
                          0
                          • J Jan Holst Jensen2

                            obeobe wrote:

                            the conclusion that 22 degrees is the optimal angle is also not backed by any proof

                            Must depend on the aspect ratio of the particular monitor. When that is known it should be really simple to calculate what angle to tilt the monitor in order to have the diagonal become horizontal. Other than that, I find the concept of diagonal mode hilarious :laugh: . And yes, a complete waste of space on the other parts of the screen.

                            O Offline
                            O Offline
                            obeobe
                            wrote on last edited by
                            #39

                            Quote:

                            it should be really simple to calculate what angle to tilt the monitor in order to have the diagonal become horizontal.

                            Yes, but where's the proof that making the diagonal horizontal is optimal for developers? (or for any other use case, for that matter).

                            J 1 Reply Last reply
                            0
                            • T trønderen

                              A long time ago, I read about a study - in a printed periodical, so no URL - where a number of test persons were split into two groups and given the same source code to study. One group got it laid out like ordinary prose, the way you would write a plain text? ("If the rain stops, let's go to the beach. Otherwise, let's break a bottle of wine!" in a single line). The other group got the same program laid out "the programming way", with conditions, if- and else-clauses on separate lines, with proper indentations etc. Similar for loops and other constructs. After the test persons had been given a controlled amount of time to study the code, they were to fill in a questionnaire to reveal how well they had understood the program logic. It turned out that those who had read the "prose formatted" program code scored significantly higher than those who had been reading the "program structured" layout. This is so many years ago that the average person still could be expected to read both fiction and non-fiction books. Today, lots of young people never read a novel after the Harry Potter books (which they chose when school required them to pick one novel to read). So maybe the results would be different today, with lots of people inexperienced with extracting meaning unless it is conveyed both in text, semantics highlighted with punctuation and structure mediated through blocks and indentation.

                              Religious freedom is the freedom to say that two plus two make five.

                              G Offline
                              G Offline
                              gggustafson
                              wrote on last edited by
                              #40

                              A citation would be helpful.

                              Gus Gustafson

                              1 Reply Last reply
                              0
                              • O obeobe

                                Quote:

                                it should be really simple to calculate what angle to tilt the monitor in order to have the diagonal become horizontal.

                                Yes, but where's the proof that making the diagonal horizontal is optimal for developers? (or for any other use case, for that matter).

                                J Offline
                                J Offline
                                Jan Holst Jensen2
                                wrote on last edited by
                                #41

                                Ah yes - *that* proof. Totally agree. That assertion *must* have been written tounge-in-cheek :) . At least, I very much hope so :laugh:

                                1 Reply Last reply
                                0
                                • U User 11783308

                                  With a readable size font, my maximum line length is 544 characters with 135 lines on the screen. I could do more with a slightly smaller font or perhaps a different font. That is not to say that I have written lines that long, I don't actually know how long that would be. We are not using punched cards anymore, we are not restricted to fan-fold paper -- who actually uses paper anymore? There is no unacceptable maximum for either the number of lines in a method / function or the length of a line. In both cases, I would expect the set of lengths to be a power distribution. Where the vast majority of function / line lengths are very short, and very long lengths would be extremely rare -- but no upper limit. The length of either a function or a line should be considered on a case by case basis. There are many times that the most important information in a line of code occurs in the first 20 or 30 characters. The best readability may be a very, very long line because the majority of the time the remainder of the line is not of interest when reading code. If there is a problem with lines that are too long, get a better monitor. My primary monitor is a 50" 4k monitor (actually TV, but that replaced a failed 48" 4k monitor because it was something like $200 instead of $2000). When available, and when I can afford it, my next monitor will be 55-65" and 8k. Even without a better monitor, just scroll left / right or up / down.

                                  J Offline
                                  J Offline
                                  jschell
                                  wrote on last edited by
                                  #42

                                  Member 11816776 wrote:

                                  There is no unacceptable maximum for either the number of lines in a method / function or the length of a line.

                                  By that argument then every code file you write should be one line. But the real argument in a business environment is that you are not writing code for yourself. You are writing it for the company. Which is why they pay you. And unless you are a deity someday someone else will need to modify that code. Matter of fact studies have shown that the cost of maintaining code is between 2 and 100 times as much as creating it in the first place. And the company must pay that. So a responsible professional developer should create code that one can reasonably be maintained by a future programmer and not the original author.

                                  Member 11816776 wrote:

                                  There are many times that the most important information in a line of code occurs in the first 20 or 30 characters. The best readability may be a very, very long line because the majority of the time the remainder of the line is not of interest when reading code.

                                  And yet your very statement points out that the rest of the line can be important.

                                  Member 11816776 wrote:

                                  If there is a problem with lines that are too long, get a better monitor

                                  No the solution then is during the code review to tell the author to reformat the line so it is shorter. I have even seen one review process where long lines could not even be viewed so one had to pop to view the file then find the line.

                                  1 Reply Last reply
                                  0
                                  • J Jan Holst Jensen2

                                    obeobe wrote:

                                    the conclusion that 22 degrees is the optimal angle is also not backed by any proof

                                    Must depend on the aspect ratio of the particular monitor. When that is known it should be really simple to calculate what angle to tilt the monitor in order to have the diagonal become horizontal. Other than that, I find the concept of diagonal mode hilarious :laugh: . And yes, a complete waste of space on the other parts of the screen.

                                    J Offline
                                    J Offline
                                    jschell
                                    wrote on last edited by
                                    #43

                                    Makes one wonder... If you use multiple monitors how does one arrange that? Side by side - so two diamonds with the points touching? Or one on top of the first so it is flat to first one? And what happens when you get a person that thinks 5 monitors is a good idea?

                                    1 Reply Last reply
                                    0
                                    • M Member_5893260

                                      I do actually find myself trying to stick to 80 lines, but some expressions just end up longer than that, with LINQ and so on - and in some cases, splitting the line makes it less readable. It's like this guy in a bar - the bartender bet him he couldn't drink the contents of the spittoon, so off he went, gagging and choking and turning blue, and kept going long after the bartender told him he could stop - and finally made it - and the bartender said, "Why didn't you stop?" and he replied, "I couldn't: it was all in one solid lump!"

                                      J Offline
                                      J Offline
                                      jschell
                                      wrote on last edited by
                                      #44

                                      Dan Sutton wrote:

                                      end up longer than that, with LINQ and so on

                                      LINQ itself lends (pretty much requires) longer lines but they can certainly be formatted. This is similar to formatting SQL in C#, Java, C++, etc when it is a string. The first try always starts out as one long string until one understands that it can be formatted in a way that makes it readable.

                                      Dan Sutton wrote:

                                      and in some cases, splitting the line makes it less readable.

                                      Not sure I believe that. But one can certainly reformat a long line in a way that makes it confusing. But that is a formatting problem rather than that the technique itself is flawed. A long line pretty much starts out being difficult to read/understand regardless of how it is formatted. Long lines will have 'parts'. So for example LINQ for a db has a data object, clauses, etc. SQL as a string has the same thing. If you write SQL in a stored proc it can be formatted in the same way. Keep in mind of course that for C#/Java/C++ line breaks are not required. So one can write a method (and even a class) on few or even one line. But very few would claim that is a good idea.

                                      M 1 Reply Last reply
                                      0
                                      • J jschell

                                        Dan Sutton wrote:

                                        end up longer than that, with LINQ and so on

                                        LINQ itself lends (pretty much requires) longer lines but they can certainly be formatted. This is similar to formatting SQL in C#, Java, C++, etc when it is a string. The first try always starts out as one long string until one understands that it can be formatted in a way that makes it readable.

                                        Dan Sutton wrote:

                                        and in some cases, splitting the line makes it less readable.

                                        Not sure I believe that. But one can certainly reformat a long line in a way that makes it confusing. But that is a formatting problem rather than that the technique itself is flawed. A long line pretty much starts out being difficult to read/understand regardless of how it is formatted. Long lines will have 'parts'. So for example LINQ for a db has a data object, clauses, etc. SQL as a string has the same thing. If you write SQL in a stored proc it can be formatted in the same way. Keep in mind of course that for C#/Java/C++ line breaks are not required. So one can write a method (and even a class) on few or even one line. But very few would claim that is a good idea.

                                        M Offline
                                        M Offline
                                        Member_5893260
                                        wrote on last edited by
                                        #45

                                        Yes - I understand how to program. But sometimes, it just doesn't make sense to split the line. Often, it does. But not always.

                                        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