So, to print or not to print?

cym13 via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 25 13:18:19 PDT 2016


On Monday, 25 April 2016 at 19:35:04 UTC, Andrei Alexandrescu 
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

To be honnest I think it would add more confusion than anything 
for newcommers to have yet another printing function but the name 
is good and it is like python so it's easier for many.

I dislike some points of the API though, I think changing eol is 
more common than changing separator so I would rather have the 
two switched. Maybe even removed, replaced by a single switch 
"eol=true" as contrary to python we have more powerful formating 
functions at hand and I think restricting the domain of each 
function would prove better on the long run in order to keep 
consistency.

Also as the unittest shows it is hard to test a function that can 
only print to stdout which raises an orange flag in my mind: 
please, consider adding a way to supplant stdout. The best would 
be to make the unittest work:   file.print(i, i*i*i);  as it 
clearly comes from an natural expectation.


More information about the Digitalmars-d mailing list