December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #10 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-07 07:54:45 PST ---
https://github.com/D-Programming-Language/dmd/pull/1356

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #11 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-07 10:39:02 PST ---
(In reply to comment #0)
> So I'd like to propose new syntax to reduce such concept confusion.
> 
> int n = int(10);  // same as cast(int)10;

So we're introducing C++-style casts into D? This means you can no longer search for 'cast' and expect to find all the unsafe casts in your code. I'm very much against this, and if I remember right Walter was also against this.

> From the meta-programming view, we can represent default construction of value
> types by T().

We can also use a library template to do it without introducing new syntax. If orthogonality is needed because of metaprogramming then why not just implement a template in Phobos?

We really don't need 10 ways of doing the same thing with a different syntax..

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #12 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-07 10:41:09 PST ---
(In reply to comment #9)
> (In reply to comment #1)
> > This is useful in generic code:
> > int n = int(10);
> 
> EXTREMELY useful. Just the other day, I was writing a unittest to cover
> appender with as many types as possible, and wanted to write something along
> the lines of:
>             app1.put(S(i)); // HERE

There:
              app1.put(DefInit!S(i));

No need to introduce new syntax because of a small issue like that.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #13 from monarchdodra@gmail.com 2012-12-07 10:55:13 PST ---
(In reply to comment #11)
> (In reply to comment #0)
> > So I'd like to propose new syntax to reduce such concept confusion.
> > 
> > int n = int(10);  // same as cast(int)10;
> 
> So we're introducing C++-style casts into D? This means you can no longer search for 'cast' and expect to find all the unsafe casts in your code. I'm very much against this, and if I remember right Walter was also against this.
> 

AFAIK, it's not exactly the same thing, as int(10) would be only a constructor, so would not downcast.

Writing:
//----
void foo(long k)
{
  int n = int(k);
}
//----

Would fail to compile the same way as:

//----
void foo(long k)
{
  int n = k;
}
//----

would. You'd need to use:

//----
void foo(long k)
{
  int n = int(cast(int)k);
}
//----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #14 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-12-07 10:57:47 PST ---
> So we're introducing C++-style casts into D? This means you can no longer search for 'cast' and expect to find all the unsafe casts in your code. I'm very much against this, and if I remember right Walter was also against this.

I'd actually argue for making it so that no explict casting is involved. It could be restricted to cases where

T var = literal;

and

T var = T(literal);

would be identical. So, stuff like ubyte(12345) would be illegal whereas cast(ubyte)12345 would be legal. It then looks like a C++ cast but isn't. It solves the problem with generic code without causing any issues you get with casts.

> We can also use a library template to do it without introducing new syntax. If orthogonality is needed because of metaprogramming then why not just implement a template in Phobos?

I tried that. Andrei rejected it, and it's not worth my time to fight him over it. Not to mention, I've always thought that

auto i = new int(7);
auto j = new immutable(int)(5);

should be legal and think that having to do something like makeNew!int(7) is a bit of a hack anyway, since it's specifically working around a deficiency in the language.

> We really don't need 10 ways of doing the same thing with a different syntax..

The whole point of this is to try and make things more consistent, not less.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #15 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-12-07 10:59:34 PST ---
> AFAIK, it's not exactly the same thing, as int(10) would be only a constructor, so would not downcast.

I agree, but if you look at Kenji's proposal, he specifically says that there's a cast involved (which I'd missed when I read it the first time). So, Andrej's complaint is completely valid given Kenji's initial proposal. But if you fix it so that no cast is involved, then I think that it's fine.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #16 from monarchdodra@gmail.com 2012-12-07 12:20:03 PST ---
(In reply to comment #15)
> > AFAIK, it's not exactly the same thing, as int(10) would be only a constructor, so would not downcast.
> 
> I agree, but if you look at Kenji's proposal, he specifically says that there's a cast involved (which I'd missed when I read it the first time). So, Andrej's complaint is completely valid given Kenji's initial proposal. But if you fix it so that no cast is involved, then I think that it's fine.

I'm just wondering if that's *actually* what's going on, or if Kenji just accidentally miss-commented it that way.

I don't know how to read compiler code, so I wouldn't know what he actually did. It'd be nice if he did deliver a fail_compile checking this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #17 from bearophile_hugs@eml.cc 2012-12-07 14:33:35 PST ---
The pull request was closed hours ago: https://github.com/D-Programming-Language/dmd/pull/1356

Do you know where are the comments that have made Hara close it?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 11, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #18 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-11 05:01:27 PST ---
(In reply to comment #16)
> (In reply to comment #15)
> > > AFAIK, it's not exactly the same thing, as int(10) would be only a constructor, so would not downcast.
> > 
> > I agree, but if you look at Kenji's proposal, he specifically says that there's a cast involved (which I'd missed when I read it the first time). So, Andrej's complaint is completely valid given Kenji's initial proposal. But if you fix it so that no cast is involved, then I think that it's fine.
> 
> I'm just wondering if that's *actually* what's going on, or if Kenji just accidentally miss-commented it that way.
> 
> I don't know how to read compiler code, so I wouldn't know what he actually did. It'd be nice if he did deliver a fail_compile checking this.

You pointed out is correct.

At first, I had considered that int(10) should be translated to cast(int)10.
But, while implementing pull, I had discovered the incorrect cast would occur
much easily.

So now, the posted pull doesn't implement int(10) as a cast, and the syntax accepts only a value which implicitly convertible to int.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 11, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #19 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-11 05:03:33 PST ---
(In reply to comment #17)
> The pull request was closed hours ago: https://github.com/D-Programming-Language/dmd/pull/1356
> 
> Do you know where are the comments that have made Hara close it?

Sorry, I had temporarily closed it so auto tester result had been broken in
64bit platforms.
After fixing test cases, I reopened that.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------