Comment

Comment by tdrdt

One thing that helps me a lot is: fail fast.

You program must break when something is not right because shitty lasts forever.

Immutable objects are great but you need to validate them when you construct them and throw an exception when something is not right. And functions should return what you would expect.

For example, this:

  function GetEntitryById(int id):Entity
  {
      var entity = [action to get an entity];
      if(entity == null) {
        throw new Exception("Entity not found");
      }
      return entity;
  }
is better than:

  function GetEntitryById(int id):Entity?
  {
      var entity = [action to get an entity];
      return entity;
  }
parent tdrdt 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton