Programmers are paid to write the code once, but many people will likely read the code several times.Įvery Python developer needs to take this into account. When it comes to Python, readability should always be the top priority. That said, this aphorism indicates that programmers should never compromise readability to fit all the functionality in one line of code. In some situations, writing solutions that way is justified. This is not to say that one-liners are bad. There’s an entire culture behind doing complicated tasks in one line of code. Programmers often feel the need to emphasize their skills with over-elaborate code. Sticking to a flat structure is the best way to keep your programs simple. But when you add more subcategories into the mix, the code becomes more and more complicated. This isn’t to say that putting all of your code in one top-layer module is a bad idea. However, organizing code in this way can create more confusion than organization. Many programmers believe that this pays off since order is better than chaos. It is common for programmers to have a knack for organizing things into categories and subcategories to separate their programs’ functionalities. In simple words, Python programmers should remember the limits of simplicity. Still, when simple solutions are impractical, you are better off implementing the complex solution. The meaning of this aphorism is that valuing simplicity over complexity may be the right way to go in most situations. But just like you wouldn’t wash the dishes with a pressure washer, you wouldn’t wash a car with a small scrubber. The previous observation and this one remind programmers that there are both simple and complex solutions to the same problem. While doing the dishes with a pressure washer is impractical, using the pressure washer may be the right way to go if you’re cleaning a car. Python programmers must avoid overcomplicating their solutions, even if they may look smart and work.Ĭomplicating your programs will ultimately do more damage, and your team will not appreciate it. Not to mention, it is a daft solution to the problem.īy the same token, writing complex code to solve a simple program is impractical. Pulling out a pressure washer to clean the dishes after dinner might be one way to go about it, but it’ll likely damage the plates. Put simply, you must write code that another programmer with no previous knowledge of the program should be able to understand how it’s working. Python programmers need to do everything they can to ensure that the functionality of their code doesn’t get hidden behind hard-to-understand language. The idea behind this aphorism is that writing verbose code is better than writing indirect code. But many fail to implement it when they code. Reading this observation, one could conclude that it’s self-explanatory. Removing unnecessary conditions and simplifying your solutions will make your code beautiful. In other words, if a program works fine, it does not mean it’s beautiful and elegant. However, the rule of thumb is that the code must be easy to understand for any developer looking at it. Ideally, the code needs to be readable and elegant.īut what makes code “beautiful”? Just like in life, beauty is subjective in Python programming. Programmers are problem-solving experts, but since writing, documenting, and maintaining Python code is typically a team effort, plainly crafting a solution to a problem is not enough. The Zen of Python: A Breakdown #1 Beautiful is Better Than Ugly We discuss the meanings of the aphorisms and how they can help you improve your code in this post. Python includes the collection as an easter egg, and you can read the list of aphorisms by running “import this” on the interpreter. Bearing these observations in mind when writing code is not mandatory, but it certainly helps ensure quality code. The collection was standardized in 2004 as PEP 20 since it significantly impacted the Python community’s programming process. While the original collection had 20 aphorisms, Guido van Rossum dismisses the final one as a bizarre joke by Peters. The Zen of Python is a collection of 19 observations noted by Tim Peters, one of the creators of Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |