Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pep8 suggest using two spaces in comments?

PEP-8 states:

You should use two spaces after a sentence-ending period.

In my usual refactoring, I am used to replacing such consecutive double spaces with a single one, thinking that this habit has come from the typewriter days (I have went through this Wikipedia page briefly).
Also most of the times I have seen mono-space fonts being used for the programming, so it's much clearer than the other cases which can sometimes need 2 spaces to easily identify sentences.

Is there any reason behind this being used in PEP-8?

like image 604
0xc0de Avatar asked Feb 05 '14 08:02

0xc0de


People also ask

Why does PEP8 prefer spaces?

The reason for spaces is that tabs are optional.

What does PEP8 say about the use of tabs or spaces?

Tabs or Spaces? Spaces are the preferred indentation method. Tabs should be used solely to remain consistent with code that is already indented with tabs. Python disallows mixing tabs and spaces for indentation.

What is PEP8 and why it is important?

PEP 8 is a document that provides various guidelines to write the readable in Python. PEP 8 describes how the developer can write beautiful code. It was officially written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The main aim of PEP is to enhance the readability and consistency of code.


2 Answers

Only those who authored the PEP can answer the "why" with any degree of certainty.

I've had a look at the standard library source code, and my conclusion is that this particular aspect of the style guide is not followed consistently: some standard modules follow it and some don't.

Until you pointed it out, I've never heard of the double space convention, and have never noticed anyone following it.

like image 72
NPE Avatar answered Sep 24 '22 18:09

NPE


The answer is simple: readability :)

like image 29
cpb2 Avatar answered Sep 23 '22 18:09

cpb2