Sujet : Re: Which code style do you prefer the most?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 02. Mar 2025, 02:24:58
Autres entêtes
Organisation : None to speak of
Message-ID : <87o6ykw7f9.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
User-Agent : Gnus/5.13 (Gnus v5.13)
Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> writes:
On 01.03.2025 23:20, Lawrence D'Oliveiro wrote:
On Sat, 1 Mar 2025 21:32:59 +0100, Janis Papanagnou wrote:
My guess is that this form is just an informal syntax mimicking Perl's
function parameter passing ...
The idea of passing arguments by keyword predates Perl.
>
That wouldn't surprise me. - I know it from Perl. - Which other
(earlier) languages do you have in mind? - What's its origin?
For example, it exists in Ada since 1983. The following are all
equivalent, given that Foo takes integer arguments Arg1 and Arg2:
Foo(Arg1 => 10, Arg2 => 20);
Foo(Arg2 => 20, Arg1 => 10);
Foo(10, Arg2 => 20);
Foo(10, 20);
The syntax is IMHO much nicer than using /*...*/ comments in C.
Python has optional keyword arguments:
print("Oops!", end="", file=sys.stderr)
Perl doesn't have keyword arguments as a language feature, but it can be
mimicked by passing hash or hash reference.
If I wanted to annotate arguments with parameter names, I'd probably use
aligned // comments with the name at the end of the line:
confection = prepare_carefully_according_to_detailed_recipe(
flat, // pan
clarified_butter, // line_with
something_yummy, // filling
lotsa_pastry, // cover_with
90 * MINUTES // bake_for
);
In practice, I seldom do so unless there's direct language support.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */