|
![](/i/fill.gif) |
In article <3d9c22b8@news.povray.org>, Warp <war### [at] tag povray org>
wrote:
> The problem with that is that returning a non-const reference to a
> member variable (which is of course private; if you see a member variable
> anywhere else than in the private part, then dump that code, it's crap)
Well, it is useful, but rarely. The only time I've ever used public
variables is for the components in a 3D vector type, and a color type.
My reasons: they are the only members, and are never going to change,
and it makes code using these vectors a lot shorter and clearer. Speed
isn't a factor, I expect any decent compiler to optimize the function
calls away.
I do use "struct" instead of "class" to differentiate these...there is
no real difference to the compiler other than default access level, but
you will never see a class from me with a public variable. (unless it is
something left over from debugging or some coding mistake)
Off the topic of this discussion, but another thing I've occasionally
wished for was a way to specify specific methods as being exposed to
objects of a class...friend classes are close, but are all-or-nothing.
Sometimes there are two closely related classes that need to talk to
each other, but the API between them doesn't need to be public and they
don't need private access to each other. Maybe a way to group
methods/data members into categories that can be exposed to specific
classes. (category is a bad term, it is already used for something else
in many OO languages and doesn't apply to C++, but I can't think of
anything better)
> is against good OO coding practices, as it pretty much nullifies the whole
> purpose of keeping it in the private part of the class.
> Reading and writing to that variable should be done eg. like this:
Exactly.
> > And I've never used the "?:" operator.
> Why not? It's handy. :)
Never needed it. Expressions using it are much less readable IMO, and
I've never had a situation where using if...else was significantly
longer or more awkward.
--
Christopher James Huff <cja### [at] earthlink net>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tag povray org
http://tag.povray.org/
Post a reply to this message
|
![](/i/fill.gif) |