Re: Hypothetical: All code in classes but main()

From: Jeff Schwab (jeffplus_at_comcast.net)
Date: 04/11/04


Date: Sun, 11 Apr 2004 11:06:55 -0400

Steven T. Hatton wrote:
> Jeff Schwab wrote:
>
>
>>Steven T. Hatton wrote:
>>
>>>Jeff Schwab wrote:
>>>
>>>
>>>
>>>>Steven T. Hatton wrote:
>>>>
>>>>
>>>>
>>>>>I actually proposed another access specifier in addition to private,
>>>>>protected, public and firend. I suggested /associated/ which would
>>>>>allow a function to be a member, but it would only have access to public
>>>>>members of its own class.
>>>>
>>>>What purpose would that serve?
>>>
>>>
>>>Binding a helper function to a class, and still exclude it from protected
>>>and private access to data members.
>>
>>A function doesn't need to be a member of a class to be associated with
>>it. Just declare the function in the same namespace as the class, but
>>outside the definition.
>>
>>class C { /* ... */ };
>>
>>void helper_function( C const& );
>
>
> Well, sure. But then we have people running around thinking of namespace
> scope as 'global' and doing unconscionable things such as using::std at
> global scope.

I don't follow your logic. Using namespaces to group related functions
and classes doesn't cause people to misunderstand namespaces. In fact,
this is exactly the canonical usage.

You can't prohibit people from abusing "using" directives. Your
approach prohibits clients placing them even within a single function;
isn't that throwing the baby out with the bath water? Anyway, trying to
prevent your clients from using common coding styles you don't like
seems a little pedantic. It's important to support clients by providing
structure, but it's equally important to respect them, and to allow
flexibility.

> Your example is exactly the functionality I was trying to preserve while
> more tightly associating the helper function with the specific class. The
> idea of having a bunch of classes at namespace scope and a bunch of helper
> functions which apply to one or some, but not all the classes seems
> unstructured to me.

But changing the word "namespace" to "class" would fix the perceived
problem?

> Certainly if care is taken in naming and choosing members of the namespace,
> it is workable. But, from what I've seen, programmers often start grouping
> things with category_subcategory_type names. These should more correctly be
> category::subcategory::type.

How would grouping items in classes instead of namespaces change this?



Relevant Pages

  • Re: Sites and Services Subnets not working
    ... Btw. assuming that you have suffiicent disk space, ... Over all everything is working fine, but I have clients that aren't ... Logging in. ...
    (microsoft.public.windows.server.active_directory)
  • System.Addin
    ... our discussion with the clients, it became clear very early that we will ... need to supply additional functionality for different departments and ... So browsing around I ran across the the System.Addin namespace. ... the addins instead of doing reflection. ...
    (microsoft.public.dotnet.languages.vb)
  • Windows 2003 R2 DFS Question
    ... Are there any known issues or warnings about the use of a space in a DFS ... would a DFS namespace of "\\domain\user data" cause ... problems with clients trying to connect? ...
    (microsoft.public.windows.file_system)
  • Re: empty classes as c structs?
    ... So, on balance, if copy semantics are important to bunch uses, and references ... for namespace I ... making the interface as convenient as possible, ...
    (comp.lang.python)
  • Re: empty classes as c structs?
    ... > I see this, but I think it weakens the case for a single implementation, ... Do you mean there should be a separate Namespace and Bunch class? ... > was matching the argspec of dict. ...
    (comp.lang.python)