The purpose of classes

This isn't so much of a technical question as it is a question on programming practices.

I understand what classes are in the sense that they are basically advanced variable types to store complex data, but as i'm writing a toy program i'm noticing that my main file is becoming quickly overcrowded with functions. i'm wondering if it is good programmer practice to write a class, or separate file, as simply a container for general functions that process data instead of defining a type: for example, a class full of static functions parsing and processing player input. would it also be a bad idea to completely forgo the class and just have my functions in file scope or in a namespace? thanks
> a class full of static functions

A class containing only static members is a bad idea.


> completely forgo the class and just have my functions in file scope or in a namespace?

Yes. Ideally, in a namespace. As a separate component, with its own header (.h) and implementation (.cpp).
It all depends on what your program is doing. There are few programs that don't deal with some some type of objects.

Since you haven't said what your program is doing, it is impossible to say whether a class is a good idea or not. Even a simple game lends itself to a Game class and a Player class.

i'm wondering if it is good programmer practice to write a class

Yes, especially if your data lends itself to objects.

as simply a container for general functions that process data instead of defining a type

Usually not a good idea. If the functions are unrelated to an object, then as JLBorges suggested, use a namespace.
Last edited on
Topic archived. No new replies allowed.