Re: static class inheritance, generalized



Frans Bouma [C# MVP] <perseus.usenetNOSPAM@xxxxxxxxx> wrote:
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);

Only if you abuse the feature though. There's nothing to force you do

static using System.String;

and indeed I wouldn't recommend it.

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.

Right - so where it's not clear, you don't use the feature.

<snip>

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.

In this case it doesn't make the language "very weak" but enables a
fluent interface which reads quite naturally. (It doesn't particularly
read like SQL, but that's okay.)

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

Have you not heard about DLR and IronRuby?

http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamic-language-
runtime-dlr.aspx

http://www.iunknown.com/2007/04/introducing_iro.html

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • implementing a domain specific language - fit and expectations
    ... i used to work on team that wrote flight scheduling optimization ... optimization problem in our setting. ... a domain specific language fits nicely. ... and the dsl could let them play with different attempts at solving the ...
    (comp.lang.scheme)
  • Re: ruby and DSL
    ... Specific Language) implementation in ruby? ... Object by rSpec. ... DSL, but several. ...
    (comp.lang.ruby)
  • Re: static class inheritance, generalized
    ... Jon Skeet [C# MVP] wrote: ... any math method likely will be in Math, ... In a procedural language, one wouldn't use 'Copy'. ... That same DSL ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: LISP diploma project idea
    ... rather than solving problems in general-purpose programming languages, ... The paper offers nothing higher level than a "Collection DSL". ... The man knows nothing of Lisp. ... to the language, it becomes increasingly difficult to add ...
    (comp.lang.lisp)
  • Re: Is the opportunity for creating objects limited and often exagerated to the detriment of softwar
    ... those features to solve your problem. ... things you can build with the language. ... > objects and using static methods as little as possible. ... > The notion that you have to instantiate an object in order to be working ...
    (microsoft.public.dotnet.languages.csharp)