View mode: basic / threaded / horizontal-split · Log in · Help
March 17, 2009
Re: eliminate writeln et comp?
Andrei Alexandrescu wrote:
> Hey all y'all,
> 
> 
> Here's another nice bicycle shed discussion. During the recent 
> discussion about globals being harmful, Walter told me something that 
> made me think. I said, hey, there are things that are global - look at 
> stdout. He said, well, that's a bad thing. He then argued that it would 
> be better and cleaner to write:
> 
> stdout.writeln("Hello, world");
> 
> instead of the current:
> 
> writeln("Hello, world");
> 
> On one hand, I agree with Walter. On the other, I want to avoid the 
> phenomenon of the all-too-long "Hello, world" example.
> 
> What do you think?

1. It is not often that a program that is first designed to write to 
stdout is changed to write to somewhere else. (The whole reason of 
stdout is, after all, that you can redirect outside the program!)

2. Of course it would be Proper (as in Prudent, almost as in goody 
two-shoes) to write stdout.writeln. But then, to be useful the 
programmer should write myOutDestination.writeln in order to be able to 
"conveniently" later change the destination.

3. IMHO later redefining stdout would be a moronic idea. (And 
/definitely/ not Prudent!)

4. Globals, shmobals... globals in spirit vs. globals in techicality. I 
can't /believe/ there's any idea in totally banning globals. Heck, this 
language has *goto*. Blind purism has made a few other languages 
impractical.

5. Good defaults a good UI make. Can't we just decide that a bare 
writeln(...) is defined as writing to stdout, period? Without thinking 
of globals.

6. stdout is "global" to such an extent, that it actually exists outside 
of the program. (RTF *nix man, man!)

Blehhhhhhh....

PS, I don't think you were serious with the post.
March 17, 2009
Re: eliminate writeln et comp?
Andrei Alexandrescu wrote:

...

> I said, hey, there are things that are global - look at 
> stdout. He said, well, that's a bad thing. He then argued that it would 
> be better and cleaner to write:
> 
> stdout.writeln("Hello, world");
> 
> instead of the current:
> 
> writeln("Hello, world");


int x;

I suggest we forbid int totally. It is too [insert something here], and 
it is ambiguous, strictly speaking.

So forbid it, and force the programmer to explicitly specify signed or 
unsigned, every single time. It would be better and cleaner.
March 17, 2009
Re: eliminate writeln et comp?
Ary Borenszweig wrote:
> Andrei Alexandrescu wrote:
>> Hey all y'all,
>>
>>
>> Here's another nice bicycle shed discussion. During the recent 
>> discussion about globals being harmful, Walter told me something that 
>> made me think. I said, hey, there are things that are global - look at 
>> stdout. He said, well, that's a bad thing. He then argued that it 
>> would be better and cleaner to write:
>>
>> stdout.writeln("Hello, world");
>>
>> instead of the current:
>>
>> writeln("Hello, world");
>>
>> On one hand, I agree with Walter. On the other, I want to avoid the 
>> phenomenon of the all-too-long "Hello, world" example.
>>
>> What do you think?
> 
> There must be something I'm missing here. Either writeln is using a 
> global "stdout" which you can't see in it's interface, or you are using 
> that global "stdout" yourself and invoking writeln on it. There's still 
> a global around. Nothing solved.

The difference is that in the current call the use of the global is 
implicit.

Andrei
March 17, 2009
Re: eliminate writeln et comp?
Sean Kelly wrote:
> Andrei Alexandrescu wrote:
>> Hey all y'all,
>>
>>
>> Here's another nice bicycle shed discussion. During the recent 
>> discussion about globals being harmful, Walter told me something that 
>> made me think. I said, hey, there are things that are global - look at 
>> stdout. He said, well, that's a bad thing. He then argued that it 
>> would be better and cleaner to write:
>>
>> stdout.writeln("Hello, world");
> 
> But then stdout is still global :-)  However, I do think an "fwritef" 
> routine would be good to have--I tend to write to stderr as often as 
> stdout.

Yah, there is in the elusive new Phobos which I still can't release due 
to compiler bugs:

auto f = File("foo.txt", "w");
f.writef("%s", 42);


Andrei
March 17, 2009
Re: eliminate writeln et comp?
Jarrett Billingsley wrote:
> On Tue, Mar 17, 2009 at 11:35 AM, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org> wrote:
>> Hey all y'all,
>>
>>
>> Here's another nice bicycle shed discussion. During the recent discussion
>> about globals being harmful, Walter told me something that made me think. I
>> said, hey, there are things that are global - look at stdout. He said, well,
>> that's a bad thing. He then argued that it would be better and cleaner to
>> write:
>>
>> stdout.writeln("Hello, world");
>>
>> instead of the current:
>>
>> writeln("Hello, world");
>>
>> On one hand, I agree with Walter. On the other, I want to avoid the
>> phenomenon of the all-too-long "Hello, world" example.
>>
>> What do you think?
> 
> Keep writefln.  You're only going to be using it when (1) you're doing
> debugging, when you want it short, and (2) you're writing a simple
> console program.  There's always dout.writefln when you need more
> power.

Is dout in the std.stream thing? That entire framework is due for 
retirement.

Andrei
March 17, 2009
Re: eliminate writeln et comp?
Max Samukha wrote:
> On Tue, 17 Mar 2009 08:56:58 -0700, Sean Kelly
> <sean@invisibleduck.org> wrote:
> 
>> Andrei Alexandrescu wrote:
>>> Hey all y'all,
>>>
>>>
>>> Here's another nice bicycle shed discussion. During the recent 
>>> discussion about globals being harmful, Walter told me something that 
>>> made me think. I said, hey, there are things that are global - look at 
>>> stdout. He said, well, that's a bad thing. He then argued that it would 
>>> be better and cleaner to write:
>>>
>>> stdout.writeln("Hello, world");
>> But then stdout is still global :-)  However, I do think an "fwritef" 
>> routine would be good to have--I tend to write to stderr as often as stdout.
> 
> writef recognizes if its first parameter is a stream. you can already
> use writef(stderr, ...)

(Not in the upcoming Phobos.)


Andrei
March 17, 2009
Re: eliminate writeln et comp?
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article
> Ary Borenszweig wrote:
> > Andrei Alexandrescu wrote:
> >> Hey all y'all,
> >>
> >>
> >> Here's another nice bicycle shed discussion. During the recent
> >> discussion about globals being harmful, Walter told me something that
> >> made me think. I said, hey, there are things that are global - look at
> >> stdout. He said, well, that's a bad thing. He then argued that it
> >> would be better and cleaner to write:
> >>
> >> stdout.writeln("Hello, world");
> >>
> >> instead of the current:
> >>
> >> writeln("Hello, world");
> >>
> >> On one hand, I agree with Walter. On the other, I want to avoid the
> >> phenomenon of the all-too-long "Hello, world" example.
> >>
> >> What do you think?
> >
> > There must be something I'm missing here. Either writeln is using a
> > global "stdout" which you can't see in it's interface, or you are using
> > that global "stdout" yourself and invoking writeln on it. There's still
> > a global around. Nothing solved.
> The difference is that in the current call the use of the global is
> implicit.

Once D will accept both syntaxes for methods, it will be up to the user.

void fn( t1 p1, t2, p2 );
fn( v1, v2 ); <-> v1.fn( v2 );
March 17, 2009
Re: eliminate writeln et comp?
Georg Wrede wrote:
> Andrei Alexandrescu wrote:
>> Hey all y'all,
>>
>>
>> Here's another nice bicycle shed discussion. During the recent 
>> discussion about globals being harmful, Walter told me something that 
>> made me think. I said, hey, there are things that are global - look at 
>> stdout. He said, well, that's a bad thing. He then argued that it 
>> would be better and cleaner to write:
>>
>> stdout.writeln("Hello, world");
>>
>> instead of the current:
>>
>> writeln("Hello, world");
>>
>> On one hand, I agree with Walter. On the other, I want to avoid the 
>> phenomenon of the all-too-long "Hello, world" example.
>>
>> What do you think?
> 
> 1. It is not often that a program that is first designed to write to 
> stdout is changed to write to somewhere else. (The whole reason of 
> stdout is, after all, that you can redirect outside the program!)
> 
> 2. Of course it would be Proper (as in Prudent, almost as in goody 
> two-shoes) to write stdout.writeln. But then, to be useful the 
> programmer should write myOutDestination.writeln in order to be able to 
> "conveniently" later change the destination.
> 
> 3. IMHO later redefining stdout would be a moronic idea. (And 
> /definitely/ not Prudent!)
> 
> 4. Globals, shmobals... globals in spirit vs. globals in techicality. I 
> can't /believe/ there's any idea in totally banning globals. Heck, this 
> language has *goto*. Blind purism has made a few other languages 
> impractical.
> 
> 5. Good defaults a good UI make. Can't we just decide that a bare 
> writeln(...) is defined as writing to stdout, period? Without thinking 
> of globals.
> 
> 6. stdout is "global" to such an extent, that it actually exists outside 
> of the program. (RTF *nix man, man!)
> 
> Blehhhhhhh....
> 
> PS, I don't think you were serious with the post.

I was, serious and especially curious. I'm with you on all of the above.

Andrei
March 17, 2009
Re: eliminate writeln et comp?
Andrei Alexandrescu wrote:
> Georg Wrede wrote:
>> Andrei Alexandrescu wrote:
>>> Hey all y'all,
>>>
>>>
>>> Here's another nice bicycle shed discussion. During the recent 
>>> discussion about globals being harmful, Walter told me something that 
>>> made me think. I said, hey, there are things that are global - look 
>>> at stdout. He said, well, that's a bad thing. He then argued that it 
>>> would be better and cleaner to write:
>>>
>>> stdout.writeln("Hello, world");
>>>
>>> instead of the current:
>>>
>>> writeln("Hello, world");
>>>
>>> On one hand, I agree with Walter. On the other, I want to avoid the 
>>> phenomenon of the all-too-long "Hello, world" example.
>>>
>>> What do you think?
>>
>> 1. It is not often that a program that is first designed to write to 
>> stdout is changed to write to somewhere else. (The whole reason of 
>> stdout is, after all, that you can redirect outside the program!)
>>
>> 2. Of course it would be Proper (as in Prudent, almost as in goody 
>> two-shoes) to write stdout.writeln. But then, to be useful the 
>> programmer should write myOutDestination.writeln in order to be able 
>> to "conveniently" later change the destination.
>>
>> 3. IMHO later redefining stdout would be a moronic idea. (And 
>> /definitely/ not Prudent!)
>>
>> 4. Globals, shmobals... globals in spirit vs. globals in techicality. 
>> I can't /believe/ there's any idea in totally banning globals. Heck, 
>> this language has *goto*. Blind purism has made a few other languages 
>> impractical.
>>
>> 5. Good defaults a good UI make. Can't we just decide that a bare 
>> writeln(...) is defined as writing to stdout, period? Without thinking 
>> of globals.
>>
>> 6. stdout is "global" to such an extent, that it actually exists 
>> outside of the program. (RTF *nix man, man!)
>>
>> Blehhhhhhh....
>>
>> PS, I don't think you were serious with the post.
> 
> I was, serious and especially curious. I'm with you on all of the above.

:-)
March 17, 2009
Re: eliminate writeln et comp?
On Tue, 17 Mar 2009 19:46:37 +0300, Nick Sabalausky <a@a.a> wrote:

> "Adam D. Ruppe" <destructionator@gmail.com> wrote in message
> news:mailman.967.1237304767.22690.digitalmars-d@puremagic.com...
>> On Tue, Mar 17, 2009 at 08:35:35AM -0700, Andrei Alexandrescu wrote:
>>> What do you think?
>>
>> Eeek. That's too much typing for a trivial, common operation.
>>
>> I wouldn't mind writefln being implemented as a macro that is turned to
>> fwritefln(stdout, ...)
>>
>> But, I'd be fairly annoyed having to write the extra seven characters  
>> each
>> time if the short version wasn't there.
>>
>
> That's how tango and C# do it.
>
> Stdout.formatln("Hello"); // Tango
> Console.WriteLine("Hello"); // C#
>
> My preference has always been for something shorter, but the current
> tango/C# ways have never really bothered me. You get used to it pretty
> quick.
>
>

That's not a very frequent operation. In most cases you should use Cout("Hello"); instead. An ideal design solution, imo (fast, short and clear).

Back on topic, in most cases I use:

debug writefln("hello");

because I have no console in release version (and it throws when there is no stdout, look in the bugzilla for a bug report). It is already long enough, so I wouldn't like it to be even longer:

debug stdio.writefln("hello");

My 0.02 rubles.
1 2 3 4 5 6
Top | Discussion index | About this forum | D home