mail-archives/mono-list/2003-October/016483.html

159 строки
6.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Mono-list] implicit, explicit, and why does C# have these?
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:dlamotta%40email.com">
<META NAME="robots" CONTENT="index,nofollow">
<LINK REL="Previous" HREF="016482.html">
<LINK REL="Next" HREF="016486.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Mono-list] implicit, explicit, and why does C# have these?
</H1>
<B>David La Motta
</B>
<A HREF="mailto:dlamotta%40email.com"
TITLE="[Mono-list] implicit, explicit, and why does C# have these?">dlamotta@email.com
</A><BR>
<I>Fri, 17 Oct 2003 09:56:08 -0400</I>
<P><UL>
<LI> Previous message: <A HREF="016482.html">[Mono-list] implicit, explicit, and why does C# have these?
</A></li>
<LI> Next message: <A HREF="016486.html">[Mono-list] implicit, explicit, and why does C# have these?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#16483">[ date ]</a>
<a href="thread.html#16483">[ thread ]</a>
<a href="subject.html#16483">[ subject ]</a>
<a href="author.html#16483">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>This is a multi-part message in MIME format.
--------------070101010801090009040807
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
I guess I should expand on my [sort-of] gripe. Implicit casting by the
language itself is OK where it makes sense, like in your example of int
and long. But, logically, it can be confusing to use an implicit
operator to convert between objects that have nothing in common, and
never will (like Truck and Pear, for instance).
// David
Arild Fines wrote:
&gt;<i>David La Motta wrote:
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;&gt;<i>Thanks for the explanation. I can see how the implicit operator can
</I>&gt;&gt;<i>be useful in the example you describe; still, I think it wasn't
</I>&gt;&gt;<i>necessary for C# to expose them to us. I.e., let us deal with the
</I>&gt;&gt;<i>explicit casts and spare the confusion they may cause. In other
</I>&gt;&gt;<i>words, an implicit cast from a Pear object to a Truck object can seem
</I>&gt;&gt;<i>quite odd, assuming their inheritance tree has nothing in common.
</I>&gt;&gt;<i>
</I>&gt;&gt;<i>
</I>&gt;<i>
</I>&gt;<i>Sure, but would you really want to be required to use an explicit cast when
</I>&gt;<i>converting an int to a long?
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i>--
</I>&gt;<i>Arild
</I>&gt;<i>
</I>&gt;<i>AnkhSVN: <A HREF="http://ankhsvn.tigris.org">http://ankhsvn.tigris.org</A>
</I>&gt;<i>Blog: <A HREF="http://ankhsvn.com/blog">http://ankhsvn.com/blog</A>
</I>&gt;<i>RSS: <A HREF="http://ankhsvn.com/blog/Rss.aspx">http://ankhsvn.com/blog/Rss.aspx</A>
</I>&gt;<i>
</I>&gt;<i>King Crimson lives in different bodies at different times and the
</I>&gt;<i>particular form which the group takes changes. When music appears,
</I>&gt;<i>which only King Crimson can play then, sooner or later, King Crimson
</I>&gt;<i>appears to play the music
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i>
</I>
--------------070101010801090009040807
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=ISO-8859-1&quot;&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body text=&quot;#000000&quot; bgcolor=&quot;#ffffff&quot;&gt;
I guess I should expand on my [sort-of] gripe.&amp;nbsp; Implicit casting by the
language itself is OK where it makes sense, like in your example of int
and long.&amp;nbsp; But, logically, it can be confusing to use an implicit
operator to convert between objects that have nothing in common, and
never will (like Truck and Pear, for instance).&lt;br&gt;
&lt;br&gt;
// David&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Arild Fines wrote:&lt;br&gt;
&lt;blockquote type=&quot;cite&quot;
cite=&quot;<A HREF="mailto:midAJEELJINGEGOMNJPJFKKCEIEDCAA.arild.fines@broadpark.no">midAJEELJINGEGOMNJPJFKKCEIEDCAA.arild.fines@broadpark.no</A>&quot;&gt;
&lt;pre wrap=&quot;&quot;&gt;David La Motta wrote:
&lt;/pre&gt;
&lt;blockquote type=&quot;cite&quot;&gt;
&lt;pre wrap=&quot;&quot;&gt;Thanks for the explanation. I can see how the implicit operator can
be useful in the example you describe; still, I think it wasn't
necessary for C# to expose them to us. I.e., let us deal with the
explicit casts and spare the confusion they may cause. In other
words, an implicit cast from a Pear object to a Truck object can seem
quite odd, assuming their inheritance tree has nothing in common.
&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre wrap=&quot;&quot;&gt;&lt;!----&gt;
Sure, but would you really want to be required to use an explicit cast when
converting an int to a long?
--
Arild
AnkhSVN: &lt;a class=&quot;moz-txt-link-freetext&quot; href=&quot;<A HREF="http://ankhsvn.tigris.org"">http://ankhsvn.tigris.org&quot;</A>&gt;<A HREF="http://ankhsvn.tigris.org</a">http://ankhsvn.tigris.org&lt;/a</A>&gt;
Blog: &lt;a class=&quot;moz-txt-link-freetext&quot; href=&quot;<A HREF="http://ankhsvn.com/blog"">http://ankhsvn.com/blog&quot;</A>&gt;<A HREF="http://ankhsvn.com/blog</a">http://ankhsvn.com/blog&lt;/a</A>&gt;
RSS: &lt;a class=&quot;moz-txt-link-freetext&quot; href=&quot;<A HREF="http://ankhsvn.com/blog/Rss.aspx"">http://ankhsvn.com/blog/Rss.aspx&quot;</A>&gt;<A HREF="http://ankhsvn.com/blog/Rss.aspx</a">http://ankhsvn.com/blog/Rss.aspx&lt;/a</A>&gt;
King Crimson lives in different bodies at different times and the
particular form which the group takes changes. When music appears,
which only King Crimson can play then, sooner or later, King Crimson
appears to play the music
&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;/body&gt;
&lt;/html&gt;
--------------070101010801090009040807--
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI> Previous message: <A HREF="016482.html">[Mono-list] implicit, explicit, and why does C# have these?
</A></li>
<LI> Next message: <A HREF="016486.html">[Mono-list] implicit, explicit, and why does C# have these?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#16483">[ date ]</a>
<a href="thread.html#16483">[ thread ]</a>
<a href="subject.html#16483">[ subject ]</a>
<a href="author.html#16483">[ author ]</a>
</LI>
</UL>
</body></html>