• 1 Post
  • 80 Comments
Joined 2 years ago
cake
Cake day: December 31st, 2023

help-circle


















  • I did this once

    I was generating a large fake dataset that had to make sense in certain ways. I created a neat thing in C# where you could index a hashmap by the type of model it stored, and it would give you the collection storing that data.

    This made obtaining resources for generation trivial

    However, it made figuring out the order i needed to generate things an effing nightmare

    Of note, a lot of these resource “Pools” depended on other resource Pools, and often times, adding a new Pool dependency to a generator meant more time fiddling with the Pool standup code


    • if something feels too “heavy”, like it’s doing xml formatting, file manips, a db insert, and making coffee, all in a single class or function

    Separate out those “concerns”, into their own object/interface, and pass them into the class / function at invocation (Dependency Injection)

    • use “if guards” and early returns to bail from a function, instead of wrapping the func body with an if
    
    public Value? Func(String arg) {
      if (arg.IsEmpty()) {
        return null;
      }
      
      if (this.Bar == null) {
        return null;
      }
    
      // ...
      return new Value();
    
    
      /// instead of
    
      if (!arg.IsEmpty) {
        if (this.Bar != null) {
          // ...
          return new Value();
        }
      }
    return null;
    }