Episode 4: Function Structure

Function signatures should be small and have few arguments as possible. In this episode, the various types that should or should not be passed was discussed.

Functions are supposed to do one thing – and passing booleans would invalidate this rule because once you pass booleans, the function then does two things – one if the arg is true, and one if the arg is false.

The three prominent programming paradigms were discussed earnestly as well.

Overall, the episode was really great and informative.

  1. Arguments
    • Arguments should be treated as a liability (not an asset), hence it should be limited. Uncle Bob tolerates as much as 3 maximum arguments in a function. And, no booleans, please. Lastly, no output arguments and null defenses as well.
    •  Defensive programming is definitely a smell because it means that you don’t trust in your unit tests OR, you haven’t even built them because the tests would have prevented you to code them in the first place.
  2. The Stepdown Rule
    • We impose an order on methods – typically in a step-down manner where we step-down one level of abstraction at a time.
  3. Paradigms
    1. Functional Programming
      • Basically means there are no side effects. However, we do not hate side effects all the time. In fact, we need desirable side effects because we also want to change / update our databases, for instance. The goal is to impose disciplines on where and how the side effects happen.
      • Command Query Separation (CQS)
        • Functions returning values should have no side effects and functions that returns void (or does not return any values) changes state (has side effects)
      • Tell Don’t Ask (TDA)
        • TDA for state. Do not violate the Law of Demeter. Do not call methods on objects that are returned from a previous method call.
    2. Structured Programming
      • Sequence — Selection — Iteration
      • Errors first
      • Prefer Exception
      • Use Unchecked Exceptions
      • Null is not an error
      • Trying one thing – Again, function are supposed to do one thing – error handling IS one thing.
    3. Object oriented Programming

The best comment is the comment you don’t have to write – Uncle Bob

My name is Roselle and I’m still working on my success story. You heard that right. I’m young, I work at home on my PJs and I’m still going to make many more mistakes in life. Just like you, just like we all do. But the other thing you should know about me is that I love helping people and this blog is one of the many outlets I have in connecting with you. I talk a lot about finance, business, and personal development. Visit my About page, if you want to know more about my story!

Write A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It
Exit mobile version