answersLogoWhite

0


Best Answer

One of the easiest ways to improve your code quality is to keep your comments to a minimum. Use a verbose comment to introduce your code, summarising its purpose and features, but try and keep the code itself as comment-free as possible. This way, the reader can follow the flow of the code without constant interruption from the programmer. Comments within your code should only be used to clarify anything that is unclear, without simply restating what the code does. That is, what the code does is explained by the code itself, but it isn't always clear why the code does what it does.

If a verbose comment is required in order to explain the purpose of a particular line of code, try rewriting that line in such a way that it becomes clearer from the code itself. Make good use of whitespace to make it clearer what's going on. Good code should also be largely self-documenting, so if the logic is obfuscated by a complex series of statements, place those statements in separate functions with meaningful names so that the code documents itself more easily. Using functions in this way costs nothing since simple functions will be inline expanded by the compiler.

Avoid code duplication at all costs. Rewriting the same code over and over, or copy/pasting code, leads to increased maintenance and error-prone code whenever that code needs to be altered. Even if the code has slight differences there are usually ways to generalise the code either as a single function call, or a series of function calls to cater for differences. This greatly reduces maintenance costs because any changes to a particular call need only be made in one function, rather than every location that uses the code. With C++ this concept extends to objects as well. Make good use of inheritance and abstraction to provide more specialised versions of your generic code.

These are probably the simplest methods to improve the quality of your code. Ultimately, the quality of your code is determined by your consistency and your style. That is, stick to common conventions as much as possible. Ensure all your objects obey the one-resource-per-object rule. Objects that mutate multiple resources are a design flaw which will only lead to problems further down the line.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are some easy ways to improve the quality of your C plus plus code?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How can TV picture improve using the sky plus box?

The sky plus box provides digital signal, so the image quality is good. Combining the sky plus box with a HD box though, can provide enhanced quality image, if the television device can display in HD. A HDMI cable would be also required.


Which mobile company code is plus plus 372?

Its code of estonia


Plus 621 is for which country code?

plus 621 what country code


What is Easy Grammar Plus?

Easy Grammar Plus is a easy grammar homeschool curriculum by Wanda C. Phillips, Ed.D.


What is reading plus site code?

A "site code" for reading plus is a code usually given to you by your teacher. Everyone in your school uses this code. You will have to use this the first time you sign in on reading plus.


Types of training for dogs?

High Quality Dog Training Course Featuring 21 Games To Improve A Dog's Intelligence And Behavior, Plus Easy Instructions For Training Obedience Commands! Created By A Well Known Professional Dog Trainer! cutt.ly/ijaKOma


What is plus 324 country code?

Code for Dubai


Is C plus plus preprocessor software?

Sometimes, it is. Some implementations compile C++ code into C code, and then compile the C code.


Why use the plus when searching the internet?

To improve the search results.


How will you fix your codes in c plus plus when you don't have the program?

Editing code is easy, they're simply plain text files you can edit with any text editor. However, you lose the syntax engine and all the external headers and libraries required by the code, not to mention the compiler and the linker that are required to actually build the code. Migrating code to another compiler is the only option if you don't have access to the original compiler.


What is the need for indentation in while writing a c plus plus program?

Indenting is a good habit to inculcate while writing any type of code Although indentation is not mandatory and will never affect the working of your programme in C++ it makes the code more easy to read and debug especially for larger programmes. Most IDE's eg eclipse automatically indent the code as you type.


C plus plus code for payroll processing?

yihuy