Beauty is subjective, but code that is written without regard for how understandable it is often ugly to others. The computer will run unreadable code, but unreadable code is difficult for human programmers to maintain and debug. Programmers often write code quickly without concern for readability. Beautiful code can be thought of as easy to read and understand. Here’s my interpretation of these aphorisms: Like all good sets of moral codes, they contradict themselves to provide the most flexibility. In the end, these guidelines are opinions that programmers can argue for or against. The Zen of Python is also an Easter egg, or hidden joke, that appears when you run import this: > import this Your Python code doesn’t necessarily have to follow these guidelines, but they’re good to keep in mind. The Zen of Python by Tim Peters is a set of 20 guidelines for the design of the Python language and for Python programs. Experienced Python programmers use these techniques, so becoming familiar with them allows you to recognize them in real-world code. What counts as pythonic can vary from programmer to programmer, but it commonly includes the examples and practices I discuss here. In this chapter, I’ll provide several common ways of writing idiomatic Python code along with their unpythonic counterparts. Certain Python language features lend themselves to writing code in ways that have become known as pythonic. The next step is to learn its idioms, or Python-specific coding practices. To write Python code like a true Pythonista, you’ll need to know more than just the syntax and standard library. Every programming language describes itself as powerful: the official Python Tutorial begins with the sentence “Python is an easy to learn, powerful programming language.” But there’s no algorithm that one language can do that another can’t, and no unit of measurement to quantify a programming language’s “power” (although you certainly can measure the volume at which programmers argue for their favorite language).īut every language does have its own design patterns and gotchas that make up its strengths and weaknesses. Powerful is a meaningless adjective for programming languages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |