Podbean logo
  • Discover
  • Podcast Features
    • Podcast Hosting

      Start your podcast with all the features you need.

    • Podbean AI Podbean AI

      AI-Enhanced Audio Quality and Content Generation.

    • Blog to Podcast

      Repurpose your blog into an engaging podcast.

    • Video to Podcast

      Convert YouTube playlists to podcasts, videos to audios.

  • Monetization
    • Ads Marketplace

      Join Ads Marketplace to earn through podcast sponsorships.

    • PodAds

      Manage your ads with dynamic ad insertion capability.

    • Apple Podcasts Subscriptions Integration

      Monetize with Apple Podcasts Subscriptions via Podbean.

    • Live Streaming

      Earn rewards and recurring income from Fan Club membership.

  • Podbean App
    • Podcast Studio

      Easy-to-use audio recorder app.

    • Podcast App

      The best podcast player & podcast app.

  • Help and Support
    • Help Center

      Get the answers and support you need.

    • Podbean Academy

      Resources and guides to launch, grow, and monetize podcast.

    • Podbean Blog

      Stay updated with the latest podcasting tips and trends.

    • What’s New

      Check out our newest and recently released features!

    • Podcasting Smarter

      Podcast interviews, best practices, and helpful tips.

  • Popular Topics
    • How to Start a Podcast

      The step-by-step guide to start your own podcast.

    • How to Start a Live Podcast

      Create the best live podcast and engage your audience.

    • How to Monetize a Podcast

      Tips on making the decision to monetize your podcast.

    • How to Promote Your Podcast

      The best ways to get more eyes and ears on your podcast.

    • Podcast Advertising 101

      Everything you need to know about podcast advertising.

    • Mobile Podcast Recording Guide

      The ultimate guide to recording a podcast on your phone.

    • How to Use Group Recording

      Steps to set up and use group recording in the Podbean app.

  • All Arts Business Comedy Education
  • Fiction Government Health & Fitness History Kids & Family
  • Leisure Music News Religion & Spirituality Science
  • Society & Culture Sports Technology True Crime TV & Film
  • Live
  • How to Start a Podcast
  • How to Start a Live Podcast
  • How to Monetize a podcast
  • How to Promote Your Podcast
  • How to Use Group Recording
  • Log in
  • Start your podcast for free
  • Podcasting
    • Podcast Features
      • Podcast Hosting

        Start your podcast with all the features you need.

      • Podbean AI Podbean AI

        AI-Enhanced Audio Quality and Content Generation.

      • Blog to Podcast

        Repurpose your blog into an engaging podcast.

      • Video to Podcast

        Convert YouTube playlists to podcasts, videos to audios.

    • Monetization
      • Ads Marketplace

        Join Ads Marketplace to earn through podcast sponsorships.

      • PodAds

        Manage your ads with dynamic ad insertion capability.

      • Apple Podcasts Subscriptions Integration

        Monetize with Apple Podcasts Subscriptions via Podbean.

      • Live Streaming

        Earn rewards and recurring income from Fan Club membership.

    • Podbean App
      • Podcast Studio

        Easy-to-use audio recorder app.

      • Podcast App

        The best podcast player & podcast app.

  • Advertisers
  • Enterprise
  • Pricing
  • Resources
    • Help and Support
      • Help Center

        Get the answers and support you need.

      • Podbean Academy

        Resources and guides to launch, grow, and monetize podcast.

      • Podbean Blog

        Stay updated with the latest podcasting tips and trends.

      • What’s New

        Check out our newest and recently released features!

      • Podcasting Smarter

        Podcast interviews, best practices, and helpful tips.

    • Popular Topics
      • How to Start a Podcast

        The step-by-step guide to start your own podcast.

      • How to Start a Live Podcast

        Create the best live podcast and engage your audience.

      • How to Monetize a Podcast

        Tips on making the decision to monetize your podcast.

      • How to Promote Your Podcast

        The best ways to get more eyes and ears on your podcast.

      • Podcast Advertising 101

        Everything you need to know about podcast advertising.

      • Mobile Podcast Recording Guide

        The ultimate guide to recording a podcast on your phone.

      • How to Use Group Recording

        Steps to set up and use group recording in the Podbean app.

  • Discover
  • Log in
    Sign up free
Coding Blocks | Software and Web Programming / Security / Best Practices / Microsoft .NET

Coding Blocks | Software and Web Programming / Security / Best Practices / Microsoft .NET

Technology:Software How-To

Episode 55 – Clean Code – How to Write Classes the Right Way

Episode 55 – Clean Code – How to Write Classes the Right Way

2017-02-05
Download Right click and do "save link as"

This week Allen is troubled by circles, Michael talks like a game show host, and Joe announces it’s twins as we continue our deep dive into the classic Clean Code book by Robert C. Martin.

Join in on the conversation by becoming a member of our Slack community by signing up at http://www.codingblocks.net/slack.

For the full show notes, visit: http://www.codingblocks.net/episode55.

Survey

This week’s survey: What type of development floats your boat?

#yop-poll-container-32_yp593f59cadc12f { width: 1000; background:#fff; padding:10px; color:#555; overflow:hidden; font-size:12px; } #yop-poll-container-32_yp593f59cadc12f input[type='text'] { margin:0px 0px 5px 0px; padding:2%; width:96%; text-indent:2%; font-size:12px; } .yop-poll-name-32_yp593f59cadc12f { font-weight:bold; background:#327BD6; color:#fff; padding:5px; text-align:center; font-size:12px; } #yop-poll-questions-container-32_yp593f59cadc12f { font-size:14px; margin:5px 0px; } .yop-poll-question-container-32_yp593f59cadc12f { padding: 2px; } .yop-poll-question-32_yp593f59cadc12f { background:#327BD6; color:#fff; margin-bottom: 21px; margin-top: -10px; font-style: italic; text-align: center; width: 100%; padding:5px; } .yop-poll-answers-32_yp593f59cadc12f { } .yop-poll-answers-32_yp593f59cadc12f ul { list-style: none outside none; margin: 0; padding: 0; } .yop-poll-li-answer-32_yp593f59cadc12f { font-style:normal; margin:0px 0px 10px 0px; padding:0px; font-size:12px; margin-bottom:20px; } .yop-poll-li-answer-32_yp593f59cadc12f input { margin:0px; float:none; } .yop-poll-li-answer-32_yp593f59cadc12f label { margin:0px; font-style:normal; font-weight:normal; font-size:12px; float:none; } .yop-poll-results-32_yp593f59cadc12f { font-size: 12px; font-style: italic; font-weight: normal; margin-left: 15px; } .yop-poll-customs-32_yp593f59cadc12f { } .yop-poll-customs-32_yp593f59cadc12f ul { list-style: none outside none; margin: 0; padding: 0; } .yop-poll-li-custom-32_yp593f59cadc12f { padding:0px; margin:0px; font-size:14px; } /* Start CAPTCHA div style*/ #yop-poll-captcha-input-div-32_yp593f59cadc12f { margin-top:5px; } #yop-poll-captcha-helpers-div-32_yp593f59cadc12f { width:30px; float:left; margin-left:5px; height:0px; } #yop-poll-captcha-helpers-div-32_yp593f59cadc12f img { margin-bottom:2px; } #yop-poll-captcha-image-div-32_yp593f59cadc12f { margin-bottom:5px; } #yop_poll_captcha_image_32_yp593f59cadc12f { float:left; } /* End CAPTCHA div style*/ .yop-poll-clear-32_yp593f59cadc12f { clear:both; } #yop-poll-vote-32_yp593f59cadc12f { } /* Start Result bar*/ .yop-poll-results-bar-32_yp593f59cadc12f { background:#f5f5f5; height:10px; } .yop-poll-results-bar-32_yp593f59cadc12f div { background:#555; height:10px; } /* End Result bar*/ /* Start Vote Button*/ #yop-poll-vote-32_yp593f59cadc12f div#yop-poll-vote-32_yp593f59cadc12f button { float:left; } #yop-poll-vote-32_yp593f59cadc12f div#yop-poll-results-32_yp593f59cadc12f { float: right; margin-bottom: 20px; margin-top: -20px; width: auto; } #yop-poll-vote-32_yp593f59cadc12f div#yop-poll-results-32_yp593f59cadc12f a { color:#fff; text-decoration:underline; font-size:12px; } #yop-poll-vote-32_yp593f59cadc12f div#yop-poll-back-32_yp593f59cadc12f a { color:#555; text-decoration:underline; font-size:12px; } #yop-poll-vote-32_yp593f59cadc12f div#yop-poll-archive-32_yp593f59cadc12f a { color:#555; text-decoration:underline; font-size:12px; } #yop-poll-vote-32_yp593f59cadc12f div { float:left; width:100%; } /* End Vote Button*/ /* Start Messages*/ #yop-poll-container-error-32_yp593f59cadc12f { font-size:12px; font-style:italic; color:red; text-transform:lowercase; margin-bottom:20px; text-align:center; } #yop-poll-container-success-32_yp593f59cadc12f { font-size:12px; font-style:italic; color:green; margin-bottom:20px; text-align:center; } /* End Messages*/#yop-poll-container-32_yp593f59cadc12f img { max-width: 1000; } .yop-poll-forms-display{}
What type of overall development floats your boat?
  • Gaming - I want to make something people play with..
  • Business apps - I want to create apps that solve real business problems...
  • Machine learning - data science gets my brain moving...
  • Dev Ops - I want to make software delivery smooth as silk...
  • Big data - I want to pour through all the bits...
  • Hacking - reverse engineering is how I butter my bread...
  • Frameworks - I want to build the next great tool for developers...
vote
News
  • Big thanks to all of those that took the time to leave us a review!
    • iTunes Reviews: Brain D., Bonny Jamburloony, Jazman9000, Jon Moscrop, Aaron’s iPhone
    • Stitcher Reviews: jd2017, DrArtz, mrbailie, Weslextech, carndog19, ManWithCamera
  • Joe releases another video in the Mini Code Adventures series. Watch at YouTube.
  • Paul Seal gives Joe a lesson on how to setup Umbraco. Watch at YouTube.
Stickers

Want some? We want you to have some. Send us a self-addressed stamped envelope. More information available at http://www.codingblocks.net/swag.

Classes Order Matters
  • Class should begin with a list of variables
    • public static constant (or read only)
    • private static
    • private instance
    • public functions
    • private utility methods after the public function that calls it
  • “Seldom a good reason to have a public variable”
  • If a variable needs to be protected in order to be accessed by a test, so be it
Classes should be small
  • Rather than count lines, count responsibilities
  • Just because it’s small doesn’t mean it’s good – could still have too many responsibilities
  • If you cannot derive a good class name, it’s probably too large / too broad a scope
  • “Weasel” words like Processor, Manager, Super, usually indicate too many responsibilities
  • We should be able to describe a class in 25 words without using the words “if”, “and”, “or”, or “but”.
Classes should adhere to SRP
  • SRP, Single Responsibility Principle (Wikipedia): The S in SOLID
    • A class or module should have one and only one reason to change
  • Identifying responsibilities can help us refactor into better, more concise classes
  • SRP is easy to follow but usually the most abused concept
  • Most people are focused on getting something done, so organizing the code goes to the wayside
  • There is the concern of ballooning the number of files / classes that must be traversed to understand an application
  • Would you rather organize drawers by just throwing everything into two drawers, or would you like well separated filing cabinets?
  • Many small classes is better
  • Large, multipurpose classes force us to scroll through code that we don’t need to know about right now.
Cohesion
  • Classes should have a small number of instance variables
  • Methods should affect as many variables in the class as possible to achieve “high cohesion”
  • When variables aren’t used by many methods, those are probably begging for a new class
  • When classes lose cohesion, it’s time to split them up.
Organizing Change
  • Breaking classes into smaller, simpler functions reduces the event that one function will break another
  • Subclassing properly can help reduce number of breaks in existing code
  • “Private method behavior that applies only to a small subset of a class can be a useful heuristic for spotting potential areas for improvement.”
  • OCP, Open Close Principle (Wikipedia): The O in SOLID
    • Classes should be open for extension but closed for modifications
  • Ideally, we add new functionality by extending the system, not modifying the existing code.
Isolating from Change
  • A client class depending on concrete details is at risk when those details change
  • Using a good base / abstract class can make testing easier as you can create repeatable tests
  • Making code more testable makes it more reusable in effect
  • DIP, Dependency Inversion Principle (Wikipedia): The D in SOLID
    • Classes should depend on abstractions, not concrete details
Resources We Like

Of course we’re going to mention Clean Code.

Seriously, read this book!

Tip of the Week
  • Trade in your old tech books (or other stuff). Check out this link at Amazon for the details.
  • GUID Performance in SQL Server as a Primary Key. See this popular answer on StackOverflow.
  • Use git archive to Git the files, not the repository. See the git-archive documentation and this popular answer on StackOverflow.
Spread the Word!

Enjoy the show? Want to help us out? It’s easier than you think. Simply tell everyone you know. And have them do the same.

OK, but seriously, we can’t expect you to tell everyone you know, but you could help us by sharing the show with some of the people you know. See? That’s not so bad now is it?

And if you haven’t already, we’d love for you to leave a review. Head to http://www.codingblocks.net/review to share your opinion with the world. Make your voice known.

Peace, love, and code.

view more

More Episodes

Episode 61 – Software Architecture – Aggregate Roots, Factories, and Repositories
2017-06-13
Episode 60 – Software Architecture – The Domain in Domain Driven Design
2017-05-29
Episode 59 – How to Jumpstart Your Next App
2017-05-11
Episode 58 – Why Domain Driven Design
2017-04-24
Episode 57 – How We Badly Built Stuff
2017-03-20
Episode 56 – Clean Code – How to Build Maintainable Systems
2017-03-06
Episode 54 – Clean Code – How to Write Amazing Unit Tests
2017-01-23
Episode 53 – Clean Code – Integrating with Third Party Libraries the Right Way
2017-01-08
Episode 52 – Clean Code – Error Handling
2016-12-28
Episode 51 – Clean Code – Objects vs Data Structures
2016-12-13
Episode 50 – Clean Code – Formatting Matters
2016-11-29
Episode 49 – Clean Code – Comments Are Lies
2016-11-07
Episode 48 – Clean Code – How to Write Amazing Functions
2016-10-17
Episode 47 – Clean Code – Writing Meaningful Names
2016-09-28
Episode 46 – Caching in the Application Framework
2016-08-27
Episode 45 – Caching Overview and Hardware
2016-08-12
Episode 44 – Stack Overflow Salaries and Landing the Job
2016-08-02
Episode 43 – Nulls, Procs, and Impostor Syndrome
2016-07-05
Episode 42 – Command, Repository and Mediator Design Patterns
2016-06-03
  • ←
  • 1
  • 2
  • 3
  • →
01234578910111213141516171819

Get this podcast on your
phone, FREE

Download Podbean app on App Store Download Podbean app on Google Play

Create your
podcast in
minutes

  • Full-featured podcast site
  • Unlimited storage and bandwidth
  • Comprehensive podcast stats
  • Distribute to Apple Podcasts, Spotify, and more
  • Make money with your podcast
Get started

It is Free

  • Podcast Services

    • Podcast Features
    • Pricing
    • Enterprise Solution
    • Private Podcast
    • The Podcast App
    • Live Stream
    • Audio Recorder
    • Remote Recording
    • Podbean AI
  •  
    • Create a Podcast
    • Video Podcast
    • Start Podcasting
    • Start Radio Talk Show
    • Education Podcast
    • Church Podcast
    • Nonprofit Podcast
    • Get Sermons Online
    • Free Audiobooks
  • MONETIZATION & MORE

    • Podcast Advertising
    • Dynamic Ads Insertion
    • Apple Podcasts Subscriptions
    • Switch to Podbean
    • YouTube to Podcast
    • Blog to Podcast
    • Submit Your Podcast
    • Podbean Plugins
    • Developers
  • KNOWLEDGE BASE

    • How to Start a Podcast
    • How to Start a Live Podcast
    • How to Monetize a Podcast
    • How to Promote Your Podcast
    • Mobile Podcast Recording Guide
    • How to Use Group Recording
    • Podcast Advertising 101
  • Support

    • Support Center
    • What’s New
    • Free Webinars
    • Podcast Events
    • Podbean Academy
    • Podbean Amplified Podcast
    • Badges
    • Resources
  • Podbean

    • About Us
    • Podbean Blog
    • Careers
    • Press and Media
    • Green Initiative
    • Affiliate Program
    • Contact Us
  • Privacy Policy
  • Cookie Policy
  • Terms of Use
  • Consent Preferences
  • Copyright © 2015-2025 Podbean.com