From: Thiago A. on
> > I'm finding myself analyzing a fairly complex system log (library),
> > where amazingly for me, many classes have lots, or even only, static
> > methods! What strikes me the most, is that static methods are used

Comparing static function X::F of X with non-member function F() I
would choose static function in these situations:

* X is a trait class; Group of functions used in templates
* F is needs access to private or protected parts of X

In other cases I would choose non-member function.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Maciej Sobczak on
On 12 Kwi, 23:59, emitrax <emit...(a)gmail.com> wrote:

> I'm finding myself analyzing a fairly complex system log (library),
> where amazingly for me, many classes
> have lots, or even only, static methods!

As was already pointed out, one possibility is that the author just
discovered that his Java code can be compiled with a C++ compiler. ;-)

Another reason - and a valid one - might be that this code dates back
to the time when compilers did not support namespaces properly and
grouping static functions in classes was a possible way to emulate
this missing functionality. The rest might be just history.

> What strikes me the most, is
> that static methods are used
> even in base class, and classes that inherits from it have only static
> methods.

Yes, that's strange. A "namespace extension", perhaps?

Are there any objects created of these types?

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Tony Delroy on
On Apr 14, 6:55 am, emitrax <emit...(a)gmail.com> wrote:
> On 13 Apr, 11:59, Ulrich Eckhardt <eckha...(a)satorlaser.com> wrote:
> > emitrax wrote:
> > > I'm finding myself analyzing a fairly complex system log (library),
> > > where amazingly for me, many classes have lots, or even only, static
> > > methods!
>
> > Typical reason: Bad code quality. Some people seem to think "OOP is a must"
> > so they put everything into a class, i.e. abuse classes as mere namespaces.
>
> Yes, that's what my colleague and I were wondering. Why not using
> namespaces in
> the first place, if the library has to be used with the following
> syntax
>
> STATICCLASSNAME::STATICMETHOD::Method(bla,bla,bla);

Some people - like John Lakos, author of Large Scale C++ Design or
whatever it's called - have written and used corporate coding
standards that demand classes/structs be used in place of namespaces
precisely because it forces the above usage (not sure if he still
does). You could read that book if you're really keen, but off the
top of my head, some of the kinds of justifications include:

* by being explicit, the code becomes less context-dependent and hence
(supposedly) easier to debug/maintain

* avoiding introduction of ambiguity should a name conflict arise in
distinct namespaces "used" by the same code

* enforcing a reliable association of interface and "physical" files
(as class content can't be declared in multiple files the way
namespace content can).

I'm not saying I've captured John's exact arguments here, or done them
justice, even that there aren't other better reasons, but when I did
take a more detailed interest in it all I came out convinced it was a
bad idea, and remain so. Context and concision are backbones of
clarity and productivity. Interfaces should be decoupled from the
physical files they're in to allow a more organic evolution and
refactoring of physical file layout without compromising the logical
interface. Yes, namespaces can be used with more potential ambiguity,
but the practical issues I've seen with that are less significant than
the productivity and maintenance issues with using classes as
restrictive namespaces.

Cheers,
Tony


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: emitrax on
On 14 Apr, 02:43, Maciej Sobczak <see.my.homep...(a)gmail.com> wrote:
> On 12 Kwi, 23:59, emitrax <emit...(a)gmail.com> wrote:
>
> As was already pointed out, one possibility is that the author just
> discovered that his Java code can be compiled with a C++ compiler. ;-)
>
> Another reason - and a valid one - might be that this code dates back
> to the time when compilers did not support namespaces properly and
> grouping static functions in classes was a possible way to emulate
> this missing functionality. The rest might be just history.
>

That could be a reason. Code was written in 2007 and compiled only
with visual studio 2003.

> > What strikes me the most, is
> > that static methods are used
> > even in base class, and classes that inherits from it have only static
> > methods.
>
> Yes, that's strange. A "namespace extension", perhaps?
>
> Are there any objects created of these types?
>

No. Those classes are stated to be non-instantiable.

S.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Maciej Sobczak on
On 14 Kwi, 09:50, Tony Delroy <tony_in_da...(a)yahoo.co.uk> wrote:

> > STATICCLASSNAME::STATICMETHOD::Method(bla,bla,bla);
>
> Some people - like John Lakos, author of Large Scale C++ Design or
> whatever it's called - have written and used corporate coding
> standards that demand classes/structs be used in place of namespaces
> precisely because it forces the above usage

Note that you can also force the above usage by banning the "use
namespace" construct.

In other words, today there is no need to abuse the notion of class
(that is, the set of objects sharing common properties) in order to
achieve what name spaces are designed for (that is, to organize
names).

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]