Re: Boxing and Unboxing ??
- From: "Peter Olcott" <NoSpam@xxxxxxxxxxxxx>
- Date: Mon, 15 Jan 2007 10:18:03 -0600
"Barry Kelly" <barry.j.kelly@xxxxxxxxx> wrote in message
news:2j9lq25hh906rrb4comdk05pdtgnjo4qsp@xxxxxxxxxx
Peter Olcott wrote:
"Barry Kelly" <barry.j.kelly@xxxxxxxxx> wrote:
Which programmer are you talking about:
1) The guy instantiating types and calling methods? If the types are
well-designed, this guy typically doesn't need to know already.
1) The guy writing types and methods? This is the guy who needs to make
the choice, so unless the two become semantically identical, he needs to
know the difference. And if you're suggesting some kind of semantic
fusion, then you'll need to be a whole lot more specific about what
you're talking about.
There are programmers that only call methods and never write methods? That
seems
like quite a stretch. Where do they put the code that calls the methods, if
not
in another method?
There are two 'hats' for a programmer: programmer as User of types, and
programmer as Designer of types. It's useful to distinguish between
them, because they require two different ways of thinking. The User of
types solves algorithmic problems based on the spec / purpose of the
method whose body they're writing. The Designer of types creates
abstractions to model a problem or domain, but the primary purpose is to
simplify the job of the guy who Uses the types that he / she is
creating.
You need to expand much more on what you're talking about, with
precision and detail, and give example code.
int SomeMethod(in SomeType SomeName) // C#
Exactly Equals
int SomeMethod(const SomeType& SomeName) // C++
What if SomeType is a reference type? If you're suggesting full C++
semantics for a deeper notion of const than simply 'pass value types by
reference for performance reasons', then I'll direct you to Anders
Hejlsberg's opinions on the matter. For example read this:
http://www.artima.com/intv/choicesP.html
There is no useful distinction between [ref] and [out].
I disagree. 'ref' means 'modify this location', while 'out' means
'return into this location'. 'out' is a mechanism to get around the fact
that C# can't return tuples. 'ref' is a means of passing by reference.
So then [ref] could be name [io] for input and output.
Unify [ref] and [out]
into [out], and add [in] as a read-only pass by address parameter qualifier.
The
CLR can be free to pass by value if it would be faster for very small items,
because on a read-only parameter there is no semantic difference.
Effectively (ISTM) the upshot of what you're asking for is a C++-style
'const &' for value types, to avoid boxing overhead when passing large
value types.
What many other people have been trying to tell you on this thread is:
1) Large value types aren't a good idea
2) Large value types don't even occur very often (e.g. arrays are
reference types, as you've found out)
3) Reference types are good, you should try them!
In fact, the primary advantage of value types is that they're usually
copied wherever they go, and thus reduce GC overhead.
Yet the language lacks the alternative capability even when it is needed.
Basically, you're suggesting a feature that wouldn't be used a lot.
It would only be used when one needs to pass aggregate data without wasting the
machine time of boxing and unboxing, or the programmer time of a user writing to
a parameter intended to be read-only. The case that I envision is something like
the C++ friend function, can't be a class member, yet requires direct access to
internal data. Good design minimizes these cases, yet can not eliminate these
cases.
Again, I think it wouldn't be harmful or anything, just not very useful.
-- Barry
--
http://barrkel.blogspot.com/
.
- References:
- Re: Boxing and Unboxing ??
- From: Arne Vajhøj
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- Prev by Date: Re: Enumerators that need to be changed at runtime, avoiding exception
- Next by Date: Where are the 'most often used program' shortcuts?
- Previous by thread: Re: Boxing and Unboxing ??
- Next by thread: Re: Boxing and Unboxing ??
- Index(es):
Relevant Pages
|