What TIPS would you share on: How to write clean code / How to code the right way...
How can we write code that's easy to maintain in the future, a code that we'll be able to tell from a number of other codes. TIPS for any language are welcome....
10/23/2018 12:03:10 PMCholasni Anaims
4 AnswersNew Answer
Use Descriptive Names. What are variables, classes, and functions? ... Give Each Class/Function One Purpose. ... Delete Unnecessary Code. ... Readability > Cleverness. ... Keep a Consistent Coding Style. ... Choose the Right Architecture. ... Master the Language's Idioms. ... Study the Code of Masters.
1.) Make code readable for people. It is true that the code we write will be interpreted by machines. ... 2. ) Use meaningful names for variables, functions and methods. ... 3.) Let one function or method perform only one task. ... 4.) Use comments for clarification. ... 5.) Be consistent. ... 6.) Review your code regularly.
Don't write the code for yourself, write it for other people. Comment and document as much as you can, give variables clear names, have stucture in your code and use new lines where they make sense instead of keeping your code as short as possible.
Make sure you completely understand the task your program is going to perform! This sounds like 'duh', but actually if you are even a bit confused about how your algorithm should work, your code will also look confused. After you have whittled down the series of operations to the minimal number of necessary steps, you have a chance to write an efficient code. If you then add telling names, good formatting and comments only where it's absolutely necessary, it will probably be good.