Skip to content

Instantly share code, notes, and snippets.

@maurolepore
Last active November 28, 2017 17:45
Show Gist options
  • Save maurolepore/21467dc9c5c0e50b3b0fe682e284025e to your computer and use it in GitHub Desktop.
Save maurolepore/21467dc9c5c0e50b3b0fe682e284025e to your computer and use it in GitHub Desktop.
code_good_practice
  • Don't hard code settings (e.g. figure colours), read them from a file via read_settings().

The code is more readable and flexible than it would be if a value were hard-coded. You don't need to change the program to change titleBar.color ; you simply change the contents of the source that's read by"

-― from "Code Complete (Developer Best Practices)" by Steve McConnell, http://a.co/b75gLyw

  • Prefer long informative names over short uninformative ones (8-20 characters is ok)

In modern languages like C++, Java, and Visual Basic, you can create names of virtually any length; you have almost no reason to shorten meaningful names.

--from "Code Complete (Developer Best Practices)" by Steve McConnell, http://a.co/4f8df29

"Access routines allow you to redecorate the interior of your house and leave the exterior unchanged so that your friends still recognize it."

--from "Code Complete (Developer Best Practices)" by Steve McConnell http://a.co/2otQ0WW

"Anything you can do with global data, you can do better with access routines. The use of access routines is a core technique for implementing abstract data types and achieving information hiding."

--"Code Complete (Developer Best Practices)" by Steve McConnell http://a.co/99fMfC9

"Emulation of named constants. Although C++, Java, Visual Basic, and most modern languages support named constants, some languages such as Python, Perl, Awk, and UNIX shell script still don't. You can use global variables as substitutes for named constants when your language doesn't support them."

--"Code Complete (Developer Best Practices)" by Steve McConnell http://a.co/cduRle6

"The only way you can intellectually manage a large program is to break it into pieces so that you only have to think about one part at a time. Modularization is the most powerful tool at your disposal for breaking a program into pieces."

--"Code Complete (Developer Best Practices)" by Steve McConnell http://a.co/btQnbMX

Refactoring

Chesterton's fence is the principle that reforms should not be made until the reasoning behind the existing state of affairs is understood.

https://en.wikipedia.org/wiki/Wikipedia:Chesterton%27s_fence

The single biggest way to improve both the quality of your code and your productivity isto reuse good code.

― from "Code Complete (Developer Best Practices)" (https://goo.gl/83hsHb)

Testing

If you are writing several routines, you should test them one at a time.

--Code Complete https://i.imgur.com/npNV0iO.png

...it's cheaper to fix defects early.

--Code Complete https://i.imgur.com/Ave7fvq.png

...code reading detected about 3.3 defects per hour of effort.

--Code Complete https://i.imgur.com/pFXB8f8.png

90% of the defects were found in preparation for the review meeting, and only 10 percent were found during the review itself.

-- Code Complete https://i.imgur.com/7GwECZc.png

As the size of the project increases, developer testing consumes a smaller percentage of the total development time.

--Code Complete https://i.imgur.com/mtqG95s.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment