registration that (unexpectetly) sets automatically sessions/cookies Avoid functions with side effects: E.g.Should follow the "Open-Closed-Principle": Modules should be open for extensions and closed for modifications.Classes always should follow the "Single-Responsibility-Principle": Class should only one thing.Should always have one level of abstraction.Should always do one main thing (you can describe that "thing" in one meaningful sentence).Should not be longer than 5 lines of code.Functions should use verbs ("deletePage") or should be prefixed with set/get ("getName").Classes should be nouns ("Customer", "Account"). don't use "GSTzip", "GSTlocation", "GSTstreet", "GSTnumber" inside a class "GST") Be consistent (always use one of fetch/retrieve/get in different classes).Use searchable names ("realDaysPerDay" vs "d").Use pronounceable names ("generationTimestamp" vs "genymdhms").Use intention-revealing names ("elapsedTimeInDays" vs.The Boy Scout Rule: Leave the campground cleaner than you found it ("always refactor a little bit every time you work on your code").Presented as cheat sheet by CosteMaxime.Don't return null, don't pass null either.Use Exceptions instead of returning error codes.You cannot reuse parts of the code in other projects because of involved risks and high effort. The software breaks in many places due to a single change. A small change causes a cascade of subsequent changes. Prefer non-static methods to static methods.Better to have many functions than to pass some code into a function to select a behavior.Base class should know nothing about their derivatives.If your class have too many instance variable, then it is probably doing more than one thing. Avoid hybrids structures (half object and half data).Use white space to associate related things and disassociate weakly related.Place functions in the downward direction.Declare variables close to their usage.Related code should appear vertically dense.Don't use closing brace comments (e.g.: } // end of function).Don't be redundant (e.g.: i++ // increment i).If it's not possible, take your time to write a good comment. Always try to explain yourself in code.Split method into several independent methods that can be called from the client without the flag. Do one thing and they should do it well.Don't append prefixes or type information. Replace magic numbers with named constants.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |