Weekly programming – The “client” concept (v49)
|
I’d like to describe a concept connected to code structure this week. I was introduced to this concept in a book I’m currently reading called “More Effective C++: 35 ways to improve your programs and designs” by Scott Meyers. It’s an optional book for our current course in programming.
The concept in a nutshell is making classes with it’s “clients” in mind. Clients are the programmers (perhaps yourself included) and other classes or parts of the code that will use the said class. You might stand at a crossroads where making the class more flexible will take more time right now but can save time for the client later on, so making it more flexible is an investment. You might be the client yourself, so this might save yourself time in the future. Making the “more flexible”-choice is probably the best one. Programming games often puts a programmer in a team with other people and making the class easy to use and understand for other fellow programmers is, I would argue, always a good thing. Whenever creating a class keep in mind what it will be used for and how generic you want the class to be. All programmers do this at some level but I believe that this is a somewhat invisible concept and thinking about it can improve a programmers overall skill. I generally make classes for the entire project to work and it usually results in working code but the flexibility of it suffers. I’m currently trying to focus on this concept and improve in this way as a programmer. One big part of this is planning before actually coding. To plan an overall structure of an entire project at the beginning of it is a good thing but it isn’t enough. Classes need to be flexible, especially when making games. Even though game pipelines often have a feature freeze deadline, things often need to change in the code and making it “client oriented” helps when this occurs. Having a broad understanding of what a purpose of a class is and how it connects to other parts of the code is paramount before beginning to code it. Our teacher, Tommi Lipponen, strongly recommended me and my group to plan more last year. So planning and discussing a class with the programming team before creating it is recommended at all stages of development. As a side note I’d say that it is extra important in the early stages of a project. This being said, when working towards a deadline sometimes this concept needs to be neglected. If there isn’t enough time, I personally support patching things together and making it WORK is the most important thing. This is a slippery slope however, making things “just work” might bite you in the ass so choose the moments for it carefully. Tommi mentioned this aswell, to the gist of “almost all games are a big pile of rubbish patched together to work”. This week I had no practical example of code but there is more to coding than that. If this helped anyone I’f love that and I strongly recommend the book I mentioned. |
