Skip to main content

Enforce Newspaper Style with Flake

Motivation

Good code reads like a newspaper. Start with the highest abstraction, go to the details. This also enables to read the code without an editor.

Quoting Robert C. Martin from his Clean Code book.

“Think of a well-written newspaper article. You read it vertically. At the top, you expect a headline that will tell you what the story is about and allows you to decided whether it is something you want to read. The first paragraph gives you a synopsis of the whole story, hiding all the details while giving you the broad-brush concepts. As you continue downward, the details increase until you have all the dates, names, quotes, claims, and other minutiae. We would like a source file to be like a newspaper article.”

In Python newspaper code should look like this.

def headline():
    text()

def text():  # this needs to be defined after the usage.
    ...

There hasn't been an automatic way in python to check for this. So here it is.

Usage

# install the flake8 extension for newspaper style
pip3 install flake8-newspaper-style==1.2.3
# then check your code
flake8 --select=NEWS src  # here it restricts flake8 to newspaper style issues

References

Release files for flake8-newspaper-style 0.2.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-newspaper-style 0.2.9
File Size Uploaded
flake8-newspaper-style-0.2.9.tar.gz 3.5 kB Details

Release files / flake8-newspaper-style-0.2.9.tar.gz

Download URL flake8-newspaper-style-0.2.9.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a9cb98d88efd85da09161105e10fb7a74dbed93ec568ee055b59d03386b15b91
BLAKE2b-256 checksum
How to use checksums
a0b28539cc432a17845672fc5602033aa9897d368276cd9308cf78e6b5aeb272
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release history Release notifications | RSS feed

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.11

1 release file

0.2.10

1 release file

This release

0.2.9 This release

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page