Why user defined types?

Hello,

at this state of code I do not see code being reduced when we introduced the struct AnimData type and made scarfyData, nebData and neb2Data. This was introduced as one of the reasons why user defined types. Mybe this will happen latter when we introduce some structures of AnimData. Like array or vector.

One of the reasons to introduce new types I have found int the Byorne Stroustrup book. Principles of programming. He says:

Types are good for directly representing ideas in code. When we write code, the
ideal is to represent our ideas directly in our code so that we, our colleagues, and the compiler can understand what we wrote.
Example: When we want to do integer arithmetic, int is a great help.

The help comes in two forms:
• Representation: A type “knows” how to represent the data needed in an object.
• Operations: A type “knows” what operations can be applied to objects.

Many ideas follow this pattern: “something” has data to represent its current value — sometimes called the current state — and a set of operations that can be applied.

Cheers

I’d say I agree with your quote. Using AnimData allows us to have a couple of things, if not reduced lines of code.

First, we have a more human-readable representation of what our code is and what it is doing that goes beyond adding comments. Sometimes referred to as self-documenteting or self-commenting code.

Second, it gives us a single place where code needs to be modified if we want to change how the animation system works for our game. This improves the maintainability of our code.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms