67
Comments
  • 13
    Schroedinger's results. You need to measure the exam to know whether you failed.
  • 0
    Flipping boolean expressions is hard.
  • 0
    Sometimes we need to learn basic math 😂
  • 1
  • 6
    @Marethyun

    Programming logic becomes a lot easier once you stick to the following rules of thumb:

    1. Give a method a single responsibility.

    2. Because of 1, nesting depth should be limited to a single level.

    3. Avoid using the keywords "else"/"else if". No need to prohibit it in your code, just check if you can avoid it.

    4. Use failure conditions with early returns instead.

    This is a pretty solid article about it:

    https://medium.com/better-programmi...
  • 4
    @bittersweet
    Didn't get much farther than guard expressions. Most of what he suggests works best in a functional approach. The imperative if/if/if/... style checking is leaning towards type guarding, which is type refinement that results in implicit type awareness of types based on compositional checking. He has almost arrived at the concept of discriminated unions and list comprehensions/pattern matching, but not quite. It's really boilerplatey without structural induction support and union types.

    A more stringent/reusable/flexible approach in imperative structures would be church encoding (https://en.wikipedia.org/wiki/...).

    Generally speaking, multiple return statements is the code smell for incorrect paradigm here.
  • 1
    @SortOfTested

    I agree that it is a simulated guard pattern.

    I disagree that it is a code smell to have multiple returns... unless you agree with me that any language that doesn't offer pattern matching / guards is super smelly by default 😛

    For any language without pattern matching / guards, having a few "ifs" with early returns followed by the happy path code feels a lot better than having nested ifs and stacks of if/else/elseifs.

    The clearest you can get with old-fashioned OOP languages is a "let's check if everything is in order, before we go on with the good stuff" pattern, with early returns.

    But the whole syntax of if is a bit iffy, I do prefer Rust's pattern matching syntax.
  • 2
    @bittersweet
    Given how many languages have introduced pattern matching and stream abstractions, I'd actually probably say that description is accurate :)
  • 1
  • 2
    @PonySlaystation in two alternative universes you passed and failed lol. The many world's test.
Add Comment