This shortened code is potentially harder to maintain because code maintainers are humans, and this short code is harder to read. We have reduced the number of lines of code but violated one of the fundamental laws of Python: ![]() Chained conditional or ternary statements: name = value if condition else value if condition2 else value2.This code block uses 2 Python language features to make the code shorter: You can check out How to Write Beautiful Python Code With PEP 8 for more on PEP 8. If your code is starting to look a bit like this map, then this is the tutorial for you.įirst, we’ll go through 4 metrics of complexity that can give you a scale to measure your relative progress in the mission to make your code simpler:Īfter you’ve explored the metrics, you’ll learn about a tool called wily to automate calculating those metrics.ġ x = 5 y = int ( input ( "Enter a number:" )) 2 equality = "is equal to" if x = y else "is less than" if x < y else "is more than" 3 print ( f " " )īut the result is hard to read, and PEP 8 has guidelines around maximum line length and line breaking. ![]() Here is a map of the Tokyo railway network to give you some perspective: Image: Tokyo Metro Co. To even the most experienced traveler, navigating central Tokyo can be mind-bogglingly complicated. There are the Toei and Tokyo Metro rapid-transport networks as well as the Japan Rail East trains going through Central Tokyo. The author of this article getting lost on the Tokyo Metro This is partly because Tokyo is a metropolis of over 30 million people, but it’s also because there are 3 networks overlapping each other. The Tokyo railway network is one of the most extensive and complicated in the world. The question isn’t so much, “Is my code complicated?” as, “Is my code more complicated than it needs to be?” ![]() If you’re writing code for NASA’s jet propulsion laboratory (literally rocket science), then it’s going to be complicated. The complexity of an application and its codebase is relative to the task it’s performing. Free Bonus: 5 Thoughts On Python Mastery, a free course for Python developers that shows you the roadmap and the mindset you’ll need to take your Python skills to the next level.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |