Re: YesOrNo: useful idiom helper or wanking?

2011-04-13 Thread Bernard Helyer
Named arguments. Seriously. Named arguments. *stares into Andrei's soul*

YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrei Alexandrescu
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrej Mitrovic
It looks like an awkward workaround for that feature called named arguments.

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread FeepingCreature
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...,

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Dmitry Olshansky
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,

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Adam D. Ruppe
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrej Mitrovic
They aren't a part of D as long as we try to avoid them with workarounds that make functions look like crap.

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread KennyTM~
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrej Mitrovic
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.

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrej Mitrovic
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Dmitry Olshansky
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread KennyTM~
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:

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrej Mitrovic
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);

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread KennyTM~
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,

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrej Mitrovic
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.

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread spir
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread spir
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread KennyTM~
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread spir
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);

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread bearophile
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread spir
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) {

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Nick Sabalausky
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Nick Sabalausky
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.

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread spir
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...) {

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrei Alexandrescu
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,

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrei Alexandrescu
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

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Andrei Alexandrescu
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:

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread KennyTM~
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:

Re: YesOrNo: useful idiom helper or wanking?

2011-04-11 Thread Stewart Gordon
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