473,842 Members | 1,818 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 7272
As I told you before C# 2.0 doesn't have .lib and static linking. Static
linking involves a native code compiler and a linker, these are the domain
of C++.

Willy.

<di********@dis cussion.microso ft.com> wrote in message
news:O7******** ********@TK2MSF TNGP10.phx.gbl. ..
As for preprocessors, theyre evil, hard to debug and just not good in any
way to have mixed compiled code.

I prefer to use a const value rather than conditional compile, at least C#
has reduced this need by having defines limited to true or false values,
still I would prefer it not there at all.

The lack of .lib static linking was a bad thing to not have, thankfully
its
back in 2.0.

Nov 15 '05 #61

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Two things spring to mind after only a very cursory glance

1) Garbage collection - you've got a sentence which doesn't finish
Pardon my density but which one?
2) User defined type values can't be used as constant expressions, but
you can certainly have readonly variables:

readonly MyValueType foo = new MyValueType(... );
What is it about my brain? I am having trouble expressing the whole
non-constness thing. What I mean to say is that I can't have a const
instance of a type. Even though the reference itself can be const.
--
Jon Skeet - <sk***@pobox.co m>


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

"Andreas Huber" <ah****@gmx.net > wrote in message
news:40******** **@news.bluewin .ch...
Thanks to all for your time and input.
AFAICT, array<complex<f loat>> will be legal ("although constructed types

may be used as generics").

Regards,

Andreas


In C#, a generic type parameter cannot itself be a generic, although
constructed types may be used as generics. What is a complex<float> if it is
not a generic? Truthfully I don't have a clue what they mean by "constructe d
type".

--
Christopher Diggins
yet another language designer
http://www.heron-language.com
Nov 15 '05 #63
christopher diggins <cd******@video tron.ca> wrote:

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Two things spring to mind after only a very cursory glance

1) Garbage collection - you've got a sentence which doesn't finish


Pardon my density but which one?


Apologies - it was in value type vs reference type:

"There are more allocations on the heap than are strictly neccessary
leading to memory f"
2) User defined type values can't be used as constant expressions, but
you can certainly have readonly variables:

readonly MyValueType foo = new MyValueType(... );


What is it about my brain? I am having trouble expressing the whole
non-constness thing. What I mean to say is that I can't have a const
instance of a type. Even though the reference itself can be const.


In fact, a reference can't be const - only a variable can be const, and
the only type of reference variable that can be const is a string one.
Const is for constants, and constants aren't the same as immutable
objects.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #64
christopher diggins wrote:
"Andreas Huber" <ah****@gmx.net > wrote in message
news:40******** **@news.bluewin .ch...
Thanks to all for your time and input.


AFAICT, array<complex<f loat>> will be legal ("although constructed
types may be used as generics").

Regards,

Andreas


In C#, a generic type parameter cannot itself be a generic, although
constructed types may be used as generics. What is a complex<float>
if it is not a generic? Truthfully I don't have a clue what they mean
by "constructe d type".


complex< float > is a normal class/type. I guess with "constructe d type"
they mean an instantiated generic what makes sense given the fact that they
are saying that C# will have nothing like C++ template template parameters
(note the double template).

Regards,

Andreas

Nov 15 '05 #65
I suppose it depends who you talk to and what you talk about :-)
For example, I've had some communications with the Mono developers, and they
are outstanding people to deal with, and overall a great bunch of guys.
However, my personal experience with others in the community is far less
spectacular. If the word Microsoft is ever dropped near most of the people i
know from that camp, they revert from geek compatriot to
raving-zealot-burn-the-heretic mode. Frankly, i'm sick of it, and it
demonstrates only vast ignorance, childishness, and unprofessionali sm. I
also believe a healthy number of them do get nowhere... just check the
various lists of projects. There are vast numbers of projects in open-source
purgatory that had a three year alpha, a brief beta, a huge log of bugs, and
abruptly *died*. The source is sitting there, rotting and half finished, in
hopes some other geek will revive it. Hell, this even happens with big
companies in open source. The UnitedLinux consortium flopped over and
officially died this week because its members couldn't get along (and MS
wasn't even one of them).

There's just too much pointless partisanship that has nothing to do with
technical merits or accuracy. The kind of stuff I have come to expect from
politicians and Larry Ellison, not engineers. Technology is science. Leave
the blind devotion and religious fervor for more important things.

And i'm not implying at all that these people don't also exist on the
non-OpenSource side of the fence. We have a healthy number in this NG too.

-Rob Teixeira [MVP]
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
<"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com>> wrote:
You're welcome Christopher. I'm glad to see the more cooperative attitude. Now if I could only convince the other open-sourcers to do the same, we
might actually get somewhere :-)


Actually, open source folks tend to be very co-operative - otherwise
they don't get anywhere. That's certainly true in my experience,
anyway.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #66


--
Christopher Diggins
yet another language designer
http://www.heron-language.com
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
christopher diggins <cd******@video tron.ca> wrote:

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Two things spring to mind after only a very cursory glance

1) Garbage collection - you've got a sentence which doesn't finish


Pardon my density but which one?


Apologies - it was in value type vs reference type:

"There are more allocations on the heap than are strictly neccessary
leading to memory f"
2) User defined type values can't be used as constant expressions, but
you can certainly have readonly variables:

readonly MyValueType foo = new MyValueType(... );


What is it about my brain? I am having trouble expressing the whole
non-constness thing. What I mean to say is that I can't have a const
instance of a type. Even though the reference itself can be const.


In fact, a reference can't be const - only a variable can be const, and
the only type of reference variable that can be const is a string one.
Const is for constants, and constants aren't the same as immutable
objects.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #67
Sorry about the previous blank post, finger slipped. Damn trigger finger.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Apologies - it was in value type vs reference type:

"There are more allocations on the heap than are strictly neccessary
leading to memory f"
Thank you.
2) User defined type values can't be used as constant expressions, but
you can certainly have readonly variables:

readonly MyValueType foo = new MyValueType(... );


What is it about my brain? I am having trouble expressing the whole
non-constness thing. What I mean to say is that I can't have a const
instance of a type. Even though the reference itself can be const.


In fact, a reference can't be const - only a variable can be const, and
the only type of reference variable that can be const is a string one.


Quote from MSDN :

The const keyword is used to modify a declaration of a field or local
variable. It specifies that the value of the field or the local variable
cannot be modified
....
One of the types: byte, char, short, int, long, float, double, decimal,
bool, string, an enum type, or a reference type.

http://msdn.microsoft.com/library/de...lrfconstpg.asp

This would seem to contradict you.
Const is for constants, and constants aren't the same as immutable
objects.


A const variable is an immutable variable though an immutable
variable is not neccessarily const. Do you not agree with me on that one?

Nonetheless, I still stand by my statement as in the critique.

--
Christopher Diggins
yet another language designer
http://www.heron-language.com
Nov 15 '05 #68
> GC:
Problem #2 : Unsafe contexts. There is a problem of being able to modify managed types. This significantly undermines the effectiveness of a GC and renders all unsafe code as potentially having classes of errors which are normally removed by a GC mechanism. From the language specification :
There are certainly issues that can come up from misuse of unsafe code. The
example you cited from the MSDN talks about strings, for example. Strings
are immutable types in the CLI/CLR, which allows the CLR to do
optimizations. For example, assigning one string ref to another doesn't copy
the contents. Since the runtime knows strings shouldn't change, both
references point at the same character array until one is assigned to a
different value. If you use unsafe code with one ref, and change the value,
you are inadvertantly changing another string ref's data as well, which
could cause a series of bugs. However, this in no way affects the GC. The
objects themselves live on the managed heap, and the GC will eventually get
around to cleaning them. I *strongly urge* you to read up on the GC and how
it works internally. Having said that, let's look at a problem with our
string scenario that can't be solved without unsafe or unmanaged code -
let's say you create one string variable and decrypt cipher data into it
containing a password (or any secret bit of info - credit card number,
etc.). You do what you need to do in your function, and when the function
ends, your string variable goes out of scope. The string is now elegible for
collection. However, you have no idea how long it will remain in memory.
It's possible that it's there for some time, and let's say it gets paged
out. Now, a clever hacker can sniff through your page file for secret data,
and it will show up. Programmers who are wary of security concerns need to
wipe secrets out of memory as quickly as possible. Knowing that there is
only ever one reference to the string, there is no reason I can't pin that
string, and using unsafe or unmanaged code, zero it out. You may not like
unsafe code, and it does have the potential of burning developers who don't
know what they're doing, but it does have its legitimate uses. Remember that
you can turn off this feature by not allowing the compiler switch to be used
by your development team. C# will not compile unsafe code by default. You do
not mention that in your text.
Value Type / Reference Types
A type in C# declares its own passing and assigning semantics. This violates a consistency rule of expected behaviour. Since objects are always reference types this also leads to several small performance penalties : a.. An extra word is always needed for the pointer
b.. There are more allocations on the heap than are strictly neccessary
leading to memory fragmentation
c.. There is more memory than strictly neccessary needed to be cleaned up
by the garbage collector
d.. Dereference of pointer penalty As a result of having two kinds of types and in order to have some kind of unification C# chose to use a boxing / unboxing semantic. Boxing and unboxing is both subtle and confusing as it can lead to a surprising interpretation of straightforward code.

Are you saying that there should only be either all value types or all
reference types? If so, which one would you use? Languages like Java use
exclusively reference types (except for special case primitives) because it
is the most flexible type. However, if you kept all reference types, then
you'd have nothing but types that fit your "perforance penalties". On the
other hand, value types have an enormous number of limitations compared to
reference types, so I can't even fathom a language with all value types.
What's your alternative?

Also, the managed heap doesn't suffer from memory fragmentation like heaps
from certain other languages do. Use of the GC allows all memory to be
allocated sequentially. As objects get collected, the space is compacted by
generation. However, let's pretend for a minute this isn't the case. How
does using a non-reference type change the way the heap is used? You are
still allocating and cleaning out memory, and you'd still be leaving
fragments of unallocated space. I don't quite understand this bullet point,
or the next one. Finally, if you are using a system that has no reference
types, how can you have references that point to the same data? Would you
have to copy all your data EVERY time? How would you synchronize instances
to maintain semantics of assignment? Wouldn't that suck for performance?
Special Primitives and Immutabilty
"a const field is a compile-time constant"
You still haven't answered my question about how you would allow reference
types (or other user-defined types) to have this behavior. This is where we
need to develop the syntax that allows programmers to specify literal values
for what could be relatively complex object graphs, THEN on top of that, the
compiler needs to have a mechanism to store this data in the program AND
reconstitute it at runtime. Then we run into the problem of read-only (which
C# can do) vs. immutability. If you reconstitute the value at runtime by
normal instantiation, you are only creating a read-only value (which C# can
already do). If you reconstitute the value in a truly const manner, you
effectively bypass constructors, which is disasterous. This is why all
languages i can think of don't allow this. If you are suggesting that C# is
doing something that is less than ideal, what is your ideal solution?
C# does not support delegating interface implementations to member classes. This significantly restricts the ability to use interfaces extensively.
Example? I'm not entirely disagreeing with you, but I'm wondering if we are
exaggerating the problem by using "extensivel y"?
The reason I'm not disagreeing entirely is that i'm not exactly fond of the
syntax C# uses for implementing interfaces. However I disagree that C# can't
do this. It is perfectly capable of delegating interface method calls to
member classes... I think you mean delegating the method call to a method of
a *contained* class (rather than nested class, right?). Anyway, again, C# is
perfectly capable of doing this.
Missing Interface Extensions
Example please? Are you assuming that you can't define Interfaces in C#?
That's what this is reading like, and that certainly isn't true at all. C#
allows you to write classes, abstract classes, AND stand-alone interfaces.
Interfaces in C# have no implementation and are not tied to a class
definition, so I'm confused at what you mean in your statement. Class
inheritance is NOT the only means of polymorphism in C#. That is also an
incorrect statement. You can certainly implement interfaces and create
interfaces. Please clarify this point, because I don't think you understand
what C# is doing here.
Source File Layout
[The lack of seperate and explicit definitions, aka header files]
promotes an unstructured coding style and often leads to bugs that are not
immediately obvious without reading the automatically generated

documentation.

I'm not sure I agree with this. What type of bugs are we talking about here
and how do we know this happens often? If you make an assertion, you are
going to have to back it up or qualify it. You may *prefer* to have header
files for various reasons, but you shouldn't make a blanket statement about
bugs without having data to prove it, or at the very least giving a good
example (or more) of what types of bugs we're dealing with here. I also
think you are going to have to explain why header files are better in your
opinion than documentation.. . in a sense, they are both being viewed here as
documentation here, and both are nothing but text at this point.

-Rob Teixeira [MVP]
Nov 15 '05 #69
With templates and generics, Complex<float> becomes a type of it's own, just
like Object or float. Therefore there's no reason why Array<Complex<f loat>>
wouldn't work. If you have an Array<T>, then T can certainly be passed
Complex<float>.

I think you're getting parameter and argument confused. The generic type
argument CAN be a generic type.

The generic type parameter cannot be a generic. For example, in C++
templates you can define a class such as this:

template < template < class A > class B >
class MyTemplateTempl ateClass {
};

I've never used this, and many C++ compilers don't even support it.
Microsoft's didn't until very recently.

I've seen a few good uses of these in C++, but I can't honestly think of how
it would be useful in C# (at least with generics being implemented as they
are in C#).

And to do Array<Complex<f loat>> in C++ you don't need a template template
parameter.

--Matthew W. Jackson

"christophe r diggins" <cd******@video tron.ca> wrote in message
news:DZ******** **************@ weber.videotron .net...

"Andreas Huber" <ah****@gmx.net > wrote in message
news:40******** **@news.bluewin .ch...
Thanks to all for your time and input.
AFAICT, array<complex<f loat>> will be legal ("although constructed types

may
be used as generics").

Regards,

Andreas


In C#, a generic type parameter cannot itself be a generic, although
constructed types may be used as generics. What is a complex<float> if it

is not a generic? Truthfully I don't have a clue what they mean by "constructe d type".

--
Christopher Diggins
yet another language designer
http://www.heron-language.com

Nov 15 '05 #70

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
9709
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,...
0
10939
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10609
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10308
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
7853
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
7028
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();...
0
5695
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4086
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3140
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.