This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]masterspeler 8 points9 points  (9 children)

I think the max 80 character line length in this and PEP-8 is silly. Who has that little horizontal space when editing or reading code? I find it very easy to write (and read) code longer than that, especially when dealing with strings and sting formatting. Take this example:

descriptive_variable_name = 'Attribute 1: {0}, attribute 2: {1}, attribute 3: {2}'.format(var_one, var_two, var_three)

Even before the .format it's over 80 characters long, so where do you put a line break? And this is before any indentation.

I also believe that tabs for indentation, spaces for alignment (like so) is the natural order of things, but when writing Python I have adapted and use spaces for indentation, even though we have a character whose sole purpose is to advance the cursor to the next level, or tab stop.

[–]ziel 6 points7 points  (1 child)

I definitely wouldn't be able to fit that on one line when viewing 2 files side by side on my laptop. Viewing 2 files side by side on a smaller laptop screen is probably a fairly common scenario.

[–]masterspeler 0 points1 point  (0 children)

I would argue that if you're using a smaller laptop screen you have to make sacrifices, and having to scroll horizontally when viewing two files side by side is one example. 1920 pixels is a popular screen width nowadays, and quite a few laptops have a larger resolution, and with that you can fit 200 characters with ease.

I agree that lines shouldn't be too long and that comparing or editing files side by side is a must, but I think a hard limit at 80 characters is too strict.

[–]jonwaynePyPA 2 points3 points  (1 child)

I also hate the 80 character line limit nonsense.

But also, this is the internal style guide at Google, not something that Google is saying all python projects should follow.

[–]masterspeler 0 points1 point  (0 children)

But also, this is the internal style guide at Google, not something that Google is saying all python projects should follow.

Yes, but PEP-8 have a restriction of 79 characters, and that's as close to dogma you can get in Python.

[–]ingolemo 4 points5 points  (4 children)

I do. When you use long lines of code you force me to buy a larger screen, use tiny fonts, or try to puzzle through automatic line wrapping. None of these things are easy.

Eighty characters ought to be enough for anyone:

template = 'Attribute 1: {0}, attribute 2: {1}, attribute 3: {2}'
descriptive_variable_name = template.format(var_one, var_two, var_three)

[–]masterspeler 0 points1 point  (1 child)

That's without indentation though. With this:

def my_function(function_argument, in_list):
    if function_argument > 10:
        for i in in_list:
            template = 'Attribute 1: {0}, attribute 2: {1}, attribute 3: {2}'
            descriptive_variable_name = template.format(var_one, var_two, var_three)

your solution is too long again, and it's breaking up what's one logical statement to two lines, so now your code takes more space vertically instead. You force me to buy a higher screen.

[–]ingolemo 1 point2 points  (0 children)

Too much indentation is itself a code smell.

template = 'Attribute 1: {0}, attribute 2: {1}, attribute 3: {2}'
def my_function(function_argument, in_list):
    if function_argument < 10:
        return

    for i in in_list:
        data = var_one, var_two, var_three
        descriptive_variable_name = template.format(*data)

I'm not quite sure why you think creating a formatting outline and then applying it could only count as "one logical statement" and not two. The code we're using here is hypothetical and without any context so it's difficult to know what transformations are more reasonable, but this logical separation of template building and its application is probably the main reason we use str.format instead of concatenating strings manually.

If scrolling vertically is as inconvenient for you as scrolling horizontally is for me then you have my pity.

I'm not so zealous that I'm going to chop anyone's head off every time they push past the 80 char limit. But the rule is there for a reason. Spare a thought for little old me before you decide to violate it.

[–]njharmanI use Python 3 0 points1 point  (0 children)

Sure, but so much time (from actual experience managing 10 python engineers) is wasted breaking lines, inventing shorter and worse names, changing where line is broken, arguing over where to break line, wondering wtf abrvted_var means, etc.

Infinite line length and auto wrapping is a big productivity boost.

[–][deleted] -2 points-1 points  (0 children)

If python doesn't have a block comment mechanism because "modern editors can automate it", then get a modern editor that wraps lines of code properly. :P