Length of a line of code


  • I am curious if anyone out there limits the length of a line of code.  Lately, I've been growing tired of having to constantly scroll to the right just to see someone's full line of code (some of the code we have is over 300 characters long).  Is this something others have been getting annoyed with?  If so, at what character length are you truncating your code?


    Friday, April 7, 2017 7:48 PM


All replies

  • Hello,

     Do you have a link to a post, code snippet, or something so we can see

    what you describe as an issue?  There are many factors that would make

    a line of code exceed the Right Margin, such as IDE setup, Font size, and

    your screen.  Normally, to keep the project source neat and clear, lines

    of code ending with semi-colon and a new line is started. Rarely, except

    when the source is generated from Unix type OS is Line Feed only used.

    In Windows, Line Feed and Return (0x0A and 0x0D) codes are part of the

    trailing text input data.


     Thanks :)

    Friday, April 7, 2017 8:46 PM
  • I am aware the my IDE setting can have an impact on how the code look; however, 300 characters is still 300 characters; which is an extremely long line to be looking at.

    For example: in the following code snippet, the line with the using statement is slightly over 200 characters long and drives me nuts to look at:

    using (DbCommand command = await SetupDbComponentsAsync(commandText, isStoredProcedure, parameters, commandTimeout, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext))
        await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext);

    So, I've started breaking things up.  The same piece of code now looks like this:

    using (DbCommand command = await SetupDbComponentsAsync(
        await command.ExecuteNonQueryAsync(cancellationToken)

    I'm just wondering if anyone has imposed their own standards on how long to allow code to go before reformatting it so a single line of text doesn't exceed said number of characters.

    Friday, April 7, 2017 9:33 PM
  • The most relevant answer I can give is that the mono guidelines call for max 180 chars.

    Obviously the days of 80 column punch cards are behind us, but readability and consistency are great reasons to have limits.

    • Marked as answer by da.3vil.coder Saturday, April 8, 2017 1:25 PM
    Saturday, April 8, 2017 4:12 AM
  • Hello,

     Yes, I see your point but those are rare cases of code. While some

    programmers use Using, I rarely do and probably don't when should.

     I have a fairly wide screen LCD and my IDE text editor is 10 pt. But,

    I have seen the code like your example. Not much can be done about

    it as its really not something we can enforce unless IDE does it.


    Thanks :)

    Saturday, April 8, 2017 12:26 PM
  • Oh... I didn't know that mono did that. That's exactly what I'm looking for; thank you very much.
    Saturday, April 8, 2017 1:21 PM