Re: Boxing and Unboxing ??

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"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/


.



Relevant Pages

  • Re: Boxing and Unboxing ??
    ... And if you're suggesting some kind of semantic ... There are two 'hats' for a programmer: programmer as User of types, ... semantics for a deeper notion of const than simply 'pass value types by ... Reference types are good, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Junit newbie
    ... > Is the general strategy to write trivial tests, boundary tests, and ... One strategy is to write tests until you don't feel like you're writing ... Another strategy is to imagine yourself as being a "lead programmer" to ... > test de/compressing some very large byte array (from a file 2GB file ...
    (comp.lang.java.help)
  • Re: C vs C++ in Embedded Systems?
    ... It's a language for the more skilled among us. ... >expertise should be required of the programmer. ... >Assembly code should require less expertise than writing ...
    (comp.arch.embedded)
  • Re: Boxing and Unboxing ??
    ... The price for the unified type model and additional expressive power ... Far from liberating the programmer from "having to worry about value ... versus reference types", C++ throws it right in your face and forces ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Boxing and Unboxing ??
    ... attention to the differences between value types and reference types. ... The act very differently: value types being... ... "improve programmer productivity". ... abstraction where programmers writing programs in this language never have any ...
    (microsoft.public.dotnet.languages.csharp)