Defining stuff outside a class – the cool Dartlang Feature

Coming from a java background, I think I had it hammered into my brain that we must stuff every variable or function inside a class. Partially because it makes us think that this OOP Paradigm is the mother of all paradigms, or maybe just because there is no other way to handle this.

But sometimes, when you are putting some random vanilla data in a variable and want it accessible later on from elsewhere, it makes no sense to create a whole class to keep it. So for instance, there is no point of having PhysicsConstants to store something simple like the value of g.

Instead, in Dartlang, we can just write this in the middle of nowhere:

const g = 9.81;

And then maybe even write a getter and a setter at the top level to handle this too!