October 13, 2020
On 10/13/2020 1:31 AM, Jacob Carlborg wrote:
> Then the compiler will be wrong in some of those cases. 

At some point it's necessary to just accept how it works, because the compiler cannot read your mind and cannot know with certainty your intent. If the compiler could always discern what you meant, it wouldn't need to issue an error message at all.

The spell checker is simple and is surprisingly effective, guessing right more than 50% of the time for me. The import hinter does even better.

If there's fault here, it is not in the checker or the hinter, it's in the choice of an extremely common word "to" in the library.
October 13, 2020
On 10/13/2020 12:14 AM, aberba wrote:
> I think making that list dynamic rather than hard coded might be it.

Not worth the complexity.
October 13, 2020
On 10/13/2020 1:08 AM, Jacob Carlborg wrote:
> Or with named arguments (which D doesn't support yet).

That is the solution, and D will.

> But unless you're using Swift or Objective-C, there's nothing that force you do use named arguments on the call site.

That's right, and we aren't going to add it. The facility of named arguments is there when people want to use it.
October 13, 2020
On Tuesday, 13 October 2020 at 08:31:34 UTC, Jacob Carlborg wrote:
> On Monday, 12 October 2020 at 20:46:07 UTC, Steven Schveighoffer wrote:
>
> auto too(T, U)(U value)
> {
>     return value;
> }
>
> void main()
> {
>     auto a = 3.to!string;
> }
>
> This will result in a compile error:
>
> Error: no property `to` for type `int`, perhaps `import std.conv;` is needed?
>
> Obviously I meant to call the function `too` in the same module. Not `std.conv.to`.
>

By revisiting the line of offending code, it would be immediately apparent as to what was intended—assuming, of course, that the person encountering the error is, in fact, the author of the code. The suggestion, therefore, is not entirely useless. I can easily infer from it what needs to be corrected. What would improve the situation is providing context along with the error message:

Error: no property `to` for type `int`, perhaps `import
std.conv;` is needed?

   auto a = 3.to!string;
              ^--------

October 13, 2020
On Monday, 12 October 2020 at 17:04:01 UTC, Ali Çehreli wrote:
> The unfortunate thing in the video was 'to' is not searchable on the internet and it took them a long time to figure out how to use a to!string expression. :/

When I try to search for “dlang to” in Google, the first result points to std.conv.to page. Their problem was that their queries looked like “dlang to template”, “dlang import to module” etc. Search engines are doing a good job at searching “unsearchable” things unless you pollute your query with irrelevant words.

Keywords like “to” and “yes” are perfectly fine. It’s not D’s fault that some people don’t know how to use the internet.
October 13, 2020
On 10/12/20 2:10 PM, Adam D. Ruppe wrote:
> On Monday, 12 October 2020 at 18:01:50 UTC, Paul Backus wrote:
>> Though for some reason std.conv.to is the 4th search result, after core.time.to, std.conv.castFrom.to, and (of all things) arsd.email.IncomingMessage.to.
> 
> It is arbitrary order since all of them get the same score due to all being an exact match of the given name.

Sort exact matches by "least nested" maybe?
October 13, 2020
On 10/12/20 3:35 PM, Walter Bright wrote:
> On 10/12/2020 10:04 AM, Ali Çehreli wrote:
>> Of course, a better thing would be to suggest importing std.conv like some other error messages do.
>>
>> The unfortunate thing in the video was 'to' is not searchable on the internet and it took them a long time to figure out how to use a to!string expression. :/
> 
> This is more of a naming problem. "to" as a major name in Phobos is always going to be hopelessly ungreppable.

git grep '\Wto!'

yields the uses.

git grep '\Wto('

yields the definitions.

> Though it could be added to the special list of names importHint().
> 
> "Yes" and "No" are also poor names, the latter is hopelessly ungreppable. Furthermore, they are just redundant to "true" and "false". They never should have been put in Phobos.

git grep '\WNo\.'

yields the uses.

Flag, Yes, and No were introduced to avoid this antipattern:

https://www.informit.com/articles/article.aspx?p=1392524

https://medium.com/@amlcurran/clean-code-the-curse-of-a-boolean-parameter-c237a830b7a3

https://understandlegacycode.com/blog/what-is-wrong-with-boolean-parameters/

October 13, 2020
On 10/12/20 4:08 PM, Walter Bright wrote:
> On 10/12/2020 11:10 AM, Adam D. Ruppe wrote:
>> I do need to write a new searcher though, it could be a lot better than it is right now.
> 
> There's nothing wrong with the search engine. There's a LOT wrong with global symbols named "to".

This is one of those cases I'm happy we can't change names.
October 13, 2020
On 10/12/20 8:36 PM, Walter Bright wrote:
> On 10/12/2020 4:52 PM, Steven Schveighoffer wrote:
>> I think we should change the name of that particular function, but I've never used it, so I don't know how disruptive that would be.
> 
> For std2021, there should be no 2 letter names.

"No".
October 13, 2020
On 10/13/20 4:31 AM, Jacob Carlborg wrote:
> On Monday, 12 October 2020 at 20:46:07 UTC, Steven Schveighoffer wrote:
> 
>> What do you mean? Just add "to" : "std.conv". Is there a problem with it?
> 
> It's already in the list [1], it's been there for two years. 

Wait, why doesn't it work?

void main()
{
    auto x = to!string(1);
}

onlineapp.d(3): Error: template instance to!string template to is not defined

> Unfortunately it's not that simple. The current implementation is a very simple mapping of a name to an import. What if there are multiple module level symbols with the same name in Phobos or druntime? Then the compiler will be wrong in some of those cases. Also, take this for example:
> 
> auto too(T, U)(U value)
> {
>      return value;
> }
> 
> void main()
> {
>      auto a = 3.to!string;
> }
> 
> This will result in a compile error:
> 
> Error: no property `to` for type `int`, perhaps `import std.conv;` is needed?

If you look at the "New to Dlang" stream, what happens is it says "Did you mean `No`?". So literally what you are asking for it to do (and it does do), causes about 30 minutes of fruitless searching. Whereas if it had said "perhaps `import std.conv;` is needed?", I think a more favorable review might have been the result.

I tested it some more.

1.to!string => Suggests import std.conv
to!string(1) => No template named to.

This seems like a bug to me.

-Steve