C++ style question

David Kramer david at thekramers.net
Sat Dec 23 01:03:21 EST 2006


Jerry Feldman wrote:
> This is more of a style issue. I have a standalone function that I want to 
> use in a number of different classes, let's call it foo.
> On one hand I could simply define and build the function in it's own C++ 
> file, or I could alternatively make it a class, either use the constructor 
> or simply define a static function. 

<rant>
One of the design elements rarely discussed these days is "what are you
optimizing for?"  Efficiency?  Effectiveness?  Speed?  Size?  Only
embedded programmers seem to care about this stuff anymore.

But there are other optimizations that are just as valid today, if not
more so.  Readability, maintainability, ability to handle bad input,
"principle of least surprise",....
</rant>

In this case, I would vote for simplicity.  With simplicity you usually
get readability and maintainability for cheap.  Creating a class doesn't
actually buy you anything but complexity in this situation, so don't do
it just because all the cool kids are.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the Discuss mailing list