Code Practices every developer can follow!
Published: 2021-10-06 19:46:06

# Coding the right way!

- You always feel difficulty understanding what doctors write, right? 
- Ever found a code on the internet but found it difficult to understand? 

<hr/>



1. ***Exception Handling*** : Code in a defensive manner. Always consider the worst case scenario. Think about input failures, event handling exceptions. This would help keep a track of possible bugs and catch the exceptions.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8fz8h2ijapwetttndq9f.jpg)

2. ***Enhance code readability*** : Writing highly optimized code and creating complex libraries is easy but consider junior developer trying to understand 300 lines of code. Which more of a challenge than learning. Code which is clean and modular reflects maturity, competency and professionalism of the developer. A code logically structured into modules and functions is always more readable, effecient and reusable. 
3. ***Minimize the memory footprint*** : Simple yet significant coding habits can change the performance of your final product. Memory management involves ways programmer / developer dynamically allocates memory to code when requested and frees it for reuse when not needed. Here are a few good blogs I came accross: 
    - [Secure Coding Best Practices for Memory Allocation in C and C++](https://www.codeproject.com/Articles/13853/Secure-Coding-Best-Practices-for-Memory-Allocation)
    - [Memory Management in Python](https://towardsdatascience.com/memory-management-in-python-6bea0c8aecc9)
    - [Best practice of memory management in programming](https://www.geekboots.com/story/best-practice-of-memory-management-in-programming)
4. ***Refactor your code*** : Restructuring your existing code without changing it's functionality. Aggregate groups of functions doing similar tasks into a single function, use of abstraction, deduplication of code and polymorphism.
    - [Refactoring Guru](https://refactoring.guru/refactoring)


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9u85gc41smlu2yl67eob.jpg)


5. ***Version Control*** : Tracking all changes and synchronization of codes, bug-resolve, managing changes to source codeover time. Basic, niche practice every developer should master. Git, GitHub, Gitlab, Mercurial are tools used for version control.
    - [What is version control?](https://www.atlassian.com/git/tutorials/what-is-version-control)

6. ***Code Testing*** : Isn't it nice when someone praises us after we dress up with a good outfit? Testing practices act just like that validation we need when code the functionalities of any software. It guides and shapes the development process of the software. Unit tests, code coverage and other testing techniques help maintain modular structure and good quality end-product.
7. ***KISS-DRY-YAGNI*** : 
    - “Keep It Simple, Silly” - keep your code as concise as possible 
    - "Don’t Repeat Yourself" - reducing repetition and redundancies 
    - "You aren't gonna need it" - Don't try to think far ahead in future and 
    add complex bits of code features. You don't need it, you ain't gonna need it!


<hr/>