Oregon State University|blogs.oregonstate.edu
Blog Owner
Blogger Name

Embracing Clean Code Practices: A Personal Reflection

  January 17th, 2025

Greetings Everyone,

As I continue to grow as a programmer, I’ve been reflecting on how I approach writing and maintaining code. Recently, I came across some insightful articles about clean code and code smells that challenged me to reevaluate my coding habits. Today, I want to share one practice I aim to incorporate more often and one I want to avoid, based on the lessons from these resources.


Cleaning Things Up: Writing Small, Focused Functions (Clean Code)

One thing that stood out to me from DZone’s article on clean code principles and freeCodeCamp’s beginner’s guide is the importance of writing small, focused functions. Functions that do one thing and do it well are not only easier to read, but also simpler to test and debug.

Here’s an example of a refactor I’d like to adopt more often:

Before (A Large, Complex Function):

After (Smaller, Focused Functions):

This approach aligns with the Single Responsibility Principle and makes the code much easier to maintain.


Does Your Code Stink? Stop Ignoring Code Smells

Another eye-opener was understanding the impact of code smells, as discussed in CodeSignal’s guide to identifying code smells and Hithesh Kumar’s insights. Ignoring code smells like long methods, duplicate code, or unnecessary comments can lead to technical debt and make the codebase harder to work with.

For example, consider this snippet:

Code with Smells (Duplicate Code):

This duplication violates the DRY (Don’t Repeat Yourself) principle. Instead, we can refactor:

Refactored Code:

By addressing code smells proactively, I can reduce future headaches and improve the overall quality of my work.


Why These Changes Matter

Writing small, focused functions fosters better collaboration, as teammates can quickly understand and modify the code. Addressing code smells ensures a healthier codebase, saving time and effort in the long run. These habits also reflect professionalism, a critical trait as I transition into the data science field, where clean and maintainable code is essential for reproducibility and scaling.

As I move forward, I’ll strive to implement these practices consistently, logging my progress in my “lessons learned” journal to ensure continuous improvement. If you have any tips or experiences with clean code or tackling code smells, I’d love to hear about them in the comments!

Cheers, Trent


Leave a Reply