Topic: Function calls with named parameters


Author: vlovich@gmail.com
Date: Wed, 30 Jul 2014 10:55:01 -0700 (PDT)
Raw View
------=_Part_5566_2110760145.1406742901991
Content-Type: text/plain; charset=UTF-8

Hi,

Has there been a proposal to be able to call functions with named
parameters?  Python & ObjC both offer this in a fashion, atlhough as a
runtime-feature.
The advantage is that this would make call-sites easier I think.   To
understand how a particular value is being interpreted, you need not jump
to the function declaration.
It also makes refactoring less error-prone since only the function
signature would potentially change if it's just a re-ordering or you add
some default parameters.

For a simple scenario of the improvement:

Declaration:
void foo(bool someFlag, bool someOtherFlag, bool yetAnotherFlag)

Call-site:
foo(someFlag = true, someOtherFlag = false, yetAnotherFlag = true);

This makes magic-constants easier to use without having to write
boilerplate enums/constants.
Additionally, as mentioned above, it makes it easier to refactor & reading
the call-site is easier.

Of course, there are some challenges (none intractable I think):
1) A declaration doesn't have to specify variable names.
2) Challenges if the declaration variable names don't match the definition
(e.g. if you have 3 booleans & just re-order, it could cause problems)
3) How does this interact with default-value rules?

Thoughts?

Thanks,
Vitali

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_5566_2110760145.1406742901991
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<br><br>Has there been a proposal to be able to call fu=
nctions with named parameters?&nbsp; Python &amp; ObjC both offer this in a=
 fashion, atlhough as a runtime-feature.<br>The advantage is that this woul=
d make call-sites easier I think.&nbsp;&nbsp; To understand how a particula=
r value is being interpreted, you need not jump to the function declaration=
..<br>It also makes refactoring less error-prone since only the function sig=
nature would potentially change if it's just a re-ordering or you add some =
default parameters.<br><br>For a simple scenario of the improvement:<br><br=
>Declaration:<br>void foo(bool someFlag, bool someOtherFlag, bool yetAnothe=
rFlag)<br><br>Call-site:<br>foo(someFlag =3D true, someOtherFlag =3D false,=
 yetAnotherFlag =3D true);<br><br>This makes magic-constants easier to use =
without having to write boilerplate enums/constants.<br>Additionally, as me=
ntioned above, it makes it easier to refactor &amp; reading the call-site i=
s easier.<br><br>Of course, there are some challenges (none intractable I t=
hink):<br>1) A declaration doesn't have to specify variable names.<br>2) Ch=
allenges if the declaration variable names don't match the definition (e.g.=
 if you have 3 booleans &amp; just re-order, it could cause problems)<br>3)=
 How does this interact with default-value rules?<br><br>Thoughts?<br><br>T=
hanks,<br>Vitali<br></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_5566_2110760145.1406742901991--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 30 Jul 2014 21:21:28 +0300
Raw View
On 30 July 2014 20:55,  <vlovich@gmail.com> wrote:
> Hi,
>
> Has there been a proposal to be able to call functions with named
> parameters?  Python & ObjC both offer this in a fashion, atlhough as a

Yes, and there have been multiple discussions on it on this forum.
The earliest proposal is somewhere along the timeline of
http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/1992/WG21%201992/X3J16_92-0054%20WG21_N0131.pdf

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.