1

A programming mistake that we had could be prevented with a a compilation error/warning for unused objects (variables/values/etc).

The use case was as follows:

  1. we'd call a function in a loop and we'd add each value it returns to a list
  2. once done with the loop, further in code, we'd only use the size of the list, but none of the individual objects that we've added to it.

The mistake was purely "human" and rather obvious in hindsight. When looking at code you'd get an impression that something is being done with the objects, since they were added to a list etc.

I'm trying to avoid this kind of mistakes in the future. It seems like something that could be automated. For example: if you create an object (or value, even) but don't ever "use" it - you will get a warning, unless you mark it as unused intentionally in your specific context.

I'm curious if there is a programming language / type system that supports similar feature.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
lcf
  • 169
  • 1
  • 8

0 Answers0