![]() Even if your code ends up being complex, each small part will be easier to time, debug and unit test! Pragmatism The key takeaway here is: if you’re coding something difficult, break it down into simpler parts. A c omplicated code is hard to understand in itself.A complex code is hard to understand because it involves a large number of different but related entities.The difference between complex and complicated is essential here: Modularity is the idea dividing up your code into components that can be separated and recombined to allow for greater flexibility and independence. So says the Zen! Errors should never pass silently. ![]() If you’ve ever debugged code, you know that having no doubt on the cause/location of your error save you a lot of time and effort. This concept applies even more to error handling. Making Python variable types explicit with type hints (12)įor example, a first practical way of making your code more explicit is to use type hints (introduced in PEP 484) and automatic type checkers ( mypy). There should be one- and preferably only one -obvious way to do it. Two parts of the Zen detail this concept: Explicit is better than implicit. Writing explicit code means writing code that leaves no room for doubt. It’s important to put yourself in an uninformed (but Python fluent) person’s shoes when evaluating your code, since “ code is read much more often than it is written” ( Guido Van Rossum, Python’s benevolent dictator for life). In practice, several tools and standards can help follow these principles, from naming conventions ( PEP 8) to code formatters ( black). (1)Īnd of course the seventh: Readability counts. This brings me to the first line of the Python Zen: Beautiful is better than ugly. ![]() If you are a developer, chances are you’re going to be spending over 8 hours a day looking at code. To write clear code is to write code that is easy to perceive, understand, or interpret. ![]() Let’s take a look at the Zen’s philosophy, and how it can apply to our development practices! Clarity 5 years later, it had become such a standard amongst developers that PEP 20 (Python Enhancement Proposal) incorporated it into the official Python literature, creating the easter egg shown above. Written in 1999 by one of Python’s core developers, Tim Peters, the Zen of Python is a list of 19 aphorisms that state Python’s design philosophy. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |