March 17, 2009
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?


Andrei
March 17, 2009
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.


> Andrei

-- 
Adam D. Ruppe
http://arsdnet.net
March 17, 2009
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.
March 17, 2009
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.
March 17, 2009
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.
March 17, 2009
"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.


March 17, 2009
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, ...)
March 17, 2009
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article
> 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?
> Andrei

To me, the current form is best because it doesn't force you to explicitly specify that you want to write to stdout.  Thus, it makes simple things simple.  Of course DWIM isn't always a good idea, but when an obvious, safe default exists, I prefer not to have to explicitly specify this kind of stuff unless I want to override the default.

Also, I don't see globals as being all that evil in themselves.  Global _mutable_ state is an absolute mortal sin, but I see absolutely nothing wrong with global variables that are immutable, or even set once and treated as read-only by convention after initialization.
March 17, 2009
Andrei Alexandrescu wrote:

> 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");

I thought the current was printf :-)

Looking at dmd/samples/d/hello.d

--anders
March 17, 2009
Anders F Björklund wrote:
> Andrei Alexandrescu wrote:
> 
>> 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");
> 
> I thought the current was printf :-)
> 
> Looking at dmd/samples/d/hello.d

LOL
« First   ‹ Prev
1 2 3 4 5 6
Top | Discussion index | About this forum | D home