Python Forum
"Limit all lines to a maximum of 79 characters" - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: "Limit all lines to a maximum of 79 characters" (/thread-19198.html)

Pages: 1 2


"Limit all lines to a maximum of 79 characters" - Skaperen - Jun-17-2019

"Limit all lines to a maximum of 79 characters" --PEP8

more text even urges limiting the width to 72 characters.

this is one thing i definitely will no longer follow. ironically, i was quite
strict about it as a C programmer. but i kept having trouble with it, especially
as i was moving to using more meaningful (longer) variable names. i started out
following this in Python. but it turned to be at least as much, if not more,
troublesome. it forced excess continuations, which hurt readability.

yes, older terminal screens needed this. but wider ones have been readily
available since then. and i find that reading 2 sources of code side-by-side,
especially when restricted in width, which can make some code continue to
another line when other code does not get continued, is very hard to do
(so much so that i find i never do this). better would be an editing tool that
can interleaving the 2 sources of code intelligently, such as by indentation
pattern, which can match up a different number of lines of code that
side-by-side can never possibly do.

ultimately, in many ways, i find readability is improved by not having this
limitation. i won't even limit it to 99 characters as PEP8 suggests deeper in
its discussion. what i will be doing is looking things over, more, if lines get
longer, especially if they exceed 160 characters. my terminal display goes all
the way to 172 characters, now. while i will try to keep lines reasonably short,
i will have no hard limits, not even at 172.

i have written a (simple enough that you can do it, too) script that tells me
the width of any ASCII or UTF8 file. you might want to use such a tool before
deciding how (or if) to display files from me.


RE: "Limit all lines to a maximum of 79 characters" - perfringo - Jun-17-2019


This thread
claims that reason for this limit is 'because an 80 char
wide Emacs window starts wrapping at 79.' from Guido van Rossum himself
Smile

But he has definitely said that “Code is read much more often than it is
written.”. And reading is done by people, not machines. If you have very long
lines of code it's harder for human to comprehend it (and of course 'readability
counts' dada-dada-blah-blah).

However, PEP8 has also chapter "A Foolish Consistency is the Hobgoblin of Little
Minds".


RE: "Limit all lines to a maximum of 79 characters" - Yoriz - Jun-17-2019

Please "Limit all lines to a maximum of 79 characters" --PEP8 in this thread Naughty


RE: "Limit all lines to a maximum of 79 characters" - Skaperen - Jun-17-2019

i do not understand applying the limit to the thread itself. the forum editor
takes in text without any newlines and outputs it likewise in HTML, allowing
the user's local browser to wrap lines (usually word wrapped) according to the
width and font size the local user has set. this is how i have always entered
text in all forums i use, including here. maybe more explanation is needed to
understand this?

i guess the 79 character limit was applied to the post input? does this mean
that we should do this? how is it done here? is it a mod tool?

you will find that my style of code, even in C, is "inconsistent" enough for
people to often complain about it. my style is more about readability on a
case-by-case basis. that means that i will choose what i do in each case based
on which way is most readable. yet, i still get complaints that my code is
"unreadable"". pressed on the issue, they usually reveal that just a few parts
of my code are harder to read than an alternate style i could have chosen (but
didn't). at the time i write the code i usually have only one reader to
evaluate readability. that reader is me.

is this post readable with the width limited to 79 characters?


RE: "Limit all lines to a maximum of 79 characters" - Yoriz - Jun-17-2019

The thread title triggered the Limit all lines to a maximum of 79 characters
moderator tool


RE: "Limit all lines to a maximum of 79 characters" - Skaperen - Jun-18-2019

so how do i edit the title?


RE: "Limit all lines to a maximum of 79 characters" - DeaD_EyE - Jun-18-2019

You can use black and if you want to learn, you could use flake8-black.

To wrap text, you can use textwrap.

I think the rest is clear and well explained.


RE: "Limit all lines to a maximum of 79 characters" - nilamo - Jun-19-2019

(Jun-17-2019, 08:11 PM)Yoriz Wrote: The thread title triggered the Limit all lines to a maximum of 79 characters
moderator tool

That's hilarious.

Personally, I don't put effort into maintaining <80 line lengths. It's only meaningful when looking at files side-by-side, and even then only moderately so.


RE: "Limit all lines to a maximum of 79 characters" - ichabod801 - Jun-19-2019

I do put effort into keeping code to a certain length, but I use 108 characters instead. Lines that are too long can be hard to understand, so I just use it as a guide for when I should break a line up to make it more readable. But I think 79 is too few characters, especially with indentation being a part of the language. I mean, in a class method with a loop and a conditional, you are now down to 63 characters. And that just encourages short variable names, making the code less readable. So there's a bit of balance there.

Guido has also said that PEP 8 was never meant to be the coding style for everything written in Python. It was just meant for the standard library, and isn't even followed rigorously there (I'm looking at you, unittest).


RE: "Limit all lines to a maximum of 79 characters" - Skaperen - Jun-19-2019

how did you happen to pick the number 108?