Where do you draw the line to stop making abstractions and to start writing sane code? There are tons of examples of 'enterprise code' such as the dozen-file "FizzBuzz" program... even something simple such as an RTS game can have something like:
class Player {} ;/// contains Weapons
class Weapons{} ;/// contains BulletTypes
class BulletType{} ;///contains descriptions of Bullets
class Bullet{} ;///extends PlaceableObject and RenderableObject which can be placed/drawn respectively
class PlaceableObject{} ;///has x,y,z, coords
class RenderableObject{} ;///an object with a draw() command
class MovingObject{}; ///an object with a move() function
etc... and it can turn into a nightmare. This can be drawn to its logical extreme, much like functional programming can be drawn to the extreme where you can create a language with only variables, function application, and anonymous function definitions (although I must admit that is slightly more elegant)...
Any sane advice on this topic?
Simply put, there is too much abstraction if the code is difficult to understand. Now this isn't to say that you should hard code everything, because that's the easiest code to write and read. The easiest test is to either put it down for a few days, pick it back up and ask yourself, does this make any sense.
Over abstraction can create unmaintainable, untestable monstrosities. Under abstraction may mean duplicate code, but duplicate code is almost always better than unmaintainable code. That is until it becomes unmaintainable itself. Duplicate code can be fixed via factoring; the over-abstracted code may not be fixable.
Abstraction in the real world Sounds familiar? Making coffee with a coffee machine is a good example of abstraction. You need to know how to use your coffee machine to make coffee. You need to provide water and coffee beans, switch it on and select the kind of coffee you want to get.
The main purpose of abstraction is hiding the unnecessary details from the users. Abstraction is selecting data from a larger pool to show only relevant details of the object to the user. It helps in reducing programming complexity and efforts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With