Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[ESEM 2022] To What Extent Cognitive Driven Development Improves Code Readability

Gustavo Pinto
September 23, 2022

[ESEM 2022] To What Extent Cognitive Driven Development Improves Code Readability

Paper presented at ESEM'22

Gustavo Pinto

September 23, 2022
Tweet

More Decks by Gustavo Pinto

Other Decks in Technology

Transcript

  1. Gustavo Pinto
    To What Extent Cognitive Driven
    Development Improves Code
    Readability?
    1
    Victor Santiago Alberto de Souza
    Leonardo Barbosa
    UFPA & Zup
    Innovation
    UFPA Zup Innovation
    UFPA

    View full-size slide

  2. @zupinnovation zup.com.br
    <>
    @zupinnovation
    ● Software aging is far from
    new
    ● Many old programs are
    essential and still require
    maintenance
    Software gets old

    View full-size slide

  3. https://github.com/spring-projects/spring-framework/blob/b595dc1dfad9db534ca7b9e8f46bb9926b88ab5a/spring-core/src/main/java/org/springframework/asm/ClassReader.java (~4k LOC)

    View full-size slide

  4. https://github.com/spring-projects/spring-framework/blob/b595dc1dfad9db534ca7b9e8f46bb9926b88ab5a/spring-core/src/main/java/org/springframework/asm/ClassReader.java (~4k LOC)
    The goal of CDD is
    to avoid this!

    View full-size slide

  5. What is Cognitive Driven
    Development (CDD)?

    View full-size slide

  6. @zupinnovation zup.com.br
    <>
    @zupinnovation
    Cognitive-Driven Development (CDD)
    ● CDD is a design technique created at Zup
    Innovation, a Brazilian tech company
    ● It is based on two psychological theories
    ○ The Magical Number 7
    ○ The Cognitive Load Theory

    View full-size slide

  7. @zupinnovation zup.com.br
    <>
    @zupinnovation
    The Magical Number 7 (+/- 2) (Miller, 1956)
    ● We are only able to process 7 (+/- 2)
    units of information in short-term
    memory.
    ● As we receive more information
    simultaneously, we lose the ability
    to process it (and we tend to make
    mistakes).
    Units of information
    Comprehension

    View full-size slide

  8. @zupinnovation zup.com.br
    <>
    @zupinnovation
    Cognitive Load Theory (Sweller, 1988; Sweller, 2010)
    ● Each material has its own intrinsic
    complexity, and requires some
    cognitive effort
    ○ Sometimes big, sometimes small
    ● Certain types of items can hinder
    our understanding

    View full-size slide

  9. @zupinnovation zup.com.br
    <>
    @zupinnovation
    CDD in a nutshell
    ● It provides a limit indicating
    how much a code unit could
    grow
    ● It defines the code elements
    that hinder our understanding
    (and then should be limited)

    View full-size slide

  10. @zupinnovation zup.com.br
    <>
    @zupinnovation
    Cognitive-Driven Development (CDD)
    ● It provides a limit indicating
    how much a code unit could
    grow
    ● It defines the code elements
    that hinder our understanding
    (and then should be limited)
    SBES 2021 ICSME 2020

    View full-size slide

  11. It seems that CDD does
    limit the complexity
    during the software
    evolution process …

    View full-size slide

  12. But does it also improves
    code readability?

    View full-size slide

  13. @zupinnovation zup.com.br
    <>
    18 Zuppers
    2 OSS projects
    10s refactorings
    ENASE 2021

    View full-size slide

  14. CDD-Driven
    Refactorings
    Regular
    Refactorings
    The source code quality league (ENASE 2021)

    View full-size slide

  15. The source code quality league (ENASE 2021)
    CDD-Driven
    Refactorings

    View full-size slide

  16. We curated
    10 pairs of code
    10 CDD-Driven
    Refactorings
    10 Original
    Versions
    Does CDD improve code readability? (ESEM 2022)
    CDD-Driven
    Refactorings

    View full-size slide

  17. Does CDD improve code readability? (ESEM 2022)
    We asked 133
    devs to answer
    (and justify) their
    preferences
    Java Experience

    View full-size slide

  18. Does CDD improve code readability?
    Description Original CDD % Original % CDD
    Encapsulating error handling 67 66 50% 50%
    Encapsulating business rules 19 114 14% 86%
    Concatenating logical expressions 9 124 7% 93%
    Extracting classes 14 119 11% 89%
    Listing all imports 45 88 34% 66%
    Functional checking style 95 38 71% 29%
    Extracting classes 27 106 20% 80%
    Encapsulating for loops 10 123 8% 92%

    View full-size slide

  19. Description Original CDD % Original % CDD
    Encapsulating error handling 67 66 50% 50%
    Encapsulating business rules 19 114 14% 86%
    Concatenating logical expressions 9 124 7% 93%
    Extracting classes 14 119 11% 89%
    Listing all imports 45 88 34% 66%
    Functional checking style 95 38 71% 29%
    Extracting classes 27 106 20% 80%
    Encapsulating for loops 10 123 8% 92%
    Does CDD improve code readability?

    View full-size slide

  20. Encapsulating error handling
    Original (50%) CDD (50%)
    “Logging with try-catch is so
    common that I didn’t even need
    to read the code to understand
    its purpose."
    “the code is smaller and
    sounds like English"

    View full-size slide

  21. Encapsulating error handling
    “It is important to known which
    exception could be raised”
    “The method signature is
    clear and it makes it easier
    to understand its behavior”
    Original (14%) CDD (86%)

    View full-size slide

  22. Functional checking style
    “The ternary is an easy resource
    and there was no complex logic to
    justify a .map”
    Original (71%)
    CDD (29%)

    View full-size slide

  23. <>
    @zupinnovation zup.com.br

    View full-size slide