Partner with CodeWalnut to drive your digital growth!
Tell us about yourself and we will show you how technology can help drive business growth.
Thank you for your interest in CodeWalnut.Our digital expert will reach you within 24-48 hours.
Oops! Something went wrong while submitting the form.
Javascript

Expert programmer vs beginner- Learnings from 50+ PRs

April 12, 2024
9 min
Expert vs Begineer Programmer
Linkedin iconX logoFacebook icon

Diving into the world of coding, especially when you're just starting out, can feel like a maze.

Ever wondered why some developers breeze through PR (Pull Request) approvals while others get stuck in a loop of feedback and fixes?

This blog is your friendly guide through the ups and downs of coding practices, with real-life lessons from over 50 PR reviews.

We're keeping it simple and straight to the point, sharing insights on common mistakes and how to dodge them, making your code cleaner and your PR process smoother.

Whether you're a beginner aiming to get better or a tech lead tired of reviewing messy code, there's something in here for you. Let's make coding a bit less daunting and a lot more fun.

Master PR Approval: Learn from Common Mistakes

Have you ever found your PR drowning in a sea of comments from senior developers? Do multiple rejections leave you feeling frustrated and stuck? If you answered yes, you're not alone. Many developers face similar challenges, and trust me, "I feel you."

The Path to Faster PR Approval

So, how can we expedite the PR approval process? If you're hoping for a magic spell, I'm afraid the software industry doesn't work that way. However, there's a simple solution: practices.

Yes, that's right. Learning from our mistakes and understanding where we go wrong is key to improvement over time.

Learning from Others' Mistakes

There's a famous quote: "If you're smart, you'll learn from your mistakes. But if you're smarter, you'll learn from others' mistakes." We can accelerate our learning process by understanding and avoiding common pitfalls, which is what this post aims to offer.

Disclaimer: While some points may seem basic, they are essential for beginners.

Let's Dive In

1. Poor naming conventions or bad naming practices :

In the intricate world of coding, where each line forms the backbone of functionality, the significance of well-chosen names cannot be overstated. A variable or function name is not merely a syntax requirement; it's a communication tool that transcends characters on the screen.

How to Overcome:

Be Descriptive: Choose names that clearly convey the purpose or functionality. A name should answer the question of "What does this do?" at a glance.

For instance:

There is a function that adds tax to the amount :

What a beginner will write :

 Javascript

function add(a){
    return a * 1.18 ;// 18% percent tax
    }

Better way: Experienced developers use descriptive naming to inform other developers about a function's role, its mechanics, and the expected results.

 Javascript

function calculateTotalWithTax(amount, taxRate) {
  const taxRateMultipler = taxRate / 100;
  return amount * taxRateMultipler;
}

2. Consistency is Key: Maintaining consistent naming conventions across your project is crucial for readability and cohesion. It ensures that the codebase is perceived as a coherent whole. Suppose your project adopts certain naming standards, such as using camelCase for identifying functions and variables, and PascalCase for class names. In that case, applying these conventions uniformly throughout your code is imperative.

For instance:

 Javascript

// Demonstrating camelCase for variables and functions
// Incorrect variable naming - lacks camelCase
const totalcost = 100; // Incorrect due to lack of camelCase
// Corrected variable naming - adheres to camelCase
const totalCost = 100; // Correct usage of camelCase

// Calculating the total amount including tax
const totalAmountWithTax = calculateTotalWithTax(totalCost);

// Demonstrating PascalCase for class names
// Incorrect class naming - does not use PascalCase
class shippingdetails {
// Class methods would be defined here
}
// Correct class naming - adheres to PascalCase
class ShippingDetails {
// Class methods are defined here
}

This example underscores the significance of adhering to specific naming conventions, such as camelCase for variables and function names and PascalCase for class names, to enhance the code's readability and maintain a consistent style throughout the project.

3. Prioritize Descriptive Clarity Over Brevity: Ambiguous names can significantly hinder comprehension and maintenance of code. It is vital to prioritize clarity and specificity in naming conventions, even at the expense of brevity. This practice not only facilitates easier reading and understanding but also ensures long-term maintainability and ease of use.

 Javascript

/**
* Computes the net price after applying a discount.
* This function takes the original price of an item and a discount rate,
* then calculates the reduced total price after subtracting the discount.
* @param {number} priceBeforeDiscount - The item's initial price before any discounts.
* @param {number} discountRate - The discount rate, represented as a percentage.
* @return {number} - The price of the item after applying the discount rate.
*/
function computeDiscountedPrice(priceBeforeDiscount, discountRate) {
  const reduction = discountRate / 100;
  const discountedAmount = priceBeforeDiscount * reduction;
  const priceAfterDiscount = priceBeforeDiscount - discountedAmount;
  return priceAfterDiscount;
  }


In this example:

  • The function ‘computeDiscountedPrice’ conveys its purpose through a descriptive name that adheres to camelCase conventions.
  • Parameters ‘priceBeforeDiscount’ and ‘discountRate’ are explicitly named to reflect their roles in the calculation, eliminating any guesswork about their purposes.
  • An introductory comment elaborates on the function's operation, providing context and expectations for its output.
  • The choice of variable names such as ‘reduction’, ‘discountedAmount’, and ‘priceAfterDiscount’ further clarifies the steps involved in the computation.

Implementing these strategies ensures that the code remains accessible and understandable, thereby aiding in its application and upkeep.

Bonus tip :

If you are using Visual Studio, we have a plugin that can help you find the spelling mistakes.

Plugin Name: Code spell checker

Art of Code Cleanup: Enhance Readability and Performance

Now, I want to delve into a question that often resonates in the corridors of senior developers: Why don't we clean our code once we consider it done?

Code, undoubtedly, is a product of our thinking process. With each iteration, the goal is to enhance and optimize our code. However, in this pursuit of improvement, we often leave behind remnants of unused code. Over time, these neglected code snippets accumulate, transforming into a formidable mass within our repositories.

The Power of Code Cleanup

The practice of diligently cleaning up code before committing yields a compounding benefit on a codebase's maintainability. A systematic approach to cleaning up code leads to several pivotal improvements over time:

  • Streamlined Codebase: By regularly removing unnecessary or redundant code, the codebase becomes leaner, significantly improving readability and simplifying maintenance. This streamlined codebase facilitates quicker navigation and modification by developers.
  • Enhanced Development Efficiency: The elimination of superfluous code can accelerate the development process, enabling teams to implement new features and address bugs more rapidly. This efficiency promotes agility and responsiveness in project timelines.
  • Reduced Technical Debt: Cleaning up code contributes to the reduction of technical debt, preventing the accumulation of outdated or ineffective code that can hinder future development efforts. A lower technical debt leads to a more stable and sustainable codebase.
  • Improved Collaboration: A tidy codebase makes it easier for development teams to collaborate. Clear, well-organized code supports a shared understanding among team members, enhancing communication and facilitating smoother peer reviews and integration of work.
  • Optimized Application Performance: Removing unused or inefficient code segments can significantly boost performance. This optimization reduces the application's resource consumption and improves load times, leading to a better user experience.

Adopting a disciplined approach to code cleanup before committing changes is not just about keeping the codebase orderly; it's a strategic practice that enhances the overall quality, maintainability, and scalability of the software, ensuring its longevity and adaptability in the face of evolving project requirements.

Best Practices for Code Cleanup

Before raising that Pull Request (PR), consider going through your changed files with the following points in mind:

  • Consistent Formatting: Align your code with established coding style guidelines, ensuring a uniform and professional appearance.
  • Remove Debugging Statements: Eliminate leftover debugging statements like console.log that served their purpose during development.
  • Refactor Redundant Code: Identify and refactor sections of code that may be redundant or duplicated, promoting cleaner and more efficient solutions.
  • Update Deprecated Code: Stay current by replacing deprecated methods, libraries, or syntax with the latest and recommended alternatives.
  • Optimize Performance: Identify and address bottlenecks or inefficiencies, optimizing your code for superior performance.
  • Documentation Cleanup: Review and update code comments and documentation to accurately reflect recent changes, ensuring clarity for future developers.
  • Check for Code Smells: Be vigilant for code smells or anti-patterns and refactor them to elevate the overall quality of your code.

Conclusion

As developers, our commitment to clean, efficient code is not just a responsibility; it's a practice that defines the success of our projects. By incorporating regular code cleanup into our development workflow, we contribute to a healthier, more sustainable codebase.

Embrace the art of code cleanup. Your fellow developers, your future self, and your codebase will thank you.

Author

Sachin Gupta
Sachin Gupta

Related posts