Hacker News new | past | comments | ask | show | jobs | submit login

Almost all code except the stuff written by the Masters of Succinctness can be shrunk by a factor of 2. Order of magnitude reduction is the only impressive metric.



I talk about code that I can shrink by a factor of 2. Most often without even understanding what the code does, just applying local correctness-preserving transformations.

I'm talking about horrors such as (this was real, production code):

  bool flag = true;
  if (var1 == const1)
  {
    if (var2 == const2)
    {
      // quite a lot of code
      flag = false;
    }
  }
  if (flag == true)
  {
    // a little piece of code.
  }
Clearly, someone forgot to clean up their code. It doesn't take a Master of Succinctness to realize that

  if (var1 != const1 ||
      var2 != const2)
  {
    // a little piece of code
  }
  else
  {
    // quite a lot of code
  }
is much better (the code represented by the comments didn't touch the flag). Plus, such simplifications tend to compound. After a first pass, I often see more possible reductions that can be used for a second, sometimes a third pass.




Applications are open for YC Winter 2020

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: