bookmark_borderOverriding and methods

Today I had a little challenge. I had a Class, I call it Class A. It has a method, i call it “doSomething”. Class B extends Class A, and overrides this method with a totally new behavior. Class C who extends from Class B wants to have the original behavior from Class A.

Here is a picture:

The Problem

Now, the simplest but most stupid way to solve this is using copy / paste. Yes, you simply copy the contents of the method of Class A and paste it into the method of Class C and you’re all set right?

Wrong!

It might work for a while, but one of the first things you *should* be feel itchy about, is code duplication! (along with its problems you get when you want to maintain your code).

So what now?

Solution : Use method for shared behavior
Solution : Use method for shared behavior

Well, when you took the easy road and duplicated your code, you probably wanted to get rid of that duplicate code immidiatly… And how do you do that? .. Yes,  you create a new method which is put in Class A , and accessible from Class C and Bam! Code Duplication gone, and you got what you want…

Another way is to re-think your class hierarchy. You might want to consider to do this:

 

Solution : Change in hierarchy, extend C from A, B from C
Solution : Change in hierarchy, extend C from A, B from C

 

 

Yes, you’ve seen it right. Perhaps you can swap Class B and C.  So C extends now from A, and B from C.

But, if you do that, be careful. You need to know exactly what kind of behavior you wanted in Class B. Most likely you have changed that now by extending from C. Take a good look at what methods B was originally calling from Class A, and if it now calls an overridden method by Class C.

These 2 solutions came up today. For my particular problem I’ve used the first. (no, not copy paste smart ass)

I think the first solution is the easiest, I would not recommend anyone to do the second solution unless you really know what you are doing. If you encounter more of these problems like above, swapping might be better for you.  

Do you got another (better?) solution? Let me know!

bookmark_borderGame Programming (Experience)

Recently I saw at Youtube someone telling about his view on game programming. His targetted audience was for those who want to create games, but have no clue how to start. He began with something along the line of “I’ve been programming games for 5 years, so I guess I could say I’m experienced“.

That got me thinking. How long have I been programming (for) games?

I’ve been working on Arrakis since I was around 14/15 years old. I’ve finished it when I was 18. Arrakis is written in Basic (using Quick Basic 4.5). I realized in order to get further I had to learn a new programming language. One that did not had the limitations as Basic. Thats when I had decided to learn C. My first attempt was writing a new Dune II clone, this time really using the Dune II graphics.

After a short period of learning C I began playing around with the Half-Life SDK; I’ve been toying around with a bot framework (Botman’s bot) and before I knew it, RealBot was born. RealBot has been developed for around 4 years.

And, to complete the circle; while RealBot was fading away I picked up again my Dune mania and recreated Dune II – The Maker from scratch. 

Today, I am 26 years old. I haven’t worked on Dune II – The Maker seriously since 2006. This would mean I would have rougly around 7 to 8 years “experience”.  So considering that, I might also say that I have experience in game programming.

When you look at my LinkedIn, you see none of those projects counted as experience. Sure, they are mentioned
under “websites”. But I would prefer to put them in a more suited spot. Perhaps somebody has a suggestion for that.

Although ~ 8 years might sound like a lot. I do think it has to taken with a grain of salt.

First, I did not work 8 hours a day, 5 days a week.
Secondly, I did not have any sparring partners,  so quality wise I did not write superb code.

However, there are concepts that I’ve learned; and you only learn those when you write games. Concepts like:

  • sprite/bitmap management
  • drawing maps / tile engine
  • A*
  • parsing files (from original game)
  • little AI, 
  • state machines, 
  • double buffering
  • blending techniques
  • team colouring (in RTS)
  • using colorkey’s
  • transparancy
  • palette manipulation

And probably a few other things I can’t recall at this moment.

So yeah, perhaps I could say I do have experience in Game programming…

bookmark_borderEclipse IDE for C++

I’ve been working with Eclipse for at least 2 years. When I just learned of Eclipse I was mostly programming C / C++ using Visual Studio 6, which I bought zillion years ago.

Eclipse was a whole new world to me, offering all the convenient tools (like finding references, go to class, etc) a Java programmer could need. 

All my hobby projects are mostly written in C / C++ using the old Visual Studio version. It worked well, but after getting used to Eclipse, going back to Visual Studio 6 was like going back to the stone age. Of course, at this time Visual Studi0 7 is already out-dated; If I’m not mistaken, version 9 or 10 is around the corner.

Good news though, there is an Eclipse version where you can develop in C / C++ using the Eclipse IDE. It is available here. You have to use it in combination with a compiler. To get started, I have used MinGW which is easy to set up. Grab that from here

The good thing is, once MinGW was set up correctly, Eclipse automatigically found it (I bet it used the PATH variable) and you could try to compile your first “Hello world” program. 

My first impressions are good, the C++ IDE is actually like the Java variant with all the handy tools.  The performance is good, it works good, It has Doxygen built in for you. All in all I am quite satisfied. Also, I am quite happy that it exists, since Dev-Cpp and Code::Blocks is not being updated. I thought Dev-Cpp had a lot of potential, especially with the built-in packages.

If you ever consider to use an IDE (you don’t need it!) for writing C / C++ programs, you should definately give the Eclipse IDE for C++ a try.

bookmark_borderC&C 3 : Increase shader details prevent crashing

I have 2 computers, one is a laptop which I carry everywhere. But, also a desktop system for playing games. It has an ok video card and an old CPU, but it does the job for now.

Recently I am playing Command and Conquer 3 : Tiberium Wars. Although I own this game for quite some time, only recently I began playing it more often.

For fun I tried it to run on my laptop, which has only an onboard video card (Intel, GMA 450). The graphical performance of this laptop is anything but good, but I gave it a shot.

The game needed to be updated first of course, but after that it actually ran fine… for 5 minutes. 

After 5 minutes it crashed horribly, just showing my Windows (XP) desktop with the known message that the program encountered a problem/error.

It took a while to figure out what was going wrong: The GMA 450 does not support C&C 3 (see Compatibility List)!

I did a search with google and figured that someone at TechGuy found a solution. The solution is easy. First make sure all your graphical settings are on “low”. Then, increase the Shaders setting to “medium”. Thats it!

It sounds weird, but it actually works! The game did not crash after 5, 10, or more minutes. 

Although this does fix the crashing problem, it did not fix my problem of getting owned by the AI.

bookmark_borderRequirements, requirements, requirements…

Recently I am studying an important topic regarding system development, called requirement engineering. A great book covering this topic is from Sommerville, Software Engineering (version 8). 

What I find fascinating is that, from a developer perspective, it is hard to tell if what you’re creating is actually that what the customer wants. Although I am used to using Functional Design’s, which cover the requirements, there are always multiple filters applied to those requirements (and their documents). And, even when finally a developer is building the software, the developer has its own filter applied as well.

The so called ‘gap’ that exists can be minimized by making the language, used for writing requirements, more abstract. Even so, there is simply not enough time to formally write requirements, like how it is done with formal specifications. Unless you’re writing requirements and the needed systems for critical systems (like a nuclear powerplant, aircraft, etc), there will always be gaps.

Something I’ve noticed is that it is also hard to verify if the end-result is actually what the customer defined in their requirements. Or, sometimes it could be that 2 or more requirements simply conflict with eachother. It should not be a problem, when these requirements are discovered early in the process. The real fun begins when these conflicting requirements are discovered later.

The good thing is there are always solutions around the corner, a little agile software development can do miracles and speed up the discovery of ‘gaps’. Using short(er) iterations to confirm your design has proven quite effective. Even when creating ‘just’ requirement specifications. 

I’ve had the pleasure of following a process of discovering requirements and I’ve learned a lot from it. Although I am not an Information Analist, nor a requirement elicitator expert, I did find something interesting about the whole requirement specification process. In one word i could define it as scope.

Somehow determining the scope of the requested functionality versus the requirements it has effect on is easily widened. This is not nescesarily a bad thing, because it is good to know what requirements are effected by a new requirement, or a change in requirement(s).

The problem lies within the complexity which is introduced by cristalizing all the details for all requirements that are ever hit. In my opinion there is a role for the company that actually creates the requirements documents, and the stakeholder(s) who continiously have new, or changed, requirements for their system. 

The role of the company, responsible for creating the system and the requirement documents, should make clear to the stakeholders what effects their requirements have on other requirements on a high-level. Even though there will be effects on the lower level(s), it should be possible to ask for faith, and trust, in your work. It should be possible to ask for an approval on high level requirements, in order to ‘drill down’  to the details. Whenever every detailed question needs to be answered in order to have the high-level requirements being accepted, it will cause multiple (unwanted) effects:

– the requirements remain unclear, and can still change. The context is not defined.
– because no decisions are being made, discussing details could be a waste of time.
– when taking all details into account, the complexity increases significantly. Making it even harder to decide what effect is acceptable for a needed change.

Again, I am no expert. But this is the vision I have built up the past few weeks. I am wondering what others think. If you have any comments then I’d like to hear them.