From: Mattias Flodin (flodin_at_[hidden])
Date: 2001-11-15 14:44:46
On Thu, 15 Nov 2001, Peter Dimov wrote:
> > I'd say there are more psychological reasons than this. I like to be able
> > to express intent with source code rather than comments, when possible.
> What is the advantage of using C++ instead of a natural language to express
> intent? I can easily cite several drawbacks.
I wouldn't say "instead of" - documentation in a natural language is still
a must (in a separate document), but I like when I can express intent such
as what we're discussing without comments in the source file. Why? Because
a source file is more limited in terms of space. By sparing me the need to
point out details like "A is a singleton", "it is an iterator", or
"member_ is a class member variable", there is more room left to write
other, less regular but useful pieces of information about the code at
hand. I think too much commentation text in a piece of code makes it
harder to follow the actual statements, or get a grasp of what the
function / code block as a whole is doing.
> Is this a library interface? If it is, why do you need the class name at
> all? You know that there is a single instance of A.
> Instead of
> class A: public /* public? */ singleton<A>
> void f();
> why not simply
> namespace A
> void f();
For one thing there is a difference here in that A does not need to
implement f(), it can be a pure virtual function - whereas in your
namespace version f() is bound by the ODR to be the only possible
A inherits publically because that is how to describe isa relationships;
singleton<A> is the class implementing the instance() function.
> > Furthermore there is a big difference between just a global variable and a
> > singleton, in that the singleton may defer instantiation to the user, and
> > thus provide a form of polymorphism.
> So can a global scoped_ptr<A>.
Yes, but that would not be enough to prevent A from being created multiple
times. You could assign a new instance to the scoped pointer in the middle
> MyApp looks like a global to me.
Well it may be in a nameless namespace (giving it the lifetime of a global
while still not polluting the global namespace). My point here though was
that when just using a global the library cannot do simply do "extern
Application app;" and then let the client define it as "MyApp app;".
> My general point is, provide something simple that solves 85% of the
> problems rather than something complex that solves 89% of the problems.
I totally agree with this - it's been on my mind as well. I trust
that not all of Gennadiy's policies / requirements will be needed. But I
saw them as a good starting point - perhaps we can afford a little more
than is necessary in the beginning, and then let empirical results judge
what can be stripped. Because personally, I do not feel that I have enough
experience to judge what others will find useful or not. Neverhteless,
having a template argument for each of those orthogonal 'axes' that he
presented would probably produce a too complex class I agree.
-- Mattias Flodin <flodin_at_[hidden]> "A good thing about C++ is that only Room D418 friends can access your private parts" Department of Computing Science Umeå University S-901 87 Umeå, Sweden Note: Any opinions expressed in this mail are personal, and do not necessarily reflect an official standpoint of Umeå University.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk