Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 1.64 KB

File metadata and controls

23 lines (18 loc) · 1.64 KB

My liberal use of final

For someone who asks why I (Justus) use final in every possible context.

  • To be overly explicit for readability purposes
  • To prevent unwanted mutation

This mostly applies to fields and local variables. Declaring immutability is important. It lets us know how a value will change over runtime, and how we can avoid side effects. This is the same reason I use final in parameters declarations. If a parameter is not marked final in my code it will be mutated. To keep this connotation, we must use final everywhere else. I also use final when I can to explicitly specify extendibility. This is important in building a library, like TorqueLib, and as a result of this, I use it in the entire Texas Torque codebase. The most extraneous uses is marking methods that are members of a final class or marking static methods as final. The reason I do this is just to maintain consistency with all function declarations. This is the only case in which I think I may overuse final, but it's a habit.

Sources