I’ve been playing a lot of Left 4 Dead lately. It’s super-fun: in each of the levels (4 scenarios with 5 big levels each) you and three other players must survive hordes of zombies to reach the Safe Room or the transport out of the city.
I’ve been playing a lot of Left 4 Dead lately. It’s super-fun: in each of the levels (4 scenarios with 5 big levels each) you and three other players must survive hordes of zombies to reach the Safe Room or the transport out of the city.
Here’s a bit of background on class members and singletons to flesh out my previous post on automatic singletons.
First let’s look at regular classes and objects. A class defines how an object behaves and what properties it has. If we wanted to make an adventure-RPG we might define classes for Torch, Horse, Ration, Weapon, and others. In Slag:
It’s the same story as always. After being mildly irritated by something for a long period of time, I finally notice it and then decide to do something about it.
This time it’s class properties and methods – also known as static variables and methods. Not only do they complicate my compilers (“do everything twice… once for the class members and once for the object members”) and not only are they hard for beginners to grasp, but they’re just plain awkward to use. Inheritance doesn’t work quite right (you can’t use super.method_name()), you can’t give anything a “this” reference, and you can’t get Class object metadata or do a toString().
Thinking about it today, I realized something important and fundamental: class members are a kludge.
As one of the last born into the “C generation”, I learned programming in the twilight of the procedural years. Like many others, I initially fit the newly-emerging object-oriented concepts into my C worldview, thinking of objects as “structures with access methods”: if you have a Clock object with {hours,minutes} values, then you write a pair of access methods for each value: getHours(), setHours(), getMinutes(), and setMinutes(), allowing for access control and implementation independence. Sounds good, right?