« Behavioral Economics and Code | Main | Refactoring is Sloppy »

December 21, 2012

Comments

Laszlo Nagy

I like the way you experimenting weird design ideas, and fall in love with them... Seriously, I think it is a good game what you are playing. My closest attempt to write code in functional programming style in C++ was to return everything by value.

The question I have related to your design: Did you use STL in your code?

Previous project I was working were also against using exceptions, and they had to re-implement all the containers. (Same thing I can see in the clang project.)

P.S.: I would love to see a little demo github project, with concrete types, constructor signatures and unit testing tricks around. ;)

Bob Lauer

Lately I realized that when you don't have singletons nor component-style injection of dependencies (setDatabase(...) :-) then you are forced to either pass things around as you mentioned, or pass "smart objects" around that contain (and hide) the dependency - encouraging a more functional style of OO.

Steven J. Greenwald

Do you mean that insufficient information hiding at the lower levels (global variable use) causes bad information hiding that we don't want at the design level (inadvertent obfuscation of design)? If so, this makes a ton of sense.

Truewill

Well said.
The same is true of Service Locator:
http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx

Rajiv Gupta

Global variables are good, specially when used in embedded systems. With a global variable, you know where it is, the compiler can use a fast address mode to fetch and update it and it doesn't get messed up by stack frames.

To make them easier to use, I like to prefix the variable name with the first 3 characters of the class which references the variable. If more than one class accesses the variable, then the first 3 characters of each class which accesses the variable should be concatenated to make the variable name.

This way you don't need to prepend g_ to your variable names. Prepending g_ is not a good practice because the slows down the compiler.

J.

Having a common superclass for something unrelated to a conceptual hierarchy feels wrong. I think dependency injection would be the best solution, I've had very good results with it for embedded systems.

Martin Moene

It's what you get following the GOOS way of developing, I think.

Growing Object-Oriented Software Guided by Tests,
http://www.growing-object-oriented-software.com/

Ben Butler-Cole

Have you looked at Gilad Bracha's Newspeak? It takes the view that module/package/whatever references in most languages are bad global variables in the same way that you were thinking about memory allocation and error reporting.

The comments to this entry are closed.