Jump to page: 1 210  
Page
Thread overview
syntax sugar: std.path::buildPath instead of from!"std.path".buildPath
Feb 14, 2017
Timothee Cour
Feb 14, 2017
Jack Stouffer
Feb 14, 2017
Timothee Cour
Feb 14, 2017
Timothee Cour
Feb 14, 2017
Walter Bright
Feb 14, 2017
Chris M
Feb 14, 2017
Timothee Cour
Feb 14, 2017
Jacob Carlborg
Feb 14, 2017
Daniel N
Feb 14, 2017
Jonathan M Davis
Feb 14, 2017
Sebastiaan Koppe
Feb 14, 2017
Meta
Feb 14, 2017
Jacob Carlborg
Feb 14, 2017
bachmeier
Feb 14, 2017
bachmeier
Feb 14, 2017
H. S. Teoh
Feb 14, 2017
bachmeier
Feb 14, 2017
Jack Stouffer
Feb 14, 2017
Adam D. Ruppe
Feb 14, 2017
bachmeier
Feb 15, 2017
Chris Wright
Feb 15, 2017
bachmeier
Feb 14, 2017
Walter Bright
Feb 14, 2017
Walter Bright
Feb 14, 2017
H. S. Teoh
Feb 14, 2017
Walter Bright
Feb 15, 2017
Jack Stouffer
Feb 15, 2017
Adam D. Ruppe
Feb 15, 2017
Jacob Carlborg
Feb 15, 2017
Chris Wright
Feb 15, 2017
Adam D. Ruppe
Feb 15, 2017
Adam D. Ruppe
Feb 15, 2017
Seb
Feb 15, 2017
Adam D. Ruppe
Feb 15, 2017
Seb
Feb 15, 2017
Walter Bright
Feb 15, 2017
Jonathan M Davis
Feb 15, 2017
Jack Stouffer
Feb 15, 2017
Walter Bright
Feb 15, 2017
Jonathan M Davis
Feb 15, 2017
Walter Bright
Feb 15, 2017
H. S. Teoh
Feb 16, 2017
Walter Bright
Feb 16, 2017
Atila Neves
Feb 22, 2017
Atila Neves
Feb 15, 2017
Walter Bright
Feb 15, 2017
Jacob Carlborg
Feb 15, 2017
Daniel N
Feb 15, 2017
Daniel N
Feb 15, 2017
Timothee Cour
Feb 15, 2017
Nick Treleaven
Feb 17, 2017
timotheecour
Feb 17, 2017
Nick Treleaven
Feb 19, 2017
Timothee Cour
Feb 21, 2017
Nick Treleaven
Feb 15, 2017
Walter Bright
Feb 16, 2017
John Colvin
Feb 16, 2017
Jacob Carlborg
Feb 16, 2017
ZombineDev
Feb 16, 2017
ZombineDev
Feb 16, 2017
Daniel Nielsen
Feb 15, 2017
Chris Wright
May 23, 2017
Martin Nowak
Feb 14, 2017
Lurker
Feb 15, 2017
Chris Wright
Feb 15, 2017
Jacob Carlborg
Feb 15, 2017
Jack Stouffer
Feb 15, 2017
Jacob Carlborg
Feb 15, 2017
Jonathan M Davis
Feb 16, 2017
Walter Bright
Feb 16, 2017
ZombineDev
Feb 16, 2017
John Colvin
Feb 16, 2017
Jacob Carlborg
Feb 16, 2017
ZombineDev
Feb 15, 2017
Jack Stouffer
Feb 15, 2017
Jonathan M Davis
Feb 15, 2017
Jacob Carlborg
Feb 15, 2017
Atila Neves
Feb 14, 2017
Jack Stouffer
Feb 14, 2017
Jonathan M Davis
Feb 14, 2017
kinke
Feb 14, 2017
Jack Stouffer
Feb 14, 2017
Johannes Pfau
Feb 14, 2017
Daniel N
Feb 14, 2017
Daniel N
Feb 14, 2017
Johannes Pfau
Feb 14, 2017
Daniel Kozak
February 13, 2017
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.


February 14, 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.
February 13, 2017
> 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.

indeed. But just because something can be done in library code doesn't mean
it should. Same exact rationale for:
`lazy`, `=>`, scope(exit), etc. All of these coul've been done in pure
library code, but the syntax sugar makes them particularly easy to use.
Syntax sugar should be used sparingly, but it makes sense if

* it simplifies syntax compared to best possible library code * it's for a common use case



On Mon, Feb 13, 2017 at 9:03 PM, Jack Stouffer via Digitalmars-d < digitalmars-d@puremagic.com> wrote:

> 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.
>


February 13, 2017
as for language change, I believe the proposed syntax (`::`) can be reduced to a minimum if we we make `fullyqualifiedName` `::` a reduction to the from/Module inline import idiom. No complex corner case or new bug introduced, it could be done as a pure AST transformation


On Mon, Feb 13, 2017 at 9:32 PM, Timothee Cour <thelastmammoth@gmail.com> wrote:

> > 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.
>
> indeed. But just because something can be done in library code doesn't
> mean it should. Same exact rationale for:
> `lazy`, `=>`, scope(exit), etc. All of these coul've been done in pure
> library code, but the syntax sugar makes them particularly easy to use.
> Syntax sugar should be used sparingly, but it makes sense if
>
> * it simplifies syntax compared to best possible library code * it's for a common use case
>
>
>
> On Mon, Feb 13, 2017 at 9:03 PM, Jack Stouffer via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
>
>> 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.
>>
>
>


February 14, 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.

Well, as Jack said there's no real clean way to do this without cluttering the function signatures more. However if this does happen through a language change, :: would look kind of awkward imo. I'd go with the following idea instead.

void fun(T)(#std.stdio.File input, T value)
if (#std.traits.isIntegral!T)
{...}

Doesn't necessarily have to be the octothorpe, but I think it looks a bit cleaner.
February 13, 2017
`#std.stdio.File` doesn't work, we don't know where is the module
separator:
that could mean `module std` with a class stdio with a field File.

so the syntax would have be:

`std.stdio SYMBOL File`

frankly I don't care which symbol, so long it looks like that. And as I said, `std.stdio::File` is reasonable since it's used for similar purpose in rust and C++



On Mon, Feb 13, 2017 at 10:21 PM, Chris M via Digitalmars-d < digitalmars-d@puremagic.com> wrote:

> 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.
>>
>
> Well, as Jack said there's no real clean way to do this without cluttering the function signatures more. However if this does happen through a language change, :: would look kind of awkward imo. I'd go with the following idea instead.
>
> void fun(T)(#std.stdio.File input, T value)
> if (#std.traits.isIntegral!T)
> {...}
>
> Doesn't necessarily have to be the octothorpe, but I think it looks a bit cleaner.
>


February 14, 2017
Please fix your newsreader client to send as text, not as html.

The html is both excessively large, and has randomly changing fonts embedded in it.
February 14, 2017
On 2017-02-14 04:49, Timothee Cour via Digitalmars-d 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

Why? It looks awful. The signatures we already have in Phobos is quite ridiculous, this will not improve. Isn't this and the whole idea of DIP 1005 just a workaround for the compiler not lazily analyzing the symbols.

-- 
/Jacob Carlborg
February 14, 2017
On Tuesday, 14 February 2017 at 09:55:51 UTC, Jacob Carlborg wrote:
>
> Why? It looks awful. The signatures we already have in Phobos is quite ridiculous, this will not improve. Isn't this and the whole idea of DIP 1005 just a workaround for the compiler not lazily analyzing the symbols.

Even those of you who favor...
with(import std.stdio)

... wouldn't you agree that this is better?
with(Module!"std.stdio")

Less intrusive compiler change because the same syntax already works everywhere "with" is valid.

February 14, 2017
Am Mon, 13 Feb 2017 19:49:28 -0800
schrieb Timothee Cour via Digitalmars-d <digitalmars-d@puremagic.com>:

> 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) {...}
> ```

If you use a single ':' instead you can argue it's simply a shortened, inline version of a selective import:

import std.stdio : File;
//still valid D
import std.stdio:File;
//expression instead of statement => remove ;
import std.stdio:File
//We're not importing a symbol, we're simply referring to it
std.stdio:File

-- Johannes

« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10