So, to print or not to print?

Solomon E via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 26 14:11:22 PDT 2016


On Tuesday, 26 April 2016 at 20:01:34 UTC, Andrei Alexandrescu 
wrote:
> Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
>> https://github.com/dlang/phobos/pull/3971
>> 
>> Walter and I were talking this morning that there should be a 
>> high barrier of entry for one-liners in Phobos. The "print" 
>> function is technically a one-liner (i.e. writefln with the 
>> appropriate format string). On the other hand, it may be 
>> convivial enough to warrant inclusion, and saves us from 
>> embarrassing things such as producing meaningless output when 
>> numbers are printed together.
>> 
>> There's been a bit of churn in the PR comments regarding the 
>> utility of "print", and discussion diverged into other 
>> functions such as "dump" etc. Keeping it on topic: any strong 
>> cons and pros regarding the function? I want to either merge 
>> or close the PR and move on.
>> 
>> 
>> Thanks,
>> 
>> Andrei
>> 
>
> I closed the PR as too controversial. -- Andrei

I thought maybe std.adapt.Python.print would be a neat compromise 
(if there are Pythonistas who want to maintain that library 
module.) When I use Python, I often define my own output 
function, now with some influence from D on the behavior and 
naming it write. I've also defined convenience output functions 
named "print" in D, while I'm learning it. That's an argument 
against having Python style "print" except in a special 
adapt.Python module.

Then I was overwhelmed by how good the suggestion from tn was to 
have "writes" and "writesln" in D's set of "write" functions.

writesln(a, b); // I would expect does the same as
writefln("%s %s", a, b);

alias print = writesln!(separator="\t");
print(a, b); // now with tab separation

Comma for tab separation was a syntax built-in of 1964 BASIC, 
which was the most limited practical student programming language 
possible. I've implemented an interpreter of it in Python. It 
would be cool if it were easy for D beginners to write anything 
that could be written in 1964 BASIC.

As for "writes" looking like it might be a present tense verb or 
a plural noun: That's part of the beauty of it. It looks 
ambiguous and casual, like "puts" in Ruby, which helped and in no 
way hurt Ruby adoption, because superficially looking casual 
while actually having precise definitions behind the keywords is 
part of what makes scripting language style writing fun, and easy 
to write with imagination for many uses (rather than the language 
seeming to impose on the subject of the program.)

About one-liners in Phobos: If those one-liners help rewrite 
other features as one-liners, until everything is one-liners, 
bring on the monogram apocalypse.


More information about the Digitalmars-d mailing list