![]() |
.. (לתיקייה המכילה) | |
Below are a few reminders of common coding errors and tips on how to avoid them, with examples relevant to the wet assignments.
Code Duplication | |
Rewriting (or copy-pasting) large code segments which are logically identical throughout your code can (and will!) force you to invest more time in debugging or changing your code in general. Use tools you've learned in order to prevent code duplication, such as adding additional functions, template functions or classes etc. Merge identical code segments Examples: Writing many tree classes that perform the same logical functions. (In this particular case, template classes would have prevented the unnecessary work). |
"Magic Numbers" | |
Use of numeric constants throughout your code will make it harder for you to remember their meaning, and will prove problematic when these constants will have to be changed throughout the code (due to logical changes or finding of errors). Define constants and name them (using #define, enum, or const) |
Long Functions | |
Writing functions that span hundreds of lines of code, will make it harder for you to debug your code and follow its logic when verifying/modifying it. Write shorter functions, by removing redundancy, simplifying your code and writing functions to replace well-defined logical portions of long functions |
Poor Modularity | |
Writing a class without the functionality needed of it will force you to re-write said functionality over and over again, every time it is needed (which brings us back to the note concerning long functions and code duplication). Concentrate the necessary functionality of your classes within the classes themselves Examples: Writing code to find/add/remove from data structures in classes containing them. Writing functions for destroying a data structure in a containing class. |