syntax sugar: std.path::buildPath instead of from!"std.path".buildPath

Jack Stouffer via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 13 21:03:07 PST 2017


On Tuesday, 14 February 2017 at 03:49:28 UTC, Timothee Cour wrote:
> What about allowing syntax sugar as an alternative to relying 
> on the new `from/Module` inline import idiom:
>
> ```
> void fun(T)(std.stdio::File input, T value) if 
> (std.traits::isIntegral!T)
> {...}
> ```
>
> instead of:
>
> ```
> void fun(T)(Module!"std.stdio".File input, T value) if
> (Module!"std.traits".isIntegral!T) {...}
> ```
>
> Rationale:
>
> * this reads much better (less noise); same as `=>` syntax for 
> lambdas
>
> * this is expected to be a very common pattern, so might as 
> well make it as simple as possible
>
> * not particular on which symbol is used, could be something 
> else, so long it doesn't involve writing a string such as 
> from!"std.traits". But :: will be familiar to those coming from 
> C++/rust etc.
>
> * from!"" is too loose and can be abused arbitrarily:
>
> ```
> // this compiles
> void fun(){
>   from!"std.stdio; pragma(msg,`abuse...`); import 
> std.stdio".File a;
> }
> ```
>
> Furthermore this is useful in other scenarios, namely when an 
> import is
> used only once in a context:
> ```
> auto fun(){  return std.file::getcwd; }
> ```
> is more DRY; instead of:
> ```
> auto fun(){ static import std.file;  return std.file.getcwd; }
> auto fun(){ return Module!"std.file".getcwd; }
> ```
>
> NOTE: if :: is not feasible for whatever reason, let's consider 
> other symbols without prejudice to this proposal.

The only thing from has going for it is that it doesn't require a 
language change. Yours does, so it should be compared to the 
proposals in DIP1005 and not just from.

TBQH all the the proposed syntaxes for the DIP1005 problem kind 
of suck, because at the end of the day there's no good way to 
solve the problem.

Every proposed solution either

1. Looks terrible (and some people highly underestimate the cost 
of a language looking bad), or
2. Complicate our already complex function definitions even 
further. How is a beginner not going to look at this and feel 
like barfing

with (import std.datetime, std.range.primitives) void 
fun(R)(scope R r, const ref Systime value) if (isInputRange!R && 
!isFinite!R)  { ... }

But, I'm still of the opinion that the `with` syntax is currently 
the best proposal. Others have already shown the weaknesses of 
the `from!` approach.


More information about the Digitalmars-d mailing list