473,842 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Another C# critique

I have posted a C# critique at
http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up
the following issues :

- unsafe code
- attributes
- garbage collection
- non-deterministic destructors
- Objects can't exist on the stack
- Type / Reference Types
- Boxing / Unboxing
- Mutability
- Classes as Modules and Programs
- Polymorphism through Class Inheritance
- Interface Delegation
- Interface Extensions
- C# Missing Template Template Parameters
- Late Added Generics
- Source File Layout
- Public Fields
- Special Primitives
- Is it a Property or is it a field?
- Microsoft

I am perhaps guilty somewhat of being a flame baiting troll, but at the same
time I honestly want to improve on the critique.

Thanks in advance for your responses.

--
Christopher Diggins
yet another language designer
http://www.heron-language.com
Nov 15 '05
188 7282

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
>
> "Frans Bouma" <pe************ ******@xs4all.n l> wrote in message
> news:Xn******** *************** **********@207. 46.248.16...
> > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in > > news:#5******** ******@tk2msftn gp13.phx.gbl:
> > > "Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
> > > news:MP******** *************** @msnews.microso ft.com...
<snip>

> > The reason const isn't part of the language is, if I understood > > Gunnerson correctly, that interop with other languages is then a
problem,
> > because these other languages don't have a concept of 'const'.
I don't see that this needs to be a problem. Const is a a compile time
thing. Couldn't it be implemented using assembly metadata? So that it
simply isn't visible at all to languages that doesn't support it? Or it might even be possible to have const enforced at runtime when assemblies using const are used from languages that don't support const and vice versa.


If it can be enforced at runtime a developer has to be aware of const, the language has to support it in some fashion. If it isn't enforced, you

could
get a class that claims const but, because it was developed in a

const-less
language really isn't. In that case I imagine you wouldn't be pleased when your object state started changing in const methods. However, due to the
point that the BCL really needs const-ness to make it truly effective,
instead of a burden, it would mean that you couldn't trust const without
examing the source, which in a sense defeats the point. All CLS languages would atleast have to respect constness, if not provide a way to create
const references of your own.


<snip>

Hmm, I should have run further with the assembly metadata idea. There

should be no need for runtime support. Const correctness could be enforced by a
post compile check at the IL level for non-supporting languages. No extra
work would be necccessary for the compilers for these languages beyond
invoking the check upon completion and mapping errors back to reasonably
sensible messages. Should these compilers fail to do so the problem would
be caught by the jit compiler.

The main issue is that you can't apply an attribute to a variable, only to
fields, etc. Which means only class members can have const specified, not
specific fields. To achieve const you need to be able to attach the data to
a particular variable, which requires compiletime supoprt
Anyone know a reason why this wouldn't work?

/Magnus Lidbom


Nov 15 '05 #161

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:ei******** ********@TK2MSF TNGP12.phx.gbl. ..

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...
>
> "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in > message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> >
> > "Frans Bouma" <pe************ ******@xs4all.n l> wrote in message
> > news:Xn******** *************** **********@207. 46.248.16...
> > > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net>
wrote in
> > > news:#5******** ******@tk2msftn gp13.phx.gbl:
> > > > "Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
> > > > news:MP******** *************** @msnews.microso ft.com...


<snip>
Hmm, I should have run further with the assembly metadata idea. There

should
be no need for runtime support. Const correctness could be enforced by a
post compile check at the IL level for non-supporting languages. No extra work would be necccessary for the compilers for these languages beyond
invoking the check upon completion and mapping errors back to reasonably
sensible messages. Should these compilers fail to do so the problem would be caught by the jit compiler.


The main issue is that you can't apply an attribute to a variable, only to
fields, etc. Which means only class members can have const specified, not
specific fields. To achieve const you need to be able to attach the data
to
a particular variable, which requires compiletime supoprt

Yes, but that would only need to be done when compiling the languages that
do support const since the others can't create their own const references.
Validating use for other languages could be done in a post compile step or
by some sort of plugin for the existing compiler. Don't most languages
compilers use reflection emit to create IL? If that's universal, plugging in
const checking there should do the trick shouldn't it?
Regards /Magnus Lidbom


Nov 15 '05 #162

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:ei******** ********@TK2MSF TNGP12.phx.gbl. ..

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
>
> "Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
> news:bv******** ****@ID-204195.news.uni-berlin.de...
> >
> > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in > > message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> > >
> > > "Frans Bouma" <pe************ ******@xs4all.n l> wrote in message
> > > news:Xn******** *************** **********@207. 46.248.16...
> > > > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
> > > > news:#5******** ******@tk2msftn gp13.phx.gbl:
> > > > > "Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
> > > > > news:MP******** *************** @msnews.microso ft.com...

<snip>
Hmm, I should have run further with the assembly metadata idea. There should
be no need for runtime support. Const correctness could be enforced by a post compile check at the IL level for non-supporting languages. No extra work would be necccessary for the compilers for these languages beyond
invoking the check upon completion and mapping errors back to reasonably sensible messages. Should these compilers fail to do so the problem would be caught by the jit compiler.


The main issue is that you can't apply an attribute to a variable, only to fields, etc. Which means only class members can have const specified, not specific fields. To achieve const you need to be able to attach the data
to
a particular variable, which requires compiletime supoprt

Yes, but that would only need to be done when compiling the languages that
do support const since the others can't create their own const references.
Validating use for other languages could be done in a post compile step or
by some sort of plugin for the existing compiler. Don't most languages
compilers use reflection emit to create IL? If that's universal, plugging

in const checking there should do the trick shouldn't it?
Well, I don't know about most compilers, the Mono C# compiler does for sure.
Plugging const into the runtime(both reflection emit and whatever else it
takes, perhaps the ref table) would be nessecery. I'm not sure of *how* to
plug it in, perhaps the experimental Rotor mod that adds const would have
more information on that.
It may be possible, just perhaps a good bit of work(tracking references
could be tricky).
Regards /Magnus Lidbom

Nov 15 '05 #163

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:ei******** ********@TK2MSF TNGP12.phx.gbl. ..

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...
>
> "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in > message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
> >
> > "Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
> > news:bv******** ****@ID-204195.news.uni-berlin.de...
> > >
> > > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote
in
> > > message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> > > >
> > > > "Frans Bouma" <pe************ ******@xs4all.n l> wrote in
message > > > > news:Xn******** *************** **********@207. 46.248.16...
> > > > > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote
> in
> > > > > news:#5******** ******@tk2msftn gp13.phx.gbl:
> > > > > > "Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
> > > > > > news:MP******** *************** @msnews.microso ft.com...
>


<snip>
> Hmm, I should have run further with the assembly metadata idea. There should
> be no need for runtime support. Const correctness could be enforced by a > post compile check at the IL level for non-supporting languages. No extra
> work would be necccessary for the compilers for these languages
beyond > invoking the check upon completion and mapping errors back to reasonably > sensible messages. Should these compilers fail to do so the problem

would
> be caught by the jit compiler.
>

The main issue is that you can't apply an attribute to a variable, only to
fields, etc. Which means only class members can have const specified, not specific fields. To achieve const you need to be able to attach the
datato
a particular variable, which requires compiletime supoprt

Yes, but that would only need to be done when compiling the languages

that do support const since the others can't create their own const references. Validating use for other languages could be done in a post compile step or by some sort of plugin for the existing compiler. Don't most languages
compilers use reflection emit to create IL? If that's universal,

plugging in
const checking there should do the trick shouldn't it?
Well, I don't know about most compilers, the Mono C# compiler does for

sure. Plugging const into the runtime(both reflection emit and whatever else it
takes, perhaps the ref table) would be nessecery. I'm not sure of *how* to
plug it in, perhaps the experimental Rotor mod that adds const would have
more information on that.
It may be possible, just perhaps a good bit of work(tracking references
could be tricky).

It would hardly be the first task for the those components that took time or
was tricky though :)

The reason I'm pursuing this is that I seem to remember language
interoperabilit y being quoted as the scale tipping reason for leaving const
out of the language. In my opinion, that argument fails if const correctness
checking can be supplied for any language by modifying reflection emit, or
by supplying a common IL validator. Wait a sec now, thats ilasm.exe for
crying out loud :)

Regards /Magnus Lidbom


Nov 15 '05 #164

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:ei******** ********@TK2MSF TNGP12.phx.gbl. ..
>
> "Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
> news:bv******** ****@ID-204195.news.uni-berlin.de...
> >
> > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in > > message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
> > >
> > > "Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
> > > news:bv******** ****@ID-204195.news.uni-berlin.de...
> > > >
> > > > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
> > > > message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> > > > >
> > > > > "Frans Bouma" <pe************ ******@xs4all.n l> wrote in message > > > > > news:Xn******** *************** **********@207. 46.248.16...
> > > > > > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote
> > in
> > > > > > news:#5******** ******@tk2msftn gp13.phx.gbl:
> > > > > > > "Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
> > > > > > > news:MP******** *************** @msnews.microso ft.com...
> >

<snip>

> > Hmm, I should have run further with the assembly metadata idea. There > should
> > be no need for runtime support. Const correctness could be enforced
by
a
> > post compile check at the IL level for non-supporting languages.
No extra
> > work would be necccessary for the compilers for these languages beyond > > invoking the check upon completion and mapping errors back to reasonably
> > sensible messages. Should these compilers fail to do so the problem would
> > be caught by the jit compiler.
> >
>
> The main issue is that you can't apply an attribute to a variable, only
to
> fields, etc. Which means only class members can have const

specified, not
> specific fields. To achieve const you need to be able to attach the data >to
> a particular variable, which requires compiletime supoprt
Yes, but that would only need to be done when compiling the languages that do support const since the others can't create their own const references. Validating use for other languages could be done in a post compile
step or by some sort of plugin for the existing compiler. Don't most languages
compilers use reflection emit to create IL? If that's universal,
plugging
in
const checking there should do the trick shouldn't it?

Well, I don't know about most compilers, the Mono C# compiler does for

sure.
Plugging const into the runtime(both reflection emit and whatever else

it takes, perhaps the ref table) would be nessecery. I'm not sure of *how* to plug it in, perhaps the experimental Rotor mod that adds const would have more information on that.
It may be possible, just perhaps a good bit of work(tracking references
could be tricky).

It would hardly be the first task for the those components that took time

or was tricky though :)

The reason I'm pursuing this is that I seem to remember language
interoperabilit y being quoted as the scale tipping reason for leaving const out of the language. In my opinion, that argument fails if const correctness checking can be supplied for any language by modifying reflection emit, or
by supplying a common IL validator. Wait a sec now, thats ilasm.exe for
crying out loud :)
Hehe, sorry, I misread your post. I thought you were propsing a tool to
determine const behavior *now*.
The language issue does exist, though a common, standardized verification
interface for compilers would go a long way. Instead of forcing a compiler
to behave just allow all compilers to accept the same rules\plugins.. .. Regards /Magnus Lidbom

Nov 15 '05 #165

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:ed******** ******@TK2MSFTN GP12.phx.gbl...

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...
>
> "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in > message news:ei******** ********@TK2MSF TNGP12.phx.gbl. ..
> >
> > "Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
> > news:bv******** ****@ID-204195.news.uni-berlin.de...
> > >
> > > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote
in
> > > message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
> > > >
> > > > "Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
> > > > news:bv******** ****@ID-204195.news.uni-berlin.de...
> > > > >
> > > > > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote
> in
> > > > > message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> > > > > >
> > > > > > "Frans Bouma" <pe************ ******@xs4all.n l> wrote in

message
> > > > > > news:Xn******** *************** **********@207. 46.248.16...
> > > > > > > "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> > wrote
> > > in
> > > > > > > news:#5******** ******@tk2msftn gp13.phx.gbl:
> > > > > > > > "Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in
message > > > > > > > > news:MP******** *************** @msnews.microso ft.com...
> > >
>


<snip>
The reason I'm pursuing this is that I seem to remember language
interoperabilit y being quoted as the scale tipping reason for leaving

const
out of the language. In my opinion, that argument fails if const

correctness
checking can be supplied for any language by modifying reflection emit, or by supplying a common IL validator. Wait a sec now, thats ilasm.exe for
crying out loud :)

Hehe, sorry, I misread your post. I thought you were propsing a tool to
determine const behavior *now*.


Oh. I don't think I'd care to attempt that :)
The language issue does exist, though a common, standardized verification
interface for compilers would go a long way. Instead of forcing a compiler
to behave just allow all compilers to accept the same rules\plugins.. ..


Exactly. Unless there are stumbling blocks I'm not seeing the
interoperabilit y issue should be a relatively minor one. Such an
implementation might also greatly simplify the migration of the BCL and
other existing code to a const correct state. A compiler flag could be used
to disable the compilers own support for checking const correctness and
delegating it to the generic validator. Since this validator would examine
actual usage of references, not declarations of references , it would allow
for the gradual introduction of const correctness in existing code without
any intermediate code breaking what so ever! Coder error barred of course.
Such a switch seems to me to counter every problem with introducing const
that you've brought up so far.

Am I missing anything?
Anyone have a reason why this wouldn't work?

Regards /Magnus Lidbom



Nov 15 '05 #166
<snip>

<snip>
The reason I'm pursuing this is that I seem to remember language
interoperabilit y being quoted as the scale tipping reason for leaving const
out of the language. In my opinion, that argument fails if const

correctness
checking can be supplied for any language by modifying reflection emit, or
by supplying a common IL validator. Wait a sec now, thats ilasm.exe
for crying out loud :)
Hehe, sorry, I misread your post. I thought you were propsing a tool to
determine const behavior *now*.


Oh. I don't think I'd care to attempt that :)
The language issue does exist, though a common, standardized

verification interface for compilers would go a long way. Instead of forcing a compiler to behave just allow all compilers to accept the same rules\plugins.. ..


Exactly. Unless there are stumbling blocks I'm not seeing the
interoperabilit y issue should be a relatively minor one. Such an
implementation might also greatly simplify the migration of the BCL and
other existing code to a const correct state. A compiler flag could be

used to disable the compilers own support for checking const correctness and
delegating it to the generic validator. Since this validator would examine
actual usage of references, not declarations of references , it would allow for the gradual introduction of const correctness in existing code without
any intermediate code breaking what so ever! Coder error barred of course.
Such a switch seems to me to counter every problem with introducing const
that you've brought up so far.
I agree, it certainly helps(although I still think *some* BCL work needs to
be done). Am I missing anything?
Anyone have a reason why this wouldn't work?
Nothing I can think of right now. This may be a case wehre the technical
aspect is surmountable while the political one isn't. Convincing the ECMA or
Microsoft that const is important would be the bigger problem.
Regards /Magnus Lidbom




Nov 15 '05 #167

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:Oe******** ******@tk2msftn gp13.phx.gbl...
<snip>

<snip>
> The reason I'm pursuing this is that I seem to remember language
> interoperabilit y being quoted as the scale tipping reason for leaving const
> out of the language. In my opinion, that argument fails if const
correctness
> checking can be supplied for any language by modifying reflection emit,
or
> by supplying a common IL validator. Wait a sec now, thats ilasm.exe for > crying out loud :)
>
Hehe, sorry, I misread your post. I thought you were propsing a tool to determine const behavior *now*.
Oh. I don't think I'd care to attempt that :)
The language issue does exist, though a common, standardized verification interface for compilers would go a long way. Instead of forcing a compiler to behave just allow all compilers to accept the same

rules\plugins.. ..
Exactly. Unless there are stumbling blocks I'm not seeing the
interoperabilit y issue should be a relatively minor one. Such an
implementation might also greatly simplify the migration of the BCL and
other existing code to a const correct state. A compiler flag could be

used
to disable the compilers own support for checking const correctness and
delegating it to the generic validator. Since this validator would examine actual usage of references, not declarations of references , it would

allow
for the gradual introduction of const correctness in existing code without any intermediate code breaking what so ever! Coder error barred of course. Such a switch seems to me to counter every problem with introducing const that you've brought up so far.

I agree, it certainly helps(although I still think *some* BCL work needs

to be done).
No argument there. Such an implementation would not diminish the need for
const correct code in any way. But it would allow the changes to be
introduced gradually, without breaking code along the way. One could go
class by class and insert const where appropriate and everything would still
compile every single step of the way. Barring bugs of course, and finding
those is hardly detrimental :). Compare that method of updating the source
to what it would be like if only declarations where examined to verify const
correctness. Just about every added const would cause breakage.
Am I missing anything?
Anyone have a reason why this wouldn't work?


Nothing I can think of right now. This may be a case where the technical
aspect is surmountable while the political one isn't. Convincing the ECMA

or Microsoft that const is important would be the bigger problem.


It may well be. But unless we're missing something the only meaningful
argument against const I've heard so far seems to be void. Maybe this
solution hasn't occurred to the C# team. After all, it is rather unorthodox.
If the decision to forgo const was made assuming that const would be
guraranteed to break language interoperabilit y and that introducing const
correct code would cause severe code breakage along the way, then this
solution, if feasable, just might make them reconsider.

/Magnus Lidbom


Nov 15 '05 #168
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
news:Oe******** ******@TK2MSFTN GP10.phx.gbl:
"Frans Bouma" <pe************ ******@xs4all.n l> wrote in message
news:Xn******** *************** **********@207. 46.248.16...
I don't see why not. It's compiler sugar. C++'s const can be
compiled into C code, a language which doesn't contain const. I don't
see why ToString() has any importance in this though. :) It doesn't
alter anything, it just transfers a value to a string format which is
returned, the actual value isn't altered.
Thats the point, ToString() is *NOT* const, its a non-const method.


I know, but that's not too interesting, is it? :) I mean: it
produces a new value, from the old value, it doesn't change the old value,
therefore isn't altering the old value which is constant. I mean this is
also good code:

// foo.Bar is const
int i = foo.Bar;
i++;

I see that as the same as:
string bar = foo.Bar.ToStrin g();

But perhaps we have a misunderstandin g going on somewhere ;)
Meaning you would haveto cast const-ness away to use it. Thats the
annoyance I'm trying to get at.
You have to explain to me why because I don't see this. It's my
understanding that ToString() always produces a new value, so I don't see
why I need to cast away const to be able to use it.
While I agree is compiler sugar, I just think its next to useless if it
is only applicable in one language out of many that *could* source the
code. Exposing it as a bit of metadata markup is one thing, you actually
could write static tools to verify this if you were enterprising enough,
but really integrating it into the language and the runtime is something
else. I don't feel that its proper to just start cramming things in as
"compiler sugar" at this point. I would rather see a clean, well thought
out implementation in V5 instead of a hacked, half-assed one in V3.
Remeber, once it goes in, it can never come back out.


I agree that if C# has 'const' and VB.NET doesn't, it's pretty moot
to mark a property's value as const in C# while you can keep altering it
in VB.NET.

However what's the problem by having it in the CLR? Say const
exists and I have this code in class object myBar:

public const Foo MyFoo
{
get { return _myFoo; }
}

Now, when I do this in C#:
Foo bla = myBar.MyFoo;

I can't alter bla's data, because it is const. Now if I do it in
VB.NET:
Dim bla As Foo = myBar.MyFoo

and say, VB.NET doesn't support const and const would be introduced
as a compiler check, the VB.NET developer would be able to alter bla's
data because VB.NET doesn't know of const, and I agree, this is an issue
with compiler-only const checks, so it's not that valuable.

However, if it is placed in the CLR, the CLR could then throw an
exception if the VB.NETdeveloper does this:

bla.MyProperty = newValue

then, although VB.NET doesn't know const, the CLR can forbid the
alternation of that property because bla is const. You can argue that this
is a bad thing, but why would it be a bad thing? I don't see it. The
developer of Bar clearly stated that MyFoo is a const property, and did
that on purpose. Even though VB.NET doesn't understand const, it can't
alter the object, simple as that.

The though thing now is: how does the VB.NET developer know MyFoo
is a const property? This is, I think an issue of documentation. I mean,
if there is no set clause in a property, setting it to a value also gives
an error.

FB
--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Nov 15 '05 #169

"Magnus Lidbom" <ma***********@ hotmail.com> wrote in message
news:bv******** ****@ID-204195.news.uni-berlin.de...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:Oe******** ******@tk2msftn gp13.phx.gbl...
<snip>

<snip>

> > The reason I'm pursuing this is that I seem to remember language
> > interoperabilit y being quoted as the scale tipping reason for leaving > const
> > out of the language. In my opinion, that argument fails if const
> correctness
> > checking can be supplied for any language by modifying reflection emit,
or
> > by supplying a common IL validator. Wait a sec now, thats ilasm.exe
for
> > crying out loud :)
> >
> Hehe, sorry, I misread your post. I thought you were propsing a tool to > determine const behavior *now*.

Oh. I don't think I'd care to attempt that :)

> The language issue does exist, though a common, standardized

verification
> interface for compilers would go a long way. Instead of forcing a

compiler
> to behave just allow all compilers to accept the same rules\plugins.. ..
Exactly. Unless there are stumbling blocks I'm not seeing the
interoperabilit y issue should be a relatively minor one. Such an
implementation might also greatly simplify the migration of the BCL
and other existing code to a const correct state. A compiler flag could be

used
to disable the compilers own support for checking const correctness and delegating it to the generic validator. Since this validator would

examine actual usage of references, not declarations of references , it would

allow
for the gradual introduction of const correctness in existing code without any intermediate code breaking what so ever! Coder error barred of course. Such a switch seems to me to counter every problem with introducing const that you've brought up so far.

I agree, it certainly helps(although I still think *some* BCL work needs

to
be done).


No argument there. Such an implementation would not diminish the need for
const correct code in any way. But it would allow the changes to be
introduced gradually, without breaking code along the way. One could go
class by class and insert const where appropriate and everything would

still compile every single step of the way. Barring bugs of course, and finding
those is hardly detrimental :). Compare that method of updating the source
to what it would be like if only declarations where examined to verify const correctness. Just about every added const would cause breakage.
Am I missing anything?
Anyone have a reason why this wouldn't work?
Nothing I can think of right now. This may be a case where the technical
aspect is surmountable while the political one isn't. Convincing the

ECMA or
Microsoft that const is important would be the bigger problem.
It may well be. But unless we're missing something the only meaningful
argument against const I've heard so far seems to be void. Maybe this
solution hasn't occurred to the C# team. After all, it is rather

unorthodox. If the decision to forgo const was made assuming that const would be
guraranteed to break language interoperabilit y and that introducing const
correct code would cause severe code breakage along the way, then this
solution, if feasable, just might make them reconsider.
It might, I'm certain someone from MS is reading this, even if they don't
respond. We'll see if it ever flys anywhere. Of course approaching MS and
the EMCA would be another choice. The rotor const implementation is
something else, inclusions in rotor are more likely to be considered(for
one, MS Employees can look at the source to rotor, I don't think they can't
look at OSS source in their area and I don't know if they can use OSS produc
ts). An examiniation of that would probably yield fruitful as well.
Unfortunate that the C# compiler is in C++ however, I'd rather not go back
to using C++ for anything I can avoid, ;).

Anyway, it also gives rise to an idea that I don't think the framework
currently supports. If the framework was extended to the point where it was
possible to plug in verification units into the run time, something that can
run just before the JIT'er and do analysis on IL on the method being JIT'ed,
such protections and other issues may be additionally avoidable. It would be
a performance issue, to some extent, but as it would only analyze each
method just before the JIT work is done, it would be faster than a scan
before every execution and could be disabled by running ngen for apps with a
vital startup speed. It would be interesting, and an extension point I'd
very much like to see, atleast experimentally. I really do need to suck it
up and take a look at rotor, see if such a mechanism is possible.
/Magnus Lidbom



Nov 15 '05 #170

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3749
by: Long | last post by:
How to include an HTML doc in another HTML doc Problem: to insert the body section of an HTML doc in another HTML document at a specific location. One possible way is to add a WebCharm tag like this: <%@charm:html 20 0 my_services.htm %> When the HTML template is processed by a WebCharm-aware web server, the
19
2561
by: TC | last post by:
Are there any good sites or forums for a web critique? I went to alt.html.critique and it's pretty dead.
9
2290
by: bowsayge | last post by:
Inspired by fb, Bowsayge decided to write a decimal integer to binary string converter. Perhaps some of the experienced C programmers here can critique it. It allocates probably way too much memory, but it should certainly handle 64-bit cpus :) #include <stdio.h> #include <stdlib.h> char * to_binary (unsigned long value) {
39
1947
by: Eric | last post by:
There is a VB.NET critique on the following page: http://www.vb7-critique.741.com/ for those who are interested. Feel free to take a look and share your thoughts. Cheers, Eric. Ps: for those on comp.programming, this may be off topic, but I've posted there because the critique was part of a discussion in that group.
0
9870
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10671
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10310
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7855
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7035
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4499
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4088
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3142
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.