Always favor simplicity. Write the simplest code that will work. KISS. |
Always favor readability. Name your variables and methods as clearly and as descriptively as possible. |
Try to keep methods under 25 lines of code (excluding vertical spacing and comments). Break down your code into small functions that are easy to understand. If a method is over 30 lines of code, it should be refactored. |
Try to keep classes under 400 lines of code (excluding vertical spacing and comments). If a class is over 500 lines of code, it should be split out into separate classes that each do one thing. |
Try to keep your code DRY, extract duplicate code into methods. |
Try to include design-pattern names such as Bridge, Adapter, or Factory as suffix to class names where appropriate. |
Avoid duplicating constants. Separate into a config file. |
Always delete unreferenced files. |
Try to have lines less than 80 characters. If the line exceeds 160 characters, it should be refactored. |
Never have more than two nested calls on the same line. |
Never have methods with more than three levels of nesting. |
Never have methods with more than five parameters. Try to have no more than three parameters at most being passed into a method, and generally only two. |
Avoid having methods with out parameters. |
Avoid having methods with ref parameters. |
Avoid writing overloads for methods that you might use some day. Follow YAGNI principle. |
Never programmatically click a button to execute the same action you have written in the button click event. Rather, call the same method which is called by the button click event handler. |
Never hardcode a path or drive name in code. Get the application path programmatically and use relative path. |
Never assume that your code will run from drive "C:". You may never know, some users may run it from network or from a "Z:". |
Always in the application start up, do some kind of "self check" and ensure all required files and dependencies are available in the expected locations. Check for database connection in start up, if required. Give a friendly message to the user in case of any problems. |
Always if a wrong value found in the configuration file, application should throw an error or give a message and also should tell the user what are the correct values. |
Always return empty collections instead of null. |
Always remove dead code. |
Always remove unnecessary using statements. |
Created By
www.kellermansoftware.com
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by GregFinzer