Re: static class inheritance, generalized



Jon Skeet [C# MVP] wrote:

Frans Bouma [C# MVP] <perseus.usenetNOSPAM@xxxxxxxxx> wrote:
Do you really have no idea, in real life rather than in theory?
Would you not guess that it was in System.Math, given no other
information, and considering the context?

I don't want to 'guess', Jon. That's the whole point. Of course,
any math method likely will be in Math, though the world is bigger
than the set of methods in Math. Of course, with 'Sqrt' it's pretty
obvious where that method might be located, however
Validate(myCustomer) is a bit less clear.

Which is why it would be a bad idea to use it for Validate.

Here's another example, without changing anything. If I write a
method called "DoSomething" then wherever I use it, I've either got
to guess what it does or consult the documentation (which would
usually be via Intellisense).

What's my answer to this? Naming methods sensibly.

Sure, though if the language has the construct of static methods, the
class name becomes part of the method name (IMHO), in such a way that
the scope in which the method operates is described by the class name
so it's not necessary to add that description in the method name itself.

FOr example, String.Copy(). It's a static method. Using the proposed
mechanism, I end up with code like:
myVar = Copy(myOtherVar);

In a procedural language, one wouldn't use 'Copy'. One would use
CopyString() for example as it copies a string. But because the method
is statically defined on String, CopyString is redundant, Copy is
enough information, as 'String' is already specified.

Have you read much C# code that requires extensive use of
System.Math?

No, last time I did geometry related code was in C++ some years
ago.

I suspect you'd be more in favour of the feature if you had had to
experience the nastiness which requiring "Math." presents.

I guess :)

I.o.w. a way to have any DSL D inside C# and where context
awareness is possible inside D and C# would be very welcome. But
that's not going to happen, see the way how they added Linq instead
of adding a DSL awareness and WITH that Linq. That same DSL
awareness then would have given you the ability for formulate the
formulas in a language much more expressive for that than C# and at
the same time wouldn't butcher C# with features which are actually
a big burden for a lot of other situations than the situation it
would be handy for.

Well, the situation I was thinking of is actually Hibernate and its
Criteria API, but I can't find the page that gives a nice example at
the moment.

We use a similar API, to get compile time checked queries (without
having Linq around ;)). Like:
IPredicate p = (CustomerFields.CompanyName == "BigCorp Inc");

The perfect DSL for querying is SQL, it's however set oriented, not
procedural nor OO. That friction has to be overcome somehow, if you
want to specify what you want in C# if you can't use SQL. IMHO the same
with mathematical procedures in an OO environment. Cutting up the
target language to become a language for another paradigm is IMHO
making the language very weak and open for abuse. Better is to enable
interoperability in a transparent form so you can write a complex
formula in the DSL which does that best, evaluate it with that DSL and
refer to the result in normal C#. And back, refer to values in the C#
program in the formula.

It would get you what you want, and in the best possible form. However
I'm not sure if we'll see it in a short timeframe in C#, unless things
like JRuby will get that much traction that MS has to act upon it. (For
the JRuby impaired readers: JRuby is an enviroment which allows you to
write ruby code and java code and let them interoperate on eachother:
call java code from within ruby, call ruby code from within java and
refer to elements living in the other language space).

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#)
------------------------------------------------------------------------
.



Relevant Pages