POV-Ray : Newsgroups : povray.off-topic : C# 4.0 Default parameters Server Time
9 Oct 2024 17:42:37 EDT (-0400)
  C# 4.0 Default parameters (Message 27 to 36 of 56)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Warp
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 12:51:55
Message: <4989d5bb@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> I think better would be the way you wind up having to do it in Java - you 
> have a class that implements a "parse this" method for each possible 
> argument to be parsed, and the parser has a map from "-debug" to an instance 
> of the class that parses the debug parameter.  So you have one subclass for 
> each parser function.  Ugly, but not as bad as a giant switch statement.

  Actually that's the most cumbersome solution (especially if you wanted
all the options inside one single class, rather than having one class per
option, which makes retrieving the values of the options more laborious)
and the one which requires most extra writing.

  Yes, I considered many possible solutions when I implemented that command
line parser class, and found that the function (or rather method) pointer
solution was the best, from the usage point of view. The classes derived
from the parser class can be made simple, short and easy to read.

> FWIW, a delegate *is* an object that behaves like a function (your "functor 
> object").  You write something like

  Does it also work for member functions?

  Member function pointers are a bit complicated in C++, but they can
be useful (as in my command line parser example). Obviously to call a
member function of a class through a pointer you need also the object for
which the function is called. The syntax for calling such a function is:

    object.*functionPointer(parameters);

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 12:54:38
Message: <4989d65e@news.povray.org>
Mike Raiford <"m[raiford]!at"@gmail.com> wrote:
> C# uses delegates, instead.

  How do they work for member functions?

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 12:57:46
Message: <4989d71a@news.povray.org>
Mike Raiford <"m[raiford]!at"@gmail.com> wrote:
> I remember declaring structs in C being rather weird.

  The problem with C structs is that whenever you want to use them, you
have to say so. In other words, this works in C++, but not in C:

struct Foo { whatever; };

void bar()
{
    Foo foo; // Doesn't work in C
}

  Instead, you have to write:

    struct Foo foo; // Works in both C++ and C

  However, there's a workaround in C (which also works in C++, because of
the backwards compatiblity):

typedef struct { whatever; } Foo;

  Now you can use "Foo" without having to put the "struct" before it every
time.

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 13:02:58
Message: <4989d852@news.povray.org>
nemesis <nam### [at] gmailcom> wrote:
> I don't like the whole OO BS.  Despite being submitted to it daily for 
> the last 20 years or so.  Functional programming and scripting too 
> opened my eyes to a much better model for software programming.

  Yet most functional programming languages support objects in one way
or another.

  The fact is: If a programming language supports types, if it also
supports abstract user-defined types, it becomes an order of magnitude
more expressive and useful. And abstract user-defined types are objects
(in the OO sense).

-- 
                                                          - Warp


Post a reply to this message

From: Mike Raiford
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 13:06:18
Message: <4989d91a$1@news.povray.org>
Warp wrote:
> Mike Raiford <"m[raiford]!at"@gmail.com> wrote:
>> C# uses delegates, instead.
> 
>   How do they work for member functions?
> 

Transparently.

e.g.

delegate void myDel(int x);

class SomeClass
{
   public int myValue;

   public void DoInstanceStuff(int x)
   {
     myValue = x;
   }

   public static void Main()
   {
     SomeClass c = new SomeClass();

     myDel d = c.DoInstanceStuff

     d(6); // this sets c.myValue to 6;

   }
}

-- 
~Mike


Post a reply to this message

From: nemesis
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 13:30:54
Message: <4989dede@news.povray.org>
Warp escreveu:
>   The fact is: If a programming language supports types, if it also
> supports abstract user-defined types, it becomes an order of magnitude
> more expressive and useful. And abstract user-defined types are objects
> (in the OO sense).

But that's within a function composition environment.  I don't like OO's 
step-by-step, verbose and multilayered approach of redundancy.  I also 
don't like all the naming conventions done for the sake of stupid, 
easily replaceable drones programming in big enterprises, like as if 
they were programming in notepad rather than in contextful high-end 
IDEs.  Then again, perhaps even Haskell would follow the same fate were 
it to be endorsed by the industry...


Post a reply to this message

From: Darren New
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 13:34:33
Message: <4989dfb9$1@news.povray.org>
Mike Raiford wrote:
> What is the difference between a multicast delegate, as shown here, and 
> an event?

An event is a delegate with only += and -= exposed outside the class. I.e., 
declaring an event vs a delegate is like declaring a protected member vs a 
public member.  Same type of object, different visibility for callers.

-- 
   Darren New, San Diego CA, USA (PST)
   "Ouch ouch ouch!"
   "What's wrong? Noodles too hot?"
   "No, I have Chopstick Tunnel Syndrome."


Post a reply to this message

From: Darren New
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 13:40:48
Message: <4989e130@news.povray.org>
Warp wrote:
> Darren New <dne### [at] sanrrcom> wrote:
>> I think better would be the way you wind up having to do it in Java - you 
>> have a class that implements a "parse this" method for each possible 
>> argument to be parsed, and the parser has a map from "-debug" to an instance 
>> of the class that parses the debug parameter.  So you have one subclass for 
>> each parser function.  Ugly, but not as bad as a giant switch statement.
> 
>   Actually that's the most cumbersome solution 

OK. By "better" I meant perhaps "more maintainable" or "more reusable" or 
"more OO".  The way I suggested lets you easily reuse the parser classes in 
other programs, for example. I can write a "-geom" parser and you can write 
a "-regex" parser, and Fred can combine them into one program easily.

>> FWIW, a delegate *is* an object that behaves like a function (your "functor 
>> object").  You write something like
> 
>   Does it also work for member functions?

Yes. Anything that'll take a float and return an integer works. So you can 
combine a static function that takes a float and returns an integer, plus a 
member function that takes an instance (as a distinguised parameter, i.e., 
in "o.xyz()" syntax) and a float and returns an integer, and have them both 
in the delegate at the same time.

>   Member function pointers are a bit complicated in C++, but they can
> be useful (as in my command line parser example). Obviously to call a
> member function of a class through a pointer you need also the object for
> which the function is called. The syntax for calling such a function is:
> 
>     object.*functionPointer(parameters);

Yah. A C# delegate wraps up both the instance and the member method in one 
syntax.  So you'd say

   class Thing {
     static public int pdq(float y) { ... }
     public abc(float z) { return (int) (z*this.stuff); }
     int stuff;
     Thing() { stuff = 28; }
   }

   Thing o = new Thing();
   delegate int xyz(float x);
   xyz = Thing.pdq;
   xyz += o.abc;
   xyz(27.3);  //  I think this will return the result of calling o.abc(27.3)

Pretty handy.

-- 
   Darren New, San Diego CA, USA (PST)
   "Ouch ouch ouch!"
   "What's wrong? Noodles too hot?"
   "No, I have Chopstick Tunnel Syndrome."


Post a reply to this message

From: Darren New
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 13:47:44
Message: <4989e2d0$1@news.povray.org>
Darren New wrote:
> Pretty handy.

Actually, what's annoying is that a null delegate doesn't just do nothing 
when you invoke it.  I've never seen a delegate invoked that wasn't guarded with
   if (myptr != null) myptr(...);

Stupid design flaw there, methinks.

-- 
   Darren New, San Diego CA, USA (PST)
   "Ouch ouch ouch!"
   "What's wrong? Noodles too hot?"
   "No, I have Chopstick Tunnel Syndrome."


Post a reply to this message

From: Orchid XP v8
Subject: Re: C# 4.0 Default parameters
Date: 4 Feb 2009 14:03:53
Message: <4989e699$1@news.povray.org>
>> * This is why, if a Haskell function takes any functions as arguments, 
>> they invariably come *first*, and any data structures come *last*. ;-)
> 
> Hmm, this is just a convention, I guess.  There's no technical 
> limitation for a function not appearing last in the argument list.

Oh, sure. Purely a convention. But currying is the reason why this 
particular convention is there. That's all I'm saying.

>> Yeah, looks like in about 8 years or so C# or Python or Ruby will have 
>> stolen everything that is cool about Haskell, and Haskell itself 
>> *still* won't be popular. :-(
> 
> Well, C# can because Microsoft employs the father of Haskell. ;)

Well, actually *anybody* who's read about how Haskell works can copy its 
design. (Although *implementing* it well is non-trivial...)

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.