New in C#4
Jarrett Billingsley
jarrett.billingsley at gmail.com
Wed Oct 29 12:29:20 PDT 2008
On Wed, Oct 29, 2008 at 10:37 AM, bearophile <bearophileHUGS at lycos.com> wrote:
> Thanks to Reddit I have found a nice short document that lists some of the differences of C#4:
> https://docs.google.com/View?docid=dcj4xk6_17ffc7nmgv
>
> They have added a dynamic invocation, useful if you want to implement a dynamic language (like IronPython, IronRuby, etc) on top of the dotnet. Object-C shows this is doable in a very C-like language, and the Boo language shows that in a statically typed language it can be useful to use a Duck type once in a while to reduce the "static type pressure". More info on this last concept in the Boo site.
Aw, man, they beat me to it. I always wondered if it would be cool to
have a language that supported both static and dynamic programming
natively. It was going to be the "cool thing" in the next language I
made ;) (it probably still will!)
> Something that I like a lot is the named arguments, that I hope to see in D and Delight someday. They are used often in Python, and they help increase the readability of the code, sometimes even reducing mistakes.
> They have used colons:
> foo(x: 1, z: 3)
> While Python uses equal signs:
> foo(x=1, z=3)
> I think they are about equally readable.
> (I think there's a problem with named arguments, that you can solve in some ways, for example with an extra hidden bitfield argument that encodes what arguments are given and what not).
Or, you could enforce that named arguments must all have default
values, or that they must _all_ be given when the function is called.
Since it's getting resolved at compile time, no bitfield is necessary.
It's the same thing as arguments with default values -- all the
compiler does is it inserts the default values at the call site.
Named parameters are very cool, though, and are invaluable for things
like GUI APIs. Combined with structs, they can also remove the need
for a separate struct literal syntax. S(x: 5, y: 10) looks pretty
damn nice.
More information about the Digitalmars-d
mailing list