Tuesday 18 March 2014

Functions and classes

Maybe I should write a book about C++ because I'm always talking about programming stuff. But let's continue with the simplifying theme. One of the things that happen when you move from C to C++ (classes) is that functions often become simpler, but their amount increases. It's strongly related to the design of classes: how they return and get information from elsewhere.

In the best situation most actions would happen inside the class and then some simple return value or state can be retrieved from the class. What happens when you move from C's functional paradigm to object-oriented style is that you get maybe too interested about simple functions, especially aiming to decrease the amount of parameters to functions.

It's maybe ironic, but more complex functions with reduced parameter data can actually increase the modular OOP design of classes. I think it's good to look at the size and complexity of the public interface and try to create simpler way to handle the input/output of the class. This is even true for type classes that contain some kind of basic data and calculations based on it. You can add more complexity (in form of higher level functions that handle the data in that class) in those simple classes to reduce the complexity from the calling routines.

With functions one of the thing often happens to me is that I write a function just in case it needs to be used more than once. Then I notice it's called only once and in those cases (when it's clearly a part of the main structure of the program) the function's source code can be fused into the calling routine, removing one function. Less functions is good when dealing with a large scale project, because every function counts and contributes to the overall complexity.

Sunday 16 March 2014

Simplifying the source code

I have some problems with updates of the screen and parts of it during a game turn. I've tried to simplify the gameloop, but it still has some bugs like how alcohol content is not updating and stuff like that. It somehow became too complex and started to produce bugs as a side effect of that.

On the other hand my programming has become simpler. You only need the simplest possible way to solve or implement something. The problem is how humans overcomplicate everything and it's often evident in the source code. As a related item the source code of Incursion (by Julian Mensch) is going to be released, because I guess it outsmarted the developer himself. I remember him talking about the elaborated custom scripting and other weird stuff like that which likely became too complex to maintain.

It may prove to be another example of making things too complex, while simplicity would work much better. I have my own problems in Teemu even it is extremely simple itself as a roguelike project. That's why I believe you should simplify the source code when things start to look complex.

Simplifying is not optimizing. I have stopped trying to optimize my code for years now, because it's often a waste of time. Besides when you write simple code it also will probably be fast, because there is less source code and less structures to handle. The actual optimization these days is done by the compiler which handles that stuff much better than a programmer.

Sunday 2 March 2014

New features

Some features are done, but sometimes you want to add features before next release and the list is growing rather than getting shorter. Yet I think the next version can be ready quite soon. If I'm correct most of the time will be spent on testing the game, because Teemu is experiencing some interesting changes.

I have some real life issues as we all do sometimes, but I hope they will pass. I doubt they will affect the development other than positively, which can seem odd... but I guess it's the way I'm responding to problems with people, you know. That's why I got interested about computers, because you don't have to speak to anyone, just write good old source code and turn off rest of the world.