473,842 Members | 1,926 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 7277
Stu Smith wrote:
I'd just like to butt-in on question 12, public fields. One of my
favourite C++ questions (with no right or wrong answer) is: "given
that we don't like public data fields, and given that the people who
implement STL libraries are pretty smart, why is pair<A, B> generally
implemented with two public data fields?"


Because the pair is a generic container for two values. The two data members
of the pair don't have anything to do with eachother (even if they had, the
clients of the pair wouldn't want/need know about it). There are no
preconditions, post conditions and invariants to enforce. Consequently,
there are no getter/setter accessors because that would not add anything.

Regards,

Andreas

Nov 15 '05 #81
codymanix wrote:
*** NO MULTIPLE INHERITANCE ***!!!

Biggest fault of C# in my opinion.


If you can state only one example where multiple nheritance is
required I'll believe you,
otherwise not. Multiple Inheritance is just bad style used by poor
programmers.
All Multiple Inheritance scenarios are best solved using composition
instead.


Please then tell me how to implement an indirect visitor in C++ without MI
(I'm sure google'll give you all you need to know).

Regards,

Andreas

Nov 15 '05 #82
codymanix wrote:
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.


The whole const-stuff in C++ is stupid. Classes should be
self-contained, and therefore everybody should be able to modify them
safely. This is real-world,
or do you know objects in the real world that are constant? :)

Maybe in C++ it was neccesary due to the whole pointer-stuff and so
on but in other
languages it is not.


Oh, yet another ingenious insight!

http://www.research.att.com/~bs/blast.html

I'm afraid the "pointer-stuff" has not much to do with whether const makes
sense or not. It is also worth noting that there is an experimental C#
compiler supporting const (Rotor I think) and that most experts would rather
see const back in Java and C#. Reference types with value-type semantics
(e.g. string) would benefit from const (performance-wise).

Regards,

Andreas

Nov 15 '05 #83
codymanix wrote:
[snip]
- non-deterministic destructors


Deterministic destructors are good for deallocating native resources
only. Theoretically
they could make dtors of value-types deterministic, but they don't. I
don't know why.


Boxing.

Regards,

Andreas
Nov 15 '05 #84
codymanix <do************ *********@gmx.d e> wrote:
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.


The whole const-stuff in C++ is stupid. Classes should be self-contained,
and therefore everybody should be able to modify them safely. This is
real-world, or do you know objects in the real world that are constant? :)


This really doesn't hold up at all.

For instance, it's handy to be able to return an array from a method,
some times - the array could fundamentally be part of the instance's
state. However, I want the contents of that array to be effectively
read-only, so that the caller can't tamper with the state of the class
just by using:

byte[] data = instance.StateD ata;
data[0] = 15;

Const-correctness would prevent that (and many similar problems, mostly
to do with collections).

--
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 #85
I have questions for you. Please see below.

"codymanix" <do************ *********@gmx.d e> wrote in message
news:ec******** ******@TK2MSFTN GP12.phx.gbl...
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.
The whole const-stuff in C++ is stupid.


If const-correctness is stupid, does that make it stupid in all of its
forms? For example: are read-only properties and fields stupid? Are you
saying that C# should remove the partial implementation of
const-correctness-support that it already has?

Would support for const-correctness not benefit the class-system designer by
giving him (or her) a whole new degree of control over the users of his
classes? Doesn't const-correctness allow for faster code by removing the
need for unnecessary copies?
Classes should be self-contained,
and therefore everybody should be able to modify them safely. This is
real-world,
or do you know objects in the real world that are constant? :)
What real-world objects are "self-contained?"

If you are thinking of animals, what animal can be safely modified without
restriction?

Which computer programs or class-systems are perfect models of the real
world?

Aren't there objects that cannot be significantly modified by some other
objects? For instance: how could you or I significantly alter the shape of
our galaxy?


Maybe in C++ it was neccesary due to the whole pointer-stuff and so on but
in other
languages it is not.


You hurt my feelings when you refer to C++ in the past tense. It's going to
make a comeback. If C# 2.0 were going to allow for multiple inheritance one
could say it already has.

-- Max
Nov 15 '05 #86
C++ over time has become a language of kludges and fixes that the developer
has to code because the compiler is badly designed in the first place.
"Max Guernsey" <ma**********@h arbingersoftwar e.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have questions for you. Please see below.

"codymanix" <do************ *********@gmx.d e> wrote in message
news:ec******** ******@TK2MSFTN GP12.phx.gbl...
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.
The whole const-stuff in C++ is stupid.


If const-correctness is stupid, does that make it stupid in all of its
forms? For example: are read-only properties and fields stupid? Are you
saying that C# should remove the partial implementation of
const-correctness-support that it already has?

Would support for const-correctness not benefit the class-system designer

by giving him (or her) a whole new degree of control over the users of his
classes? Doesn't const-correctness allow for faster code by removing the
need for unnecessary copies?
Classes should be self-contained,
and therefore everybody should be able to modify them safely. This is
real-world,
or do you know objects in the real world that are constant? :)
What real-world objects are "self-contained?"

If you are thinking of animals, what animal can be safely modified without
restriction?

Which computer programs or class-systems are perfect models of the real
world?

Aren't there objects that cannot be significantly modified by some other
objects? For instance: how could you or I significantly alter the shape

of our galaxy?


Maybe in C++ it was neccesary due to the whole pointer-stuff and so on but in other
languages it is not.
You hurt my feelings when you refer to C++ in the past tense. It's going

to make a comeback. If C# 2.0 were going to allow for multiple inheritance one could say it already has.

-- Max

Nov 15 '05 #87
<di********@dis cussion.microso ft.com> wrote in message
news:u9******** ******@TK2MSFTN GP09.phx.gbl...
C++ over time has become a language of kludges and fixes that the developer has to code because the compiler is badly designed in the first place.


Wow! I have never heard it stated quite so eloquently. I've been looking
for someone like you. I only have one question:

Where do I ship the time machine you're going to use to go back and make
sure that C++ was designed properly? Please make sure that it didn't have
templates so that we dinosaurs are lucky enough to have to sprinkle our code
with typecasts like you advanced C# programmers. Also, if you have time,
can you see to it that multiple-inheritance was replaced by interfaces so
that I can spend my life retyping the same method over and over?

Thanks in advance.


Nov 15 '05 #88
And modern C++ compilers can generally inline small functions.

As Andreas said in the next post, it's because pair is one of those classes
that everything is know about; there is nothing to check, no unknown future
uses. In certain cases there are classes like that, and that's (one of the
reasons) why C# and C++ don't disallow public data members.

Why have several lines when two will do?
"codymanix" <do************ *********@gmx.d e> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
"Stu Smith" <st*****@remove .digita.com> schrieb im Newsbeitrag
news:eO******** ******@TK2MSFTN GP12.phx.gbl...
I'd just like to butt-in on question 12, public fields. One of my

favourite
C++ questions (with no right or wrong answer) is: "given that we don't

like
public data fields, and given that the people who implement STL libraries are pretty smart, why is pair<A, B> generally implemented with two public data fields?"


Uuuh...Performa nce? But wait! What was the Jit good for?
Yes, it can automatically inline calls to Properties. So what?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #89
> The whole const-stuff in C++ is stupid. Classes should be self-contained,
and therefore everybody should be able to modify them safely. This is
real-world,
or do you know objects in the real world that are constant? :)


I've missed the first part of this discussion, so forgive me if someone has
already said this:

One of the really useful reasons to be able to specify that a function does
not change one of its operands is for self-documentation.

In C++, if you see that a function argument is declared with a const-ref
operand, you need look no further to know that calling that function will
not change the operand. (I'm ignoring erroneous code which casts away the
const in the function - such code is buggy).

In C#, whenever I pass a reference-type to an unfamiliar function, I need to
consult the documentation and/or inspect the function's implementation in
order to determine whether the operand may be changed.

What's more, if I am the implementer of such a function, I can easily forget
and change the operand. If it could be const, then the compiler wouldn't
allow you to.

Now I realise that you can argue that you should always fully consult the
documentation for any function. But the lack of const can make you have to
search more of the code, particularly in the face of incomplete or possibly
out-of-date documentation. Even worse, the documentation may say that the
function doesn't change it's operand - and that may well have been true when
the documentation was written. Alas, a later maintenance programmer has
optimised the code in the function somewhat, and as a side-effect has
changed the operant. Blam! There's a bug that would instantly be caught if
you had constant operands.

As another example, suppose you were looking at some code that used a Matrix
class. You come across this function:

Matrix m1 = new Matrix( 4, 12 );
....
Matrix m2 = invert_matrix( m1 );

You consult the documentation and find that it says: "invert_mat rix returns
the inverse of the specified matrix". And that's about it (about from some
info about possible exceptions and un-invertable matrices). Now, of course,
you have to go and inspect a load of complicated matrix-inversion code just
to see if the operand is changed.

You see, it's all about code clarity and self-documentation.
Nov 15 '05 #90

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
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,...
0
10610
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
7854
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
7030
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...
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
4087
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3141
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.