Named arguments. Seriously. Named arguments.
*stares into Andrei's soul*
A fair amount of code in std uses this idiom:
enum SomeOption { no, yes }
void someFunction(...parms..., SomeOption, ...more_parms...) { ... }
SomeOption is really a Boolean but replaces the unhelpful call syntax
someFunction(...args..., false, ...more_args...) with the
self-documenting
It looks like an awkward workaround for that feature called named arguments.
On 11.04.2011 16:53, Andrei Alexandrescu wrote:
A fair amount of code in std uses this idiom:
enum SomeOption { no, yes }
void someFunction(...parms..., SomeOption, ...more_parms...) { ... }
SomeOption is really a Boolean but replaces the unhelpful call syntax
someFunction(...args...,
On 11.04.2011 18:53, Andrei Alexandrescu wrote:
A fair amount of code in std uses this idiom:
enum SomeOption { no, yes }
void someFunction(...parms..., SomeOption, ...more_parms...) { ... }
SomeOption is really a Boolean but replaces the unhelpful call syntax
someFunction(...args..., false,
Andrej Mitrovic wrote:
It looks like an awkward workaround for that feature called named
arguments.
Named arguments aren't a part of standard D now, nor does it look
likely they will be for many years.
We've gotta look at the here and now to make decisions; focus
on what we have rather than
They aren't a part of D as long as we try to avoid them with
workarounds that make functions look like crap.
On Apr 11, 11 23:27, Adam D. Ruppe wrote:
Andrej Mitrovic wrote:
It looks like an awkward workaround for that feature called named
arguments.
Named arguments aren't a part of standard D now, nor does it look
likely they will be for many years.
We've gotta look at the here and now to make
On 4/11/11, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote:
template YesOrNo(string name)
{
mixin(enum ~name~ : bool { no, yes });
}
void someFunction(YesOrNo!SomeOption) { }
How exactly would this work? I can't compile it.
Also, I would rather name this template choice. Maybe if people got
used to this word they would understand it when they see it in the
documentation before a function definition. E.g.:
http://codepad.org/9mrL6MOG or if the site is down:
https://gist.github.com/913926
Otherwise I have no idea how
On 11.04.2011 21:13, Andrej Mitrovic wrote:
On 4/11/11, Andrei Alexandrescuseewebsiteforem...@erdani.org wrote:
template YesOrNo(string name)
{
mixin(enum ~name~ : bool { no, yes });
}
void someFunction(YesOrNo!SomeOption) { }
How exactly would this work? I can't compile it.
Yeah it's
On Apr 12, 11 01:49, Andrej Mitrovic wrote:
Also, I would rather name this template choice. Maybe if people got
used to this word they would understand it when they see it in the
documentation before a function definition. E.g.:
http://codepad.org/9mrL6MOG or if the site is down:
On 4/11/11, KennyTM~ kenn...@gmail.com wrote:
The idea, IIUC, is to avoid documenting that extra enum type. So, for
example,
TRange topNCopy(alias less = a b, SRange, TRange)
(SRange source, TRange target,
YesOrNo!SortOutput sorted = false);
On Apr 12, 11 02:29, Andrej Mitrovic wrote:
On 4/11/11, KennyTM~kenn...@gmail.com wrote:
The idea, IIUC, is to avoid documenting that extra enum type. So, for
example,
TRange topNCopy(alias less = a b, SRange, TRange)
(SRange source, TRange target,
Are we talking about readability in a code editor or just the website?
Because without some form of syntax highlighting the function headers
are almost unreadable from the website:
http://i.imgur.com/B5M6u.png
It's a wall of text.
On 04/11/2011 04:59 PM, Andrej Mitrovic wrote:
It looks like an awkward workaround for that feature called named arguments.
True, but only for the case of yes/no; in this case only, the bool type
provides proper *constants* which *meaning* is obvious. Else, you need an enum
anyway, even
On 04/11/2011 07:49 PM, Andrej Mitrovic wrote:
Also, I would rather name this template choice.
YesOrNo is far better, by making it clear it's a kind of logical choice /
closed question. Choice is super vague.
Denis
--
_
vita es estrany
spir.wikidot.com
On Apr 12, 11 03:05, Andrej Mitrovic wrote:
Are we talking about readability in a code editor or just the website?
The concern is that 'OpenRight' needs to be documented separately from
'until'. With 'YesOrNo', documentation of 'OpenRight' can be omitted.
Because without some form of
On 04/11/2011 08:16 PM, KennyTM~ wrote:
import std.stdio;
template YesOrNo(T) if(is(T == enum) !T.no T.yes) {
alias T YesOrNo;
}
enum Redraw : bool { no, yes }
void drawCircle(YesOrNo!Redraw redraw) {
writeln(cast(bool) redraw);
}
void main() {
drawCircle(Redraw.yes);
spir:
True, but only for the case of yes/no; in this case only, the bool type
provides proper *constants* which *meaning* is obvious. Else, you need an
enum
anyway, even with named args.
f = File(path=f.txt, mode=2);
Right, in some cases I prefer an enum and in some cases a named
On 04/11/2011 08:16 PM, KennyTM~ wrote:
If the goal of YesOrNo is simply for documentation, why not define it like this?
import std.stdio;
template YesOrNo(T) if(is(T == enum) !T.no T.yes) {
alias T YesOrNo;
}
enum Redraw : bool { no, yes }
void drawCircle(YesOrNo!Redraw redraw) {
Andrei Alexandrescu seewebsiteforem...@erdani.org wrote in message
news:inv4rv$1dfl$1...@digitalmars.com...
A fair amount of code in std uses this idiom:
enum SomeOption { no, yes }
void someFunction(...parms..., SomeOption, ...more_parms...) { ... }
SomeOption is really a Boolean but
KennyTM~ kenn...@gmail.com wrote in message
news:invke1$2gv6$1...@digitalmars.com...
On Apr 12, 11 03:05, Andrej Mitrovic wrote:
Because without some form of syntax highlighting the function headers
are almost unreadable from the website:
http://i.imgur.com/B5M6u.png
It's a wall of text.
On 04/11/2011 09:35 PM, Nick Sabalausky wrote:
Andrei Alexandrescuseewebsiteforem...@erdani.org wrote in message
news:inv4rv$1dfl$1...@digitalmars.com...
A fair amount of code in std uses this idiom:
enum SomeOption { no, yes }
void someFunction(...parms..., SomeOption, ...more_parms...) {
On 4/11/11 1:29 PM, Andrej Mitrovic wrote:
On 4/11/11, KennyTM~kenn...@gmail.com wrote:
The idea, IIUC, is to avoid documenting that extra enum type. So, for
example,
TRange topNCopy(alias less = a b, SRange, TRange)
(SRange source, TRange target,
On 4/11/11 2:35 PM, Nick Sabalausky wrote:
/// Documentation here
enum SomeOption { no, yes }
///ditto
void someFunction(...parms..., SomeOption, ...more_parms...) { ... }
That groups the two together, right? So solved.
Never thought of it. Facepalm etc. Thanks!
Andrei
On 4/11/11 2:41 PM, Nick Sabalausky wrote:
KennyTM~kenn...@gmail.com wrote in message
news:invke1$2gv6$1...@digitalmars.com...
On Apr 12, 11 03:05, Andrej Mitrovic wrote:
Because without some form of syntax highlighting the function headers
are almost unreadable from the website:
On Apr 12, 11 03:41, Nick Sabalausky wrote:
KennyTM~kenn...@gmail.com wrote in message
news:invke1$2gv6$1...@digitalmars.com...
On Apr 12, 11 03:05, Andrej Mitrovic wrote:
Because without some form of syntax highlighting the function headers
are almost unreadable from the website:
On 11/04/2011 18:13, Andrej Mitrovic wrote:
On 4/11/11, Andrei Alexandrescuseewebsiteforem...@erdani.org wrote:
template YesOrNo(string name)
{
mixin(enum ~name~ : bool { no, yes });
}
void someFunction(YesOrNo!SomeOption) { }
How exactly would this work? I can't compile it.
I make
29 matches
Mail list logo