$30 off During Our Annual Pro Sale. View Details »

'Code Smells - Developing Design Sense for your Code' by Llewellyn Falco

'Code Smells - Developing Design Sense for your Code' by Llewellyn Falco

'In order to make delicious food,you must eat delicious food…. you need to develop a palate capable of discerning good and bad. Without good taste, you can't make good food.' - Jiro Ono (World’s Best Sushi Chef). The same is true for great code. If we want to make great code we need a refined palate for what great code looks like. We need to look at code and develop a sense for it’s properties and smells. Sadly this is rarely ever done. Programmers are expected to just 'know' what is good and what is bad with ever getting a chance to develop and curate an aesthetic sense. Worse, code is rarely looked at unless it is causing us problems so we are expected to be gourmets while spending our time eating at McDonalds. Come work on your sense of code. We will look at many snippets to compare and contrast different aspects of what good code is. Learning Outcomes: How to identify and correct, Clutter, Long lines, Long Methods, Bad Names, Duplication, Inconsistency.

Related slides:
* https://speakerdeck.com/agilelatvia/code-smells-developing-design-sense-for-your-code-sparrows-song-and-house-by-llewellyn-falco
* https://speakerdeck.com/agilelatvia/code-smells-developing-design-sense-for-your-code-bad-names-by-llewellyn-falco
* https://speakerdeck.com/agilelatvia/code-smells-developing-design-sense-for-your-code-clutter-by-llewellyn-falco
* https://speakerdeck.com/agilelatvia/code-smells-developing-design-sense-for-your-code-duplication-by-llewellyn-falco
* https://speakerdeck.com/agilelatvia/code-smells-developing-design-sense-for-your-code-inconsistency-by-llewellyn-falco
* https://speakerdeck.com/agilelatvia/code-smells-developing-design-sense-for-your-code-longlines-by-llewellyn-falco

Link: http://agiledayriga.lv/index.html#session13

Agile Latvia

July 07, 2017
Tweet

More Decks by Agile Latvia

Other Decks in Technology

Transcript

  1. Code Smells
    Developing Design Sense for your Code
    @LlewellynFalco

    View Slide

  2. Play along at
    Slides:
    llewellynfalco.blogspot.com/p/sparrow-decks.html
    Phone game:
    bit.ly/sparrowdecks

    View Slide

  3. *http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0141357
    Dr. Pigeon diagnosis cancer
    15 days of training
    85% successful
    University of Iowa

    View Slide

  4. Sparrows Decks

    View Slide

  5. Sparrows Decks

    View Slide

  6. Clutter

    View Slide

  7. bit.ly/sparrowdecks

    View Slide

  8. Time to find things

    View Slide

  9. View Slide

  10. Patterns in the code

    View Slide

  11. View Slide

  12. Accounts_Receivable
    Balance_Sheet
    Cost_of_Goods
    Expenses
    Liabilities_2010
    Present_Value
    Profit_And_Loss
    Outstanding_Invoices
    Accounts_Receivable_2010
    Balance_Sheet_2010
    Cost_of_Goods_2010
    Expenses_2010
    Liabilities
    Present_Value_2010
    Profit_And_Loss_2010
    Outstanding_Invoices_2010
    Accounts_Receivable_2010
    Balance_Sheet_2010
    Cost_of_Goods_2010
    Expenses_2010
    Liabilities
    Present_Value_2010
    Profit_And_Loss_2010
    Outstanding_Invoices_2010

    View Slide

  13. Long lines
    if (fullName.StartsWith(hintAssemblyName, StringComparison.OrdinalIgnoreCase)
    && stream != null && BrowserInteropHelper.IsBrowserHosted || (loadedAssembly.FullName.S

    View Slide

  14. Encapsulation
    & Readability

    View Slide

  15. if (fullName.StartsWith(hintAssemblyName, StringComparison.OrdinalIgnoreCase)
    && stream != null && BrowserInteropHelper.IsBrowserHosted || (loadedAssembly.FullName.S
    if (isAssemblyAvailable())
    vs.

    View Slide

  16. Long Methods
    // If a license key has been located...
    if (licenseKey != null) {
    // Decrypt
    licenseKey = ActiproLicenseProvider.DecryptString(licenseKey, encryptionKey);
    // Find the licensee and license key
    string[] licenseKeyData = licenseKey.Split(new Char[] { ';' });
    if (BrowserInteropHelper.IsBrowserHosted) {
    // XBAP licensing uses required assembly / licensee / license key
    // Ensure that the specified assembly is in the AppDomain
    string requiredAssemblyName = licenseKeyData[0].Trim();
    Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
    bool assemblyFound = false;
    foreach (Assembly loadedAssembly in assemblies) {
    if (loadedAssembly.FullName.StartsWith(requiredAssemblyName + ",", StringCompari
    assemblyFound = true;
    break;
    }
    }
    if ((assemblyFound) && (plainTextLicensee == licenseKeyData[2]) && (String.Compare
    // Assembly was found so use license data
    licensee = licenseKeyData[2];
    licenseKey = licenseKeyData[1];
    sourceLocation = ActiproLicenseSourceLocation.AssemblySavedContext;
    }
    }
    else {
    // Regular licensing just uses licensee / license key
    licensee = licenseKeyData[1];
    licenseKey = licenseKeyData[0];
    sourceLocation = ActiproLicenseSourceLocation.AssemblySavedContext;

    View Slide

  17. Encapsulation
    & Readability

    View Slide

  18. Merge Conflict

    View Slide

  19. Bad Names

    View Slide

  20. Time to Onboard New Employees

    View Slide

  21. Silo’s

    View Slide

  22. Lingo

    View Slide

  23. @LlewellynFalco
    DoSomething
    EvilTo
    Database()
    Foo()
    ParseXml
    AndStoreFlight
    ToDatabase
    AndLocalCache
    AndStart
    Processing()
    StoreFlight
    ToDatabase
    AndStart
    Processing()
    Begin
    Tracking
    Flight()
    Intent
    Honest Honest &
    Complete
    Does the
    Right Thing Domain
    Abstraction
    Monitoring
    Panel
    .Add(flight)
    The 7 stages of naming
    Start
    Structural
    Refactoring
    By ArloBelshee
    Missing
    Nonsense

    View Slide

  24. @LlewellynFalco
    Foo()
    Missing
    Nonsense
    // If a license key has been located...
    if (licenseKey != null) {
    // Decrypt
    licenseKey = ActiproLicenseProvider.DecryptString(licenseKey, encryptionKey);
    // Find the licensee and license key
    string[] licenseKeyData = licenseKey.Split(new Char[] { ';' });
    if (BrowserInteropHelper.IsBrowserHosted) {
    // XBAP licensing uses required assembly / licensee / license key
    // Ensure that the specified assembly is in the AppDomain
    string requiredAssemblyName = licenseKeyData[0].Trim();
    Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
    bool assemblyFound = false;
    foreach (Assembly loadedAssembly in assemblies) {
    if (loadedAssembly.FullName.StartsWith(requiredAssemblyName + ",", StringCompari
    assemblyFound = true;
    break;
    }
    }
    if ((assemblyFound) && (plainTextLicensee == licenseKeyData[2]) && (String.Compare
    // Assembly was found so use license data
    licensee = licenseKeyData[2];
    licenseKey = licenseKeyData[1];
    sourceLocation = ActiproLicenseSourceLocation.AssemblySavedContext;
    }
    }
    else {
    // Regular licensing just uses licensee / license key
    licensee = licenseKeyData[1];
    licenseKey = licenseKeyData[0];
    sourceLocation = ActiproLicenseSourceLocation.AssemblySavedContext;
    }
    The 7 stages of naming

    View Slide

  25. @LlewellynFalco
    DoSomething
    EvilTo
    Database()
    Honest
    The 7 stages of naming
    Nonsense Foo()

    View Slide

  26. @LlewellynFalco
    ParseXml
    AndStoreFlight
    ToDatabase
    AndLocalCache
    AndStart
    Processing()
    The 7 stages of naming
    Honest Honest &
    Complete
    DoSomething
    EvilTo
    Database()

    View Slide

  27. @LlewellynFalco
    StoreFlight
    ToDatabase
    AndStart
    Processing()
    The 7 stages of naming
    Honest &
    Complete
    Does the
    Right Thing
    Start
    Structural
    Refactoring
    ParseXml
    AndStoreFlight
    ToDatabase
    AndLocalCache
    AndStart
    Processing()

    View Slide

  28. @LlewellynFalco
    The 7 stages of naming
    Intent
    Does the
    Right Thing
    StoreFlight
    ToDatabase
    AndStart
    Processing()
    Begin
    Tracking
    Flight()

    View Slide

  29. @LlewellynFalco
    The 7 stages of naming
    Intent Domain
    Abstraction
    Begin
    Tracking
    Flight()
    Monitoring
    Panel
    .Add(flight)

    View Slide

  30. @LlewellynFalco
    DoSomething
    EvilTo
    Database()
    Foo()
    ParseXml
    AndStoreFlight
    ToDatabase
    AndLocalCache
    AndStart
    Processing()
    StoreFlight
    ToDatabase
    AndStart
    Processing()
    Begin
    Tracking
    Flight()
    Intent
    Honest Honest &
    Complete
    Does the
    Right Thing Domain
    Abstraction
    Monitoring
    Panel
    .Add(flight)
    The 7 stages of naming
    Start
    Structural
    Refactoring
    By ArloBelshee
    Missing
    Nonsense

    View Slide

  31. Duplication
    Duplication
    Duplication
    Duplication
    Duplication
    Duplication
    Duplication
    Duplication
    Duplication

    View Slide

  32. Inconsistency

    View Slide

  33. View Slide

  34. LlewellynFalco.blogspot.com

    View Slide

  35. Resources
    www.ApprovalTests.com
    21 episode youtube series

    View Slide

  36. #MobProgrammingGuidebook

    View Slide

  37. Contact Information
    @LlewellynFalco
    http://LlewellynFalco.Blogspot.com
    http://www.approvaltests.com

    View Slide