Skip to content

Instantly share code, notes, and snippets.

@cristiana214
Last active May 22, 2024 07:50
Show Gist options
  • Save cristiana214/341abe53f8f1a32ff9d31ad6281de81a to your computer and use it in GitHub Desktop.
Save cristiana214/341abe53f8f1a32ff9d31ad6281de81a to your computer and use it in GitHub Desktop.
Coding Best Practices

The principles of good programming are connected to good design and engineering principles.

These programming principles have improved my skills as a programmer, and I believe they can do the same for any developer. They help increase efficiency, make code easier to maintain, and reduce the number of bugs.

Write code for maintainers please

Write code for the maintainer When you're writing code, always keep in mind that it will need to be maintained in the future, either the future you or someone else. You might not remember everything about the code in the future, just like someone else who didn't write it. So, always write your code in a way that makes it easy for others to understand and maintain.

DRY - (Do not repeat Yourself) https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

The most important rule in coding is not to repeat the same thing. There are many tools in programming, like loops, functions, and classes, that help you avoid doing this. If you find yourself writing the same code or concept again, it's a good idea to make a new abstraction. This way, your code will be better and more efficient.

KISS (Keep it simple, stupid!) http://en.wikipedia.org/wiki/KISS_principle

You should always aim for simplicity in your code and try to avoid making it too complicated. The benefits of keeping things simple are many. For one, it takes less time to write simple code. Also, simple code tends to have fewer errors. And, when it comes to making changes or updates, simple code is much easier to work with. So, always strive for simplicity in your coding.

YAGNI (You aren’t going to need it) http://en.wikipedia.org/wiki/YAGNI

It's important to avoid adding features that you don't really need, a concept known as YAGNI (You aren't going to need it). Instead, you should focus on adding new features only when they are truly necessary.

Minimize Coupling http://en.wikipedia.org/wiki/Coupling_(computer_programming)

This make sure that different parts of your code (like code blocks, functions, classes, etc.) don't rely too much on each other. You can do this by using shared variables as little as possible. When your code has low coupling, it's usually a sign that your system is well-organized and your design is good. It also makes your code easier to read and maintain.

Open/Closed Principle http://en.wikipedia.org/wiki/Open_Closed_Principle

The Open/Closed Principle in programming means that your code should be open to being extended (meaning you can add new features or functionality), but closed to modification (meaning you shouldn't need to change the existing code to add these new features). In simple terms, you should be able to add new things to your code without having to change what's already there.

Single Responsibility Principle http://en.wikipedia.org/wiki/Single_responsibility_principle

The Single Responsibility Principle in programming simply means that each part of your code (like a class or function) should have one job only and it should do it well. This makes your code easier to understand, test, and maintain.

Note: this lists will be constantly updated

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