Re: static class inheritance, generalized
- From: "Frans Bouma [C# MVP]" <perseus.usenetNOSPAM@xxxxxxxxx>
- Date: Wed, 06 Jun 2007 01:21:37 -0700
Ben Voigt [C++ MVP] wrote:
I'm trying to construct a compelling example of the need for a
language feature, with full support for generics, to introduce all
static members and nested classes of another type into the current
name search scope.
i.e. a very simple application would be
class ManyComputations
{
calling System.Math;
... z = Sin(3*x) + Log(y); // qualifiers not needed
}
This provides a superset of the "inherit from a static class"
concept, without actually using inheritance or conflicting with
"sealed".
All C# experts are invited to join the discussion over in
microsoft.public.dotnet.languages.vc in the thread titled "howto
decouple in .NET?" Some familiarity with C++/CLI is a definite plus.
I agree with Jon, THIS is the C# newsgroup and C# discussions should
be held here. We already have a truckload of offtopic (i.e. which are
more about .NET than C#) discussions here so more ONtopic discussion
here would be great ;)
What you're suggesting is IMHO running into problems very quickly.
With 'Sin' and 'Cos' you might not have duplicates in scope, but what
if you have?
Furthermore, the necessity which makes you want what you're suggesting
is the friction between procedural programming and OO programming: math
methods and calculation methods are typical procedural
methods/routines, which don't really fit into the OO paradigm, unless
you'd add Sin() as a method of an int or double for example.
As the language and framework (C#, .NET) are OO, the routines have to
be placed inside a class. To refer to the methods you now have to
specify in which class they're in. This can be a bit odd at first,
because you just want to call a routine like we all did in C or Pascal
and in these languages you also didn't have to specify in which file
the routine was in, it was just there as long as you'd #include the
header file.
However, if you would go the route of 'if I have included / imported a
header/namespace with solely routines and no classes, I should be able
to call them without specifying their location', you effectively
breaking down the OO nature of C# and will introduce what C++ also has:
a way to program C-style code, without classes.
Personally I think every static method has to be specified with the
class it's in. This is for clarity which method is called (so the
reader of the code can easily understand which method is called, a big
helper in getting bug rates down) and also to avoid duplicate names.
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
.
- Follow-Ups:
- Re: static class inheritance, generalized
- From: Ben Voigt [C++ MVP]
- Re: static class inheritance, generalized
- From: Christof Nordiek
- Re: static class inheritance, generalized
- From: Jon Skeet [C# MVP]
- Re: static class inheritance, generalized
- From: Christof Nordiek
- Re: static class inheritance, generalized
- References:
- static class inheritance, generalized
- From: Ben Voigt [C++ MVP]
- static class inheritance, generalized
- Prev by Date: Re: Named parameters
- Next by Date: Re: compare two structs via ==
- Previous by thread: Re: static class inheritance, generalized
- Next by thread: Re: static class inheritance, generalized
- Index(es):
Relevant Pages
|