|
![](/i/fill.gif) |
Mike Raiford wrote:
> That is how C# is now. Sometimes it would be nice just to have one
> function with defaults, rather than 3 overloads of the same function
> that simply delegate back to the "full featured" function.
No, i mean instead of
job.print(orient:landscape, copies:2, paper:A4)
the suggestion it that it's much more OO to say
job.initialize()
job.orient(landscape)
job.copies(2)
job.paper(A4)
job.print()
job.copies has no optional parameters, nor does job.paper, nor job.print.
(Of course, with properties, those could all look like assignments too)
Having three overloaded functions that delegate back to the full one is also
the "wrong" way. Just don't call the set-up function anyway, and have the
constructor set up the default arguments like it should.
The advantage is that if you have 20 possible settings, and you add 3 more,
you just write three new methods to set them and initialize them in the
constructor and you know none of the calls need to be adjusted.
Note that I'm simply presenting a point of view, not arguing that it's
necessarily right. Altho IME doing things this way always seems to lead to
cleaner (altho more verbose) code.
>> Sadly, C# syntax is starting to get really ugly. :-) I expect the
>> overloading rules will soon almost be as bad as C++.
>
> Yep. Default parameters are a C thing.. :D Maybe that's why I like them...
Errr, they are? No. A C++ thing, but not a C thing.
>> > list.SearchForContacts(address="home", name="sam", age:30);
>>
>> Heh. My first thought on seeing the syntax was "I bet I'd always be
>> messing that up and using = instead of :".
>>
>
> I've never been very fond of the named arguments syntax. I'm sure some
> people love it. BTW, why are strings passed with "=" and numbers passed
> with ":"?
I think he screwed it up, is what I'm saying.
list.Search(address="home")
assigns "home" to address, then passes it to list.Search()
I wonder how often that's going to bite someone. :-) Lots, I expect.
--
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
|
![](/i/fill.gif) |