To write a comment in Python, simply put the hash mark # before your desired comment: They describe parts of the code where necessary to facilitate the understanding of programmers, including yourself. Python Commenting BasicsĬomments are for developers. WRITE LINES OF YOUR FAVORITE TEXT EDITOR HOW TONow that you understand why it’s so important to comment your code, let’s go over some basics so you know how to do it properly. You can help ensure a smooth transition by choosing to comment your code from the outset of a project. Comments help other devs skim through your code and gain an understanding of how it all works very quickly. Using comments throughout your code can help other developers in situations like this one. It takes a few days before they can even help you maintain it! The new hires spend a lot of time stepping through your code line by line, trying to figure out how it all works. You used some quirky variable names and wrote with super terse syntax. The new devs work hard to quickly get up to speed, but within the first few days of working together, you’ve realized that they’re having some trouble. The only problem is, by the end of the year your “small Django project” has turned into a “20,000 lines of code” project, and your supervisor is bringing on additional developers to help maintain it. Comments take time to write and maintain, and you just don’t see the point. You understand your own code pretty well, so you don’t tend to use comments or any other sort of documentation, and you like it that way. Imagine you’re the only developer working on a small Django project. Be nice to Future You! When Others Are Reading Your Code Writing comments as you go is a great way to prevent the above scenario from happening. When it’s time to revisit it later down the line, they can spend hours trying to parse through what they wrote. Once the project is submitted, many developers are simply too tired to go back and comment their code. When a deadline is fast approaching, and hours in front of the computer have led to bloodshot eyes and cramped hands, that pressure can be reflected in the form of code that is messier than usual. Worst of all, you don’t have any comments in the script to tell you what’s what!ĭevelopers forget what their own code does all the time, especially if it was written a long time ago or under a lot of pressure. You were in such a rush at the time that you didn’t name your variables properly or even set your functions up in the proper control flow. You spend hours parsing through your old code, but you’re completely lost in the mess. It’s your job to maintain it, since you were the one who built it in the first place. WRITE LINES OF YOUR FAVORITE TEXT EDITOR PATCHWithin a few days, you’ve completely forgotten that you were supposed to go back and properly comment the code you wrote for Client A.įast forward six months, and Client A needs a patch built for that same service to comply with some new requirements. WRITE LINES OF YOUR FAVORITE TEXT EDITOR UPDATEYou make a mental note to go back and update the comments, but before you can put it on your to-do list, your boss comes over with a new project that you need to get started on immediately. The deadline comes, and you deploy the service, right on time. All that “extra” stuff-documentation, proper commenting, and so forth-you’ll add that later. You’re already on a tight deadline, so you decide to just make it work. Client A wants a last-minute deployment for their web service.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |