Where do you set your right margin?

  • Where do you set your right margin when coding?  To put that
    another way, if you have a long line of code, how long would it have to
    be for you to break it up into multiple lines. Obviously, sometimes you
    break even a small line for readibility.  But other times, you'll
    have just a really long line of code that's all one statement.  Do
    you have any rules for when to break it?  I'm thinking that 105
    characters is about right.

  • I use 120 - 160 if i'm not planning on accessing it on
    a terminal so that i can keep SQL queries in a single line ( e.g. "DELETE FROM {$GLOBALS['database_prefix']}pages WHERE id = '$id' LIMIT 1" ).
     Generally 80 is the most common for historical reasons ( 80*24
    terminals ).

  • I never, ever go past 80 columns. It doesn't matter how wide my screen
    is. Long lines are always a chore to read, be it plain text or source

    As for where I break long lines, I have a simple rule: on a line like:

    long_variable_name = long_function_name(long_argument1, long_argument_two);

    I either break like that:

    long_variable_name =

        long_function_name(long_argument1, long_argument_two);

    or like that:

    long_variable_name = long_function_name(

        long_argument1, long_argument_two);

    if the first version doesn't fit whithin the margin. If I have a really
    long expression involving other operators than assignment, I break
    before an operator.

    It's not very uniform, but it makes the most readable code, IMO.

  • I keep long lines as long lines mostly, since breaking them up usually results in less legible code.

    Except where not. 🙂 It really all depends on the situation. There is no correct maximum line length.

    I add/subtract several things in onse statement, I usually do this syntax:

    [code]var bladibla = getWidth('something')
       + sometothervalue
       + athirdvalue
       - thatvalue
        + 'finalize';

    Same goes for concatenating bits of string, such as long SQL statements:

    var foo = 'sdkjs ,ksb slvk el'
       + 'zsdm,vhjybsdvilblbvil sb l '
       + 'xvsdkgs elvisuhvlsuihodigei'
       + 'sdkjvguskdjgysfku';

    The separations aren't arbitray, of course, and not based on some random character count. I'm not sure, but mabye I or someone should do a benchmark to see if the [+] method is faster to run than the [variable +=] method. May not differ much anyway, though the +'s can easily be compiled away.

  • this is a test to see if I can use a TAB inside the [ code ] tag.
    if (this)
        do that;


  • Tarnation!

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.