The code follows several best practices of Python programming, for example: Here's an example of how to follow best practices in Python, making maintainable and robust code: Names in one module do not conflict with the names in another. Different namespaces may coexist, but these are isolated from each other. Use namespaces to avoid conflicts while naming the variables. Namespaces are one honking great idea - let's do more of those! If the code is readable and easy to follow, some of the principles may be deviated to serve the purpose of practicality. Well, there is no alternative to experience. It's best to follow the standard best practices to develop the algorithm and write the code instead of trying to create a new approach. Special cases aren't special enough to break the rules. The code should be organized as flatly as possible. Too much nesting and hierarchy make the code hard to read and understand. Readability counts: The code uses variable names and clean formatting, making it easy to read and understand. Keep it simple: The algorithm to calculate the sum of the first n integer is straightforward. This simple and easy-to-understand code follows several of The Zen of Python principles such as: There are two implementations of the same problem, one is sparse and the other is dense. The squares of all numbers are calculated, and then sum of these squared are calculated. Here's a simple example where we have list of numbers. Making good use of line spacing and indentation helps improve readability. The use of sufficient comments in the code helps any developer who wants to understand and use the code in the future. Using appropriate, easy-to-understand names for variables and functions helps. Instead of compressing the code into one line or the minimum number of lines, it's better to keep the code sparse, spanning over multiple lines, for better readability. Writing one-liner codes that incorporates a lot of functionality may seem alluring to programmers, however, it becomes cumbersome to read. However, Python emphasizes well-thought-out and easy-to-use code. Often, developers are not concerned about the readability while coding. Make code readableįocus on simplicity, readability, and elegance. So the order might be a bit different than what is seen in this.py. These principles can be grouped into categories. Note: A video of Barry Warsaw singing The Zen of Python, which he composed himself, can be found on YouTube. These best practices are added into Python language in this.py module as a string object. However, these are good programming practices that define the Pythonic way of programming. While programming, these guidelines don't have to be strictly followed. Guido voluntarily stepped down from the title of Python’s BDFL in 2018. Note: Benevolent dictator for life (BDFL) is a title given to a small number of open-source software development leaders who retain the final say in disputes or arguments in the community. According to Tim Peters, these principles were his design philosophy while developing the language. Much of these guidelines are attributed toward the benevolent dictator of life (BDFL) BDFL is a title given to a small number of open-source software development leaders who retain the final say in disputes or arguments in the community of Python, Guido van Rossum. Today, the Zen of Python is considered a fundamental philosophy of the language and serves as a cornerstone of best practices for Python programming. In fact these were eventually incorporated into the official Python Enhancement Proposal (PEP20) in 2004. These so-called principles became very popular among the community of Python developers and had an influence on the development process. They first appear in a mailing list of Python programmers a thread called “The Way of Python”under a thread called "The Way of Python", in the form of a lyric. These guiding principles were first presented by Tim Peters, one of Python's founding contributors, in 1999. The Zen of Python is a set of golden principles or axioms for the best programming practices in Pythonic style.
0 Comments
Leave a Reply. |