![]() This is the same point as the previous one, just applied to input instead of output. It's better if those functions return numbers to be printed later by formatter function. Think about the task of using your code to make a web page: it's going to be hairy because your math functions have print statements in them. Do this by keeping results in a structure that preserves the semantics of the data, and defer formatting to the very end. ![]() Make it easy to affect how output is displayed. Not only do you have to change the code, but it's been months since you looked at it! You won't remember how everything works. Separate content from presentationĪ common pattern arises when you create something that's useful to someone (yourself, usually), later it becomes useful to other people, and those people need the output in a different format. Define pi with more digits, and shorten the result so that it shows the actual precision. You're displaying results with maximum "precision" but basing them on a value of pi that has only four significant figures. Especially here, where the change will affect the output in surprising and subtle ways. This is bad! Mangling user data is necessary sometimes and to be avoided otherwise. You're silently truncating the user's input with int(). In that light, here are things I'd do differently from what you have done. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |