Coding For Dummies
Book image
Explore Book Buy On Amazon

Python has its own set of design principles that guide how the rest of the language is structured. There are nineteen design principles that describe how the Python language is organized. Some of the most important principles include

  • Readability counts: This is possibly Python’s most important design principle. Python code looks almost like English, and even enforces certain formatting, such as indenting, to make the code easier to read. Highly readable code means that six months from now when you revisit your code to fix a bug or add a feature, you will be able to jump in without trying too hard to remember what you did. Readable code also means others can use your code or help debug your code with ease.

    Reddit.com is a top-10-most-visited website in the US, and a top-50-most-visited website in the world. Its co-founder, Steve Huffman, initially coded the website in Lisp and switched to Python because Python is “extremely readable, and extremely writeable”.

  • There should be one — and preferably only one — obvious way to do it: This principle is directly opposite to Perl’s motto, “There’s more than one way to do it.” In Python, two different programmers may approach the same problem and write two different programs, but the ideal is that the code will be similar and easy to read, adopt, and understand. Although Python does allow multiple ways to do a task — as, for example, when combining two strings — if an obvious and common option exists, it should be used.

  • If the implementation is hard to explain, it’s a bad idea: Historically, programmers were known to write esoteric code to increase performance. However, Python was designed not to be the fastest language, and this principle reminds programmers that easy-to-understand implementations are preferable over faster but harder-to-explain ones.

Access the full list by design principles, which is in the form of a poem, by typing import this; into any Python interpreter, or by visiting Python's website. These principles, written by Tim Peters, a Python community member, were meant to describe the intentions of Python’s creator, Van Rossum, who is also referred to as the Benevolent Dictator for Life (BDFL).

About This Article

This article is from the book:

About the book author:

Nikhil Abraham is the CFO of Udacity, an education company that teaches technology skills that help launch or advance a career. Prior to joining Udacity, Nik worked at Codecademy where he taught beginning coders across a variety of professions. He is also author of Coding For Dummies and Getting a Coding Job For Dummies.

This article can be found in the category: