<div>On 9 March 2011 13:22, Gareth Charnock <span dir="ltr"><<a href="mailto:gareth.charnock@gmail.com">gareth.charnock@gmail.com</a>></span> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Named arguments are useful when you have a function that takes a large number of parameters, the vast majority of which have default values. For example, have a look at this constructor in wxWidgets:<br>
<br>
<a href="http://docs.wxwidgets.org/trunk/classwx_frame.html#01b53ac2d4a5e6b0773ecbcf7b5f6af8" target="_blank">http://docs.wxwidgets.org/trunk/classwx_frame.html#01b53ac2d4a5e6b0773ecbcf7b5f6af8</a><br>
<br>
wxFrame::wxFrame        (       wxWindow *      parent,<br>
wxWindowID      id,<br>
const wxString &        title,<br>
const wxPoint &         pos = wxDefaultPosition,<br>
const wxSize &  size = wxDefaultSize,<br>
long    style = wxDEFAULT_FRAME_STYLE,<br>
const wxString &        name = wxFrameNameStr   <br>
)<br>
<br>
If you want to change the name argument you need to call<br>
<br>
new wxFrame(a_parent,wxANY,"Hello world",wxDefaultPosition,wxDefaultSize,wxDEFAULT_FRAME_STYLE,"My Custom name str")<br>
<br>
Which meant I had to look up what the default values of pos,size and style where even though I was happy with those default values. The more arguments the more of a pain this setup is without named arguments. Contrast to a hypothetical C++ syntax:<br>

<br>
new wxFrame(a_parent,wxANY,"Hello world",name = "My Custom name str")<br>
<br>
I haven't bothered with the arguments I don't care about and my function call has ended up less sensitive to changes in the wxFrame constructor.<div class="im"><br>
<br>
On 28/02/11 21:50, Jonathan M Davis wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On Monday, February 28, 2011 13:38:34 Don wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
spir wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 02/28/2011 07:51 PM, Jonathan M Davis wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm not entirely against named arguments being in D, however I do<br>
think that any<br>
functions that actually need them should be refactored anyway.<br>
</blockquote></blockquote>
<br>
I agree.<br>
CreateFont() in the Windows API, I'm looking at you. (For Linux people,<br>
that function has about 12 parameters).<br>
<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
???<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In actuality, if I were to vote on whether named arguments should be<br>
in the<br>
language, I would definitely vote against it (I just plain don't want<br>
the code<br>
clutter,  [...]<br>
</blockquote>
<br></div><div class="im">
Just don't use them!<br>
</div></blockquote><div class="im">
<br>
You don't have that option. At least, if you're a library developer, you<br>
don't. (I'm a bit sick of people saying "you don't have to use it if you<br>
don't want to" in language design. If it is in the language, you don't<br>
have a choice. You will encounter it).<br>
<br></div><div class="im">
There are a couple of things that I really, really don't like about the<br>
names argument idea:<br></div><div class="im">
1. It makes parameter names part of the API.<br></div><div class="im">
Providing no way for the function writer to control whether it is part<br>
of the API or not, and especially, doing it retrospectively, strikes me<br>
as extremely rude.<br>
<br>
2. It introduces a different syntax for calling a function.<br>
foo(4, 5);<br>
foo(x: 4, y: 5);<br>
They look different, but they do exactly the same thing. I don't like<br>
that redundancy.<br>
<br>
<br>
Especially since, as far as I can tell, the named arguments are just<br>
comments (which the compiler can check).<br>
If so, a syntax like this would be possible, with no language change at<br>
all:<br>
<br>
pragma(namedarguments); // applies to whole module<br>
<br>
foo(/*x*/ 4, /*y*/ 5);<br>
<br>
--->  if a function parameter has a comment which forms a valid<br>
identifier, it's a named parameter.<br>
<br></div><div class="im">
But I still don't see the need for this feature. Aren't people using<br>
IDEs where the function signature (with parameter names) pops up when<br>
you're entering the function, and when you move the mouse over the<br>
function call?<br></div><div class="im">
And if you really want to see them all the time, why not build that<br>
feature into the IDE?<br>
("hit ctrl-f9 to show all parameter names, hit it again to hide them").<br>
</div></blockquote>
<br><div class="im">
I agree with pretty much everything said here. However, as I understand it,<br>
named parameters (at least as they work in Python) would allow for you to<br>
reorder parameters and give values for paramters which are normally default<br>
parameters without giving values for the default paramters before them, and<br></div>
those changes could not be dealt with by comments. However, I consider them to<br>
be a big _problem_, not a feature - _especially_ the ability to rearrange the<br>
function arguments. All of a sudden you could have<div class="im"><br>
<br>
foo(4, 5);<br>
foo(x : 4, y : 5);<br></div>
foo(y : 5, X : 4);<br>
<br>
all making _exactly_ the same function call. That seem _very_ bug-prone and<br>
confusing to me. foo(x : 4, y : 5) was bad enough, but allowing foo(y : 5, x :<br>
4)? Not good. The amount of effort to understand the code becomes considerably<br>
higher. You could be very familiar with foo and know exactly what parameters it<br>
takes and totally mistake what it's really getting passed, because the arguments<br>
were flipped in comparison to the function parameters.<br>
<br>
I agree with Don. I think that named parameters would cause far more<br>
intellectual overhead and problems than they'd solve.<br>
<br>
- Jonathan M Davis<br>
<br>
- Jonathan M Davis<br>
</blockquote>
<br>
</blockquote></div><br>I actually like the idea of named variables, for these funktions that takes a lot of parameters, mostly because if the libary dev, chooses to change the default value of something, my old placeholder value, will end up being wrong without me knowing anything about it.<div>
<br></div><div>Say:</div><div>wxFrame::wxFrame        (       wxWindow *      parent,<br>wxWindowID      id,<br>const wxString &        title,<br>const wxPoint &         pos = wxDefaultPosition,<br>const wxSize &  size = wxDefaultSize,<br>
long    style = wxDEFAULT_FRAME_STYLE,<br>const wxString &        name = wxFrameNameStr   <br>)<br></div><div><br></div><div>And I call it with the default args, because I have to, to change the name; however then the libary dev decides it would be better to have a default value of size = 800x600, now I'm not getting the default as I wanted to.</div>
<div><br><div><br>-- <br>// Yours sincerely<br>// Emil 'Skeen' Madsen<br>
</div></div>