Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Coursera

Writing Clean Code: 20 Code Smells & How to Avoid Them

Packt via Coursera

Overview

Coursera Plus Monthly Sale:
All Certificates & Courses 40% Off!
Grab it
In this course, you'll learn how to write cleaner, more maintainable code by identifying and addressing common code smells. You'll gain essential skills to enhance your software design abilities and create more efficient, scalable applications. By the end of the course, you'll be equipped to refactor and restructure problematic code into something more robust and readable. The journey begins by exploring the fundamental principles of software design, including the SOLID principles that lead to better modularity, testability, and flexibility. You'll understand the importance of structured and deep modules and how to avoid poor design practices that affect the longevity and scalability of software systems. The course then takes you through a series of common code smells, such as repeated switches, primitive obsession, and inefficient loops. You'll explore the causes of these issues and learn actionable techniques for refactoring them. Each section includes real-world examples and strategies that will allow you to immediately apply what you learn to your own codebases. Whether you're a developer looking to improve your coding practices or a team leader guiding others toward cleaner code, this course is a perfect fit. It’s ideal for developers who want to improve their software design skills, refactor legacy code, or implement best practices for maintainability. The course is designed for intermediate learners with basic programming knowledge.

Syllabus

  • Getting Started with the Course
    • In this module, we will introduce the course and outline its goals. You will learn how identifying and removing code smells can drastically improve the quality and maintainability of your codebase, laying the groundwork for better software design practices.
  • Software Design Fundamentals and SOLID Principles
    • In this module, we will dive into essential software design principles, focusing on the SOLID principles. You'll explore how these principles can be applied to create cleaner, more maintainable, and scalable software architecture. We’ll also cover techniques for structuring modules effectively to improve code quality.
  • Understanding and Navigating the Code Base
    • In this module, we will guide you on how to read and comprehend large codebases effectively. You’ll learn techniques for navigating code efficiently and identifying areas where code smells can be improved or refactored for better clarity and maintainability.
  • Repeated Switches
    • In this module, we will introduce the repeated switch code smell and discuss its negative impact on code readability and maintainability. You will learn how to recognize and refactor repeated switch statements for cleaner, more maintainable code.
  • Primitive Obsession
    • In this module, we will explore the primitive obsession code smell, focusing on how overusing primitive data types can complicate your code. You will learn how to replace these with domain-specific objects, improving abstraction and readability.
  • Loops
    • In this module, we will address inefficient loop structures, one of the most common code smells, and discuss their impact on both performance and readability. We’ll provide best practices for refactoring loops to make them more efficient and easier to understand.
  • Long Parameter List
    • In this module, we will cover the long parameter list code smell and how excessive parameters can complicate function signatures. You will learn strategies for simplifying these lists, such as using objects or default values to enhance readability and maintainability.
  • Knowledge Duplication
    • In this module, we will address the knowledge duplication code smell, explaining how repeated logic across the codebase can lead to inconsistencies and higher maintenance costs. You will learn techniques for refactoring and removing redundancies to improve the maintainability of your software.
  • Uninformative Comments
    • In this module, we will explore how uninformative comments can clutter your code and reduce clarity. You will learn how to write useful, concise comments and improve code readability by eliminating redundancy.
  • Shotgun Surgery
    • In this module, we will dive into the shotgun surgery code smell, where changes in one part of the system require modifications across multiple classes. You will learn strategies for refactoring to reduce the complexity of these scattered changes and improve maintainability.
  • Alternative Classes with Different Interfaces
    • In this module, we will discuss the problem of alternative classes with inconsistent interfaces, which can lead to confusion and usability issues. You’ll learn how to refactor classes to unify interfaces and improve code consistency.
  • Refused Bequest
    • In this module, we will explore the refused bequest code smell, which occurs when a subclass inherits functionality that it does not use. You’ll learn how to refactor your code to reduce misuse of inheritance and prefer composition to improve flexibility and maintainability.
  • Data Clumps
    • In this module, we will address the data clumps code smell, where related data is grouped together inappropriately. You will learn how to refactor these data structures to improve organization and encapsulation for better maintainability.
  • Middle-Man
    • In this module, we will examine the middle-man code smell, where unnecessary classes add complexity by simply delegating functionality. You’ll learn how to refactor your code by removing unnecessary abstraction layers to simplify your codebase.
  • Mutable Data
    • In this module, we will explore mutable data and how uncontrolled changes to state can lead to bugs and inconsistencies. You’ll learn how to refactor your code to manage data immutability effectively for better reliability and predictability.
  • Feature Envy
    • In this module, we will address the feature envy code smell, where methods tend to focus too heavily on data from another class. You’ll learn how to refactor your code to improve object boundaries and move behavior to the class where it logically belongs.
  • Divergent Change
    • In this module, we will explore the divergent change code smell, where a module requires frequent modifications for unrelated reasons. You’ll learn how to refactor your code to minimize the risk of frequent changes causing instability or regressions.
  • Large Interfaces
    • In this module, we will explore the issue of large interfaces and how they can make code difficult to maintain and extend. You’ll learn how to refactor large interfaces into smaller, more manageable ones that are easier to maintain and scale.
  • Multitaskers
    • In this module, we will address the multitasker code smell, where classes or methods take on too many responsibilities. You’ll learn how to apply the Single Responsibility Principle to refactor your code and improve its clarity and maintainability.
  • Unclear / Confusing Names
    • In this module, we will focus on the importance of clear, intuitive naming conventions. You will learn how unclear names can cause confusion and how to adopt best practices for naming variables, functions, and classes for improved readability.
  • Speculative Generality
    • In this module, we will discuss speculative generality and how over-engineering can make code unnecessarily complex. You’ll learn how to simplify code by removing premature abstractions and focusing on current requirements.
  • Unnecessary Exceptions
    • In this module, we will explore the unnecessary exceptions code smell, where the excessive use of exceptions makes error handling more complicated than needed. You will learn how to simplify exception handling for clearer and more robust code.
  • Shallow Modules
    • In this module, we will discuss the shallow module code smell, where modules contain little functionality relative to their complexity. You will learn how to refactor these modules to provide more meaningful functionality and enhance reusability.
  • Final Thoughts and Course Wrap-Up
    • In this final module, we will summarize the key takeaways from the course, reinforce the importance of clean code practices, and offer guidance on how to continue improving your software design skills for better maintainability and scalability.

Taught by

Packt - Course Instructors

Reviews

Start your review of Writing Clean Code: 20 Code Smells & How to Avoid Them

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.