473,842 Members | 1,853 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
> You think it would mean more typing? Maintainability problems?
Let's compare the way you'd expose a piece of state, that must not be
modified, from your class in C# as is, and with const:

IMHO it is nonsense to protect a selfcontained object from modification.
Please give me one example where you would actually need a object
that must be passed as const. please proof that modification to this object
would
bring your app in trouble.
Please choose not a generic collection (array,list,mat rix) but a specific
real use object.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #131

"cody" <do************ *********@gmx.d e> wrote in message
news:bv******** ****@ID-176797.news.uni-berlin.de...
You think it would mean more typing? Maintainability problems?
Let's compare the way you'd expose a piece of state, that must not be
modified, from your class in C# as is, and with const:

IMHO it is nonsense to protect a selfcontained object from modification.


I'd really like to hear your definition of selfcontained and your argument
as to why this definition renders const obsolete. Noone will be happier than
I if you're right.

Meanwhile, in the world as I know it today:
Unless you can pass a const version around you must copy every single object
passed as an argument if you don't want it modified.

MyClass myObject = new MyClass ();
SomeClass.DoSom ething(myObject );

After this call you don't know what state myObject is in anymore. If you
need to know that it's state is not modified you must pass a copy instead of
myObject. Which means a degradation of performance and more code since
MyClass must implement ICloneable. Most likely, either DoSomething shouldn't
change it's argument, or myObject shouldn't be passed if it musn't be
modified, but without const or a workaround you cannot verify that this is
the case. I believe my last post gave a convincing argument for const over
the the workarounds.
Please give me one example where you would actually need a object
that must be passed as const.
One common scenario with a truly compelling need for const I've encountered
often is when you need to expose application-wide state to subsystems.

Examples:

1. Any subsystem should be able to show a user which permissions he has for
an object. No subsystem but the security subsystem should be able to change
it. Exposing a const version of the data is a simple solution.
(Note that this is not intended to be safe against a malicious programer
only to protect against mistakes.)

2. Inside an Object Relational mapping framework objects containing
information about how classes and fields are mapped to tables and columns
are constantly passed around. None of this information may ever be changed
by the client or chaos ensues.

3. An application caches often read data instead of reading it from the
database. Content templates, security restriction etc is kept in the cache.
None of this may ever be changed by a client.

This is but a few real world examples of one common scenario that I
personally have dealt with.
please proof that modification to this object
would
bring your app in trouble. What do you think would happen if any of the objects mentioned above were
changed?
Please choose not a generic collection (array,list,mat rix) but a specific
real use object.

Those are not real use objects? On what grounds do you feel they should be
excluded from the discussion?

/Magnus Lidbom






Nov 15 '05 #132
cody - see inline.

"cody" <do************ *********@gmx.d e> wrote in message
news:bv******** ****@ID-176797.news.uni-berlin.de...
When you think Flexibility=="I can do every stupid thing I want, the
compiler won't hinder me" then yes, C++ is more flexible.

That is a child-like, absurd interpretation of Flexibility. Please
reconsider.


Erm..Please tell me your definition of Flexibility. Iam not sure what you
meant.


Sure you do -- you are just standing firm, defending a bad statement (that's
OK, we all do it, you just got caught) C# runs in a controlled environment,
and to some extent, so does C++. It is a matter of fact that the C#
environment is more controlling, ergo, the C++ environment is less
controlling. Less controlling may be a better surrogate for flexibility. I
suspect that C# is not first and foremost a replacement for C++, but rather
an alternative or upgrade for classic VB (and I suspect that upgrade is not
the best word for the meaning that I had in mind).

Consider this construct --

/* *************** ************* */
bool someBool = false;
int ival = 220;
/* statement a*/
if((someBool == true) && (ival++ >= 100)){...}

/* statement b*/
if((someBool == true) & (ival++ >= 100)) {...}

/* *************** ************* */

While the major complaint with C++ may oft times be the uncontrolling and
unforgiving way pointers are handled (by programmers and by the language and
by the runtime), it is the arcane idiosyncrasies( note - one person's
idiosyncrasy is another's "must have feature") like above that lead to hard
to debug and even harder to maintain. While statement "a" and "b" in above
seem to generate the same results, it is the issue of the "compound test
short-circuit" and "expression side-effects" that get so many in trouble.
And while it is good syntax, it's quite bad form -- what if you really
wanted the value of ival to increment anfter the test if and only if
someBool is true? What if you didn't????

The if expression in statement "a" is seen as two statements(wher e the
second is evaluated only if necessary). The if expression in statement "b"
is seen as one statement.

To this end, C# is no better than C++ -- the above syntax is valid in MC++,
classic C++ (version 7 of the C++ compiler) and in C# -- and the compiler
warning messages are the same - NONE, and the results are the same....

This is but an simple example of why I thought your
definition/interpretation of Flexibility was uncalled for. The above is
clearly not stupid, the problem is certainly subtle, and the compiler is
quite content.

I would be hesitant to call this a design flaw of the language, rather more
inclined to see it as an unfortunate side effect. But there are many of
these that can ruin an over-hyped demo of a program that you have been
working months on and is the basis of not just the next salary raise, but
continue employment - and one gets better at this by understanding the
language.

regards
roy fine

I don't doubt this. C and C++ will be still popular in 10 years and still used in 30 years.


I don't want to pile on here - but computing will likely change so
dramatically in the next 5 years, that what happens in 10 years will

hardly
be recognized as computing by those that are doing it now...


Hm. Very hard to tell, but lots of stuff have to be backward compatible
and consider the very huge codebase written in C++.

--
cody

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

Nov 15 '05 #133
> Meanwhile, in the world as I know it today:
Unless you can pass a const version around you must copy every single object passed as an argument if you don't want it modified.

MyClass myObject = new MyClass ();
SomeClass.DoSom ething(myObject );

After this call you don't know what state myObject is in anymore.
Does that matter? Selfcontained object should never fear modification.
Please give me one example where you would actually need a object
that must be passed as const.


One common scenario with a truly compelling need for const I've

encountered often is when you need to expose application-wide state to subsystems.

Examples:

1. Any subsystem should be able to show a user which permissions he has for an object. No subsystem but the security subsystem should be able to change it. Exposing a const version of the data is a simple solution.
(Note that this is not intended to be safe against a malicious programer
only to protect against mistakes.)
And what if you forget const? You do not believe yourself that you
"accidently " set a permission in a method.
Why not making 2 different classes: 1 to set the permissions and 1 to get
them.
2. Inside an Object Relational mapping framework objects containing
information about how classes and fields are mapped to tables and columns
are constantly passed around. None of this information may ever be changed
by the client or chaos ensues.
So why don't you make that fields readonly?
3. An application caches often read data instead of reading it from the
database. Content templates, security restriction etc is kept in the cache. None of this may ever be changed by a client.


Make it private?
Please choose not a generic collection (array,list,mat rix) but a specific real use object.

Those are not real use objects? On what grounds do you feel they should be
excluded from the discussion?


They are not selfcontained, so they need protection, either by const,
through a wrapper or through a copy.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #134

"cody" <do************ *********@gmx.d e> wrote in message
news:bv******** ****@ID-176797.news.uni-berlin.de...
Meanwhile, in the world as I know it today:
Unless you can pass a const version around you must copy every single object
passed as an argument if you don't want it modified.

MyClass myObject = new MyClass ();
SomeClass.DoSom ething(myObject );

After this call you don't know what state myObject is in anymore.


Does that matter? Selfcontained object should never fear modification.

Still waiting for this revolutionary definition of selfcontained that
apparently means any code may do anything to any object and everyting will
still work fine.

Until this definition materializes: Yes it matters. It matters a whole lot.
If you can't guarantee the state of the objects you're working with you
cannot guarantee anything about the functioning of the system.
Please give me one example where you would actually need a object
that must be passed as const.


One common scenario with a truly compelling need for const I've

encountered
often is when you need to expose application-wide state to subsystems.

Examples:

1. Any subsystem should be able to show a user which permissions he has

for
an object. No subsystem but the security subsystem should be able to

change
it. Exposing a const version of the data is a simple solution.
(Note that this is not intended to be safe against a malicious programer
only to protect against mistakes.)


And what if you forget const? You do not believe yourself that you
"accidently " set a permission in a method.

Errors are always possible. Const is one way to help minimize them.
What was your point?
Why not making 2 different classes: 1 to set the permissions and 1 to get
them.

Duplicate an entire class hierarchy? An entire security subsystem?
That´s better than writing const where appropriate?
2. Inside an Object Relational mapping framework objects containing
information about how classes and fields are mapped to tables and columns
are constantly passed around. None of this information may ever be changed by the client or chaos ensues.


So why don't you make that fields readonly?

Because many of them are not known when the constructor is called, and many
are collections for which readonly is not meaningful.
3. An application caches often read data instead of reading it from the
database. Content templates, security restriction etc is kept in the

cache.
None of this may ever be changed by a client.


Make it private?

So how will the client read it? How will the subsystem that manages the
cache set up the data?
Please choose not a generic collection (array,list,mat rix) but a specific real use object.

Those are not real use objects? On what grounds do you feel they should be excluded from the discussion?


They are not selfcontained, so they need protection, either by const,
through a wrapper or through a copy.

All collections need const?
Did you have an actual argument against const?

Bear in mind, blanket assertions are not arguments.

/Magnus Lidbom


Nov 15 '05 #135
On Sun, 1 Feb 2004 15:02:46 +0100, "cody"
<do************ *********@gmx.d e> wrote:
> C++ makes a lot use of pointers (arrays, char*, pointers to objects)
> which are not
> selfcontained.


Does a C# array qualify as not self-contained? If no, why not?

An array ios like all generic containers not selfcontained neither in C++
nor in C#.
There must be a way to protect such objects from mofification. either
through
wrappers or keywords.
But for all normal objects no const stuff is required imho.

Cody....
As usual, I suggest you quit while you are behind.

Oz
Nov 15 '05 #136
"cody" <do************ *********@gmx.d e> wrote in
news:bv******** ****@ID-176797.news.uni-berlin.de:
Examples:

1. Any subsystem should be able to show a user which permissions he has for
an object. No subsystem but the security subsystem should be able to

change
it. Exposing a const version of the data is a simple solution.
(Note that this is not intended to be safe against a malicious
programer only to protect against mistakes.)


And what if you forget const? You do not believe yourself that you
"accidently " set a permission in a method.


"What if you forget <abc>... " are non-arguments. If a programmer
forgets to include something, it's a bug. NOT wanting to have a feature
because you can also forget something is silly. What if you forgot to
mention 'ref'... ? still it's available.
Why not making 2 different classes: 1 to set the permissions and 1 to
get them.


Why is it so hard for some people to accept that a given feature
CAN be helpful to SOME people? Why o why do I have to read stupid (yes,
stupid) arguments like "You can also create extra classes to do the same
thing" to counter a feature request over and over again? YOu can also
program C++ in C, just type a lot more code. You don't do it, for obvious
reasons. Why is there a switch statement in C# while if() {} can do it
also. Why is there a while statement in C# while 'for' can do it too and
more compact. Silly things too. They had reasons to include these
(although I still doubt why a while is included) but apparently had
reasons to not include const. I tell you one reason: it was too much work.

having const in C# is a very very nice thing to have. I too have
trouble keeping data readonly and because in my tool it is so incredibly
complex to do that, I decided some time ago to just leave it and not
provide a read-only copy, because it would otherwise result in
implementations of IClonable all over the place. (after all, .NET doesn't
support a deep copy feature)
2. Inside an Object Relational mapping framework objects containing
information about how classes and fields are mapped to tables and
columns are constantly passed around. None of this information may ever
be changed by the client or chaos ensues.


So why don't you make that fields readonly?


You can't do that.
These fields have to be set somewhere by code. Up till today you
can't specify accessor operators in interface definitions, you also can't
define get public and set internal for properties. This means that this
kind of information is changeable.

The example is not that good though. At runtime it's sometimes
handy to be able to change persistence information (if that information is
stored inside the entity that is!) on the fly, for example with dynamic
tables some people use, catalogs/tables chosen on the fly etc.

There are other examples however which suffer from the lack of
const. For example I expose the complete project tree of objects to my
generator framework. This framework uses plugins ala NAnt. I can't make my
project read-only. Normally you don;t change stuff in the project but I
also can't prevent it, or I have to implement IClonable on every class and
that's a hell of a job to do, solely to keep stuff read-only in some
situations. Silly!

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 #137
"cody" <do************ *********@gmx.d e> wrote in message news:<bv******* *****@ID-176797.news.uni-berlin.de>...
C++ makes a lot use of pointers (arrays, char*, pointers to objects)
which are not
selfcontained.


Does a C# array qualify as not self-contained? If no, why not?

An array ios like all generic containers not selfcontained neither in C++
nor in C#.
There must be a way to protect such objects from mofification. either
through
wrappers or keywords.
But for all normal objects no const stuff is required imho.


Yes, you have already expressed that opinion. However, you have so far
not defined what exactly a self-contained object is. Enumerating
classes that qualify vs. ones that do not qualify is not enough. We
need clear-cut rules how to identify such classes.
Neither have you said why you think that one must have the ability to
protect a non-self-contained object from modification while
self-contained ones do not need such protection.
I don't think that further discussion will yield any result as long as
you don't clarify these points.

I may be wrong but my impression is that self-containedness is a
rather foggy property. From what you have said so far it somehow seems
to depend on how open a class' interface is. Yes, I see that some
classes do hide their implementation more than others. But why are
users affected by this fact? Users *always* only see the interface,
they should never assume anything about the implementation. Doing so
would be a good recipe for disaster.
Self-containedness somehow seems to depend on the "difference s"
between interface and implementation so it is possible that two
different implementations of the same interface also differ in
self-containedness. This strikes me as rather odd because const
correctness is an interface-only thing.

Regards,

Andreas
Nov 15 '05 #138

"Frans Bouma" <pe************ ******@xs4all.n l> wrote in message
news:Xn******** *************** **********@207. 46.248.16...
"cody" <do************ *********@gmx.d e> wrote in
news:bv******** ****@ID-176797.news.uni-berlin.de:
<snip>

2. Inside an Object Relational mapping framework objects containing
information about how classes and fields are mapped to tables and
columns are constantly passed around. None of this information may ever
be changed by the client or chaos ensues.


So why don't you make that fields readonly?


You can't do that.
These fields have to be set somewhere by code. Up till today you
can't specify accessor operators in interface definitions, you also can't
define get public and set internal for properties. This means that this
kind of information is changeable.

The example is not that good though. At runtime it's sometimes
handy to be able to change persistence information (if that information is
stored inside the entity that is!)

In this case the mapping information has a one to one relationship to the
type of the object that is mapped. Duplicating the mapping information for
each entity would mean huge memory consumption and very bad performance. Is
there such a thing as an object relational mapping framework that duplicates
mapping information for each entity?
on the fly, for example with dynamic
tables some people use, catalogs/tables chosen on the fly etc.

This framework does not support such functionality at the moment. It might
eventually if a compelling need is demonstrated. However, I see no need to
duplicate the mapping information for each entity in order to implement such
functionality. A single new mapping per scenario should suffice.

<snip>

/Magnus Lidbom

Nov 15 '05 #139
> > > 3. An application caches often read data instead of reading it from
the
database. Content templates, security restriction etc is kept in the cache.
None of this may ever be changed by a client.


Make it private?

So how will the client read it? How will the subsystem that manages the
cache set up the data?


So provide only getter-methods. The method that read from the Database
should be private.
Did you have an actual argument against const?


Yes. Since EVERY parameter / variable in C# (rarely used structs excluded)
are passed by
reference and providing a copy is not always possible, you have to precede
nearly every
parameter / variable that don't need/should not be modified with const.

Should you ever change a const method into a mutating method you have to go
through
the whole application and refactor the whole app. I call this the const-hell

That was bad in C++ and will be even worse in C# due to the reason I gave at
the top.

In C++ const was useful since there were always char* and other pointer
passed around
unprotected and you had no control over who and when something was modified.

In C#, strings are immutable and all collections provide readonly wrappers.

The C# language designers are not stupid peaple. they considered using const
and came to
the conclusing that is is not suitable for C#.

These are similar reasons as the fact that checked exceptions (like in Java)
were dropped.
Overall development productivity.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #140

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
10940
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
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...
1
10670
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
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...
0
9451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.

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.