Re: Hypothetical: All code in classes but main()
Steven T. Hatton wrote:[color=blue]
> Jeff Schwab wrote:
>
>[color=green]
>>Steven T. Hatton wrote:
>>[color=darkred]
>>>Jeff Schwab wrote:
>>>
>>>
>>>
>>>>Steven T. Hatton wrote:
>>>>
>>>>
>>>>
>>>>>I actually proposed another access specifier in addition to private,
>>>>>protecte d, 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.[/color]
>>
>>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& );[/color]
>
>
> 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.[/color]
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.
[color=blue]
> 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.[/color]
But changing the word "namespace" to "class" would fix the perceived
problem?
[color=blue]
> 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_subcat egory_type names. These should more correctly be
> category::subca tegory::type.[/color]
How would grouping items in classes instead of namespaces change this?
Steven T. Hatton wrote:[color=blue]
> Jeff Schwab wrote:
>
>[color=green]
>>Steven T. Hatton wrote:
>>[color=darkred]
>>>Jeff Schwab wrote:
>>>
>>>
>>>
>>>>Steven T. Hatton wrote:
>>>>
>>>>
>>>>
>>>>>I actually proposed another access specifier in addition to private,
>>>>>protecte d, 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.[/color]
>>
>>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& );[/color]
>
>
> 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.[/color]
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.
[color=blue]
> 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.[/color]
But changing the word "namespace" to "class" would fix the perceived
problem?
[color=blue]
> 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_subcat egory_type names. These should more correctly be
> category::subca tegory::type.[/color]
How would grouping items in classes instead of namespaces change this?
Comment