A
A
Andrey2016-01-17 15:08:24
Python
Andrey, 2016-01-17 15:08:24

What is the maximum length of a line of code in Python?

Hello!
1. What is the maximum length of a line of code in Python? 79 or 119?
2. Why is this restriction needed at all?
3. Do you follow this rule in your code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-01-17
@sim3x

3. Compliance with the limit of 120 - greatly simplifies the code reading

A
abcd0x00, 2016-01-17
@abcd0x00

2. Why is this restriction needed at all?

This option has several aspects.
1)
The oldest reason is the size of the editor window. There used to be terminals and there was a standard size of 80x24 (80 columns by 24 lines). Accordingly, long lines were ugly wrapped or climbed over the edge into the invisible area (depending on the editor). There may still be reasons, but from the same area.
2)
There is such a rule: one operator - one line. It has to do with debuggers. When a statement error occurs in the debugger, it indicates the line where the error occurs. If there are several statements in a line, then it is not clear which of them is the error, and you have to separate them into different lines and run it all over again. It takes time, time turns into hours, hours into days.
3)
There are ordinary brains of a person who reads the code. In the brain, everything is divided into conscious and unconscious (outside of consciousness). Consciousness can hold no more than 7 objects at the same time. If there are more objects, the unconscious helps him to group them into 7 objects anyway (only a few become groups). Therefore, the longer the line, the longer you think about it (time is spent on these groupings of extra objects into groups).
4)
There are also comments in some languages, where in order to comment on a fragment, you need to transfer it to a separate line. Therefore, when operators are on the same line, you cannot comment out one of them right there. That is, either you separate them into different lines, or you save time and do not check something that should have been checked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question