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 7282
> > An array is 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.


Normal objects will be programmed in a way that they will always have a
consistant, well-defined state.
They protect theirselven either through their interface or through thrown
exceptions if a modification is tried
that would result in inconsistent or undefined state.

Generic collections does not have that luxeriority. they are not for a
specific use or context,
they don't even now what types of objects they will hold at a later time.

Providing the ability for generic collections to be readonly makes them
selfcontained, that's all.
At the moment there is the only way to make a collection selfcontained a
wrapper, which is not very efficient.
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.


How's that?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #141
codymanix <do************ *********@gmx.d e> wrote:
Did you have an actual argument against const?
Yes. Since EVERY parameter / variable in C# (rarely used structs excluded)
are passed by reference


No they are not. They are passed by value. The value passed, however,
is a reference. That's an entirely different matter.

Please see http://www.pobox.com/~skeet/csharp/parameters.html

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


I don't think that's necessarily the reason - they may well have
basically run out of time, just like they did for generics.

I wouldn't be at all surprised to see const correctness in a future
version of C#.

--
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 #142
codymanix wrote:
An array is 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.


Normal objects will be programmed in a way that they will always have
a consistant, well-defined state.


This is true for all objects, no matter whether they are normal classes,
arrays or collections, is it not?
They protect theirselven either through their interface or through
thrown exceptions if a modification is tried
that would result in inconsistent or undefined state.
The same here. E.g. an array throws an exception if you try to access an
element past the last one.
Generic collections does not have that luxeriority. they are not for a
specific use or context,
they don't even now what types of objects they will hold at a later
time.
Not true. Generic collections and arrays throw exceptions in certain
situations. So they do enforce their "well-defined state" in certain
situations, don't they?
Providing the ability for generic collections to be readonly makes
them selfcontained, that's all.
At the moment there is the only way to make a collection
selfcontained a wrapper, which is not very efficient.
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.


How's that?


I assume you want to know why const correctness is an interface-only thing.
Short answer: the C++ keyword mutable. Long answer: Sometimes classes have
data members that need to be modified even when you call observer functions.
E.g. you have the following class:

class Polygon
{
public:
// other members

double Circumference() const
{
if ( dirty_ )
{
circumference_ = /* expensive calculation */;
dirty_ = false:
}

return circumference_;
}

private:
mutable double circumference_;
mutable bool dirty_;
};

Lets assume Circumference() is an expensive calculation you only want to
make when you absolutely have to. Logically, Circumference() must be const
as it does not modify the object visibly. However, for performance reasons
you need to cache the result in a member variable. In such situations you
can declare the involved members mutable, what allows you to modify them
even in const functions. So, const only concerns the interface because an
implementer always has complete freedom to modify object state in a const
function. However, he must always say so explicitly by declaring mutable all
data members he wants to modify in a const function.

Regards,

Andreas

Nov 15 '05 #143

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com...
codymanix <do************ *********@gmx.d e> wrote:
Did you have an actual argument against const?
Yes. Since EVERY parameter / variable in C# (rarely used structs excluded) are passed by reference


No they are not. They are passed by value. The value passed, however,
is a reference. That's an entirely different matter.

Please see http://www.pobox.com/~skeet/csharp/parameters.html

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


I don't think that's necessarily the reason - they may well have
basically run out of time, just like they did for generics.

I wouldn't be at all surprised to see const correctness in a future
version of C#.

While it would be a noble feature, as has been expressed several times by
various MS employees(I can probably still find references if you want 'em)
because .NET & C# didn't have const in the beginning, the vast amount of
existing code(the framework most notably) that has no concept of const may
make it as much of a silly issue as it is in C++(cast it away easily, etc).
Realistically, adding const to C# really would mean adding it to the BCL or
its usage would be *heavily* marginalized. Just as adding optional exception
specs would effectivly do no good because a very large portion of
functionality doesn't have them, its an issue that will have to be
addressed.
--
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 #144

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

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com...
codymanix <do************ *********@gmx.d e> wrote:
> Did you have an actual argument against const?

Yes. Since EVERY parameter / variable in C# (rarely used structs excluded) are passed by reference
No they are not. They are passed by value. The value passed, however,
is a reference. That's an entirely different matter.

Please see http://www.pobox.com/~skeet/csharp/parameters.html

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


I don't think that's necessarily the reason - they may well have
basically run out of time, just like they did for generics.

I wouldn't be at all surprised to see const correctness in a future
version of C#.

While it would be a noble feature, as has been expressed several times by
various MS employees(I can probably still find references if you want 'em)
because .NET & C# didn't have const in the beginning, the vast amount of
existing code(the framework most notably) that has no concept of const may
make it as much of a silly issue as it is in C++(cast it away easily,
etc).


I don't feel const in C++ is silly.
Casting away const is possible, but a competent programmer will do so only
as a last resort. Casting away const on an object that is actually declared
const, not just a reference to const to a non const object, is undefined
behavior. The implementation is allowed to do anything without you having a
right to complain when you write code with undefined behavior. Given that if
you have a need to cast away const you probably wont _know_ wether the
actual object is declared const.....

In C++ const is a statement that the object may not be modified, not a
guarantee that it won't be. For a certain definition of better, i't might be
possible to do better in a managed environment. See below.
Realistically, adding const to C# really would mean adding it to the BCL or its usage would be *heavily* marginalized. Just as adding optional exception specs would effectivly do no good because a very large portion of
functionality doesn't have them, its an issue that will have to be
addressed.

I don't feel that having code around which doesn't utilize the safety net
makes the net any less useful to those that do use it. There's no security
feature or good design practice that is used always in all code. I don't
believe that is any reason not to use them all in your own code, or that it
takes anything away from the gain you, your coworker and clients receive
from using it. It does however mean that const in C# would have to be like
in C++, possible to cast away. In a managed environment however, it might be
possible to have an exception automatically thrown if an attempt is made to
modified a non mutable field.

As for the BCL I'd certainly expect it to use const correct code if const
was introduced. Yes, it would be quite a lot of work and possibly have to be
staggered over a few releases.

Regards /Magnus Lidbom


Nov 15 '05 #145

"codymanix" <do************ *********@gmx.d e> wrote in message
news:uL******** ******@TK2MSFTN GP12.phx.gbl...
> 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.

The same question still applies: How will the subsystem that manages the
cache set up the data?
Do you feel that an XML document object should have it's own data access
layer?
Did you have an actual argument against const?


Yes. Since EVERY parameter / variable in C# (rarely used structs excluded)
are passed by
reference

Jon already corrected you here.
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. You don't need to specify that the method takes a const parameter at the
call site. In fact you can't. You speak as if you remember "hell" in C++,
but what you say only demonstrates that you don't even know how const in C++
works. Changing your method to modify it's argument will cause problems only
if it is passed arguments that are const. And that is exactly the point to
having const. Not modifying instances that may not be modified. That is a
boon, not a problem.
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. An how are references any different?
In C#, strings are immutable and all collections provide readonly
wrappers.

Yes, there are cases where the need for const was so pressing that
the long way around of writing entire extra classes to do the job was
chosen since const isn't around. And this still, after all that work,
results in runtime errors instead of compile time errors, since the type
system cannot tell the purpose of the wrapper. And there is no standard way
of doing this, or of obtaining the readonly wrapper. The result: more work,
more reading docs, more confusing code, more time necessary for
maintenance, more bugs.

How does this mitigate the need for const?

/Magnus Lidbom


Nov 15 '05 #146

"codymanix" <do************ *********@gmx.d e> wrote in message
news:u3******** ******@TK2MSFTN GP12.phx.gbl...
Normal objects will be programmed in a way that they will always have a
consistant, well-defined state.
They protect theirselven either through their interface or through thrown
exceptions if a modification is tried
that would result in inconsistent or undefined state.


Const is not about ensuring an object has a consistent and well-defined
state. It is about ensuring that the state does not change from one
consistent well-defined state to another. If an object's state changes when
the programmer assumes it won't, it may be disastrous even if the new state
is consistent and well-defined.

Sami
Nov 15 '05 #147
"Magnus Lidbom" <ma***********@ hotmail.com> wrote in
news:bv******** ****@ID-204195.news.uni-berlin.de:
"Frans Bouma" <pe************ ******@xs4all.n l> wrote in message
news:Xn******** *************** **********@207. 46.248.16...
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?


With my tool, LLBLGen Pro, I supply templates which generate code
in 2 different paradigms: selfservicing and adapter. Selfservicing
contains persistence info per entity. adapter uses a central repository
for that. Selfservicing requires this info in the entity because it has to
be able to execute code like this:

CustomerEntity customer = new CustomerEntity( "CHOPS");

that creates an entity object instance of type Customer and fetches the
entity data with PK "CHOPS" from the database into this new entity
instance. This code has to be able to function completely decoupled from a
central repository, so the data is carried with the entity. THe other
model doesn't use this paradigm, as it uses a central 'adapter' class
which handles all actions with the persistent storage and which retrieves
persistence info for an entity at runtime from a central repository
(singleton object store)

However I don't see why it would result in huge memory problems.
The thing is: you don't carry around an entity for a long time that often,
it's not that wise to load 1000s of entity objects into memory anyway, if
you want to load a list of data for example. You then can better use
readonly lists build ontop of entity definitions which fetch data into a
datatable fast.
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.


The problem is that you should be able to do that on a per-call
basis. Of course, if you as a developer can inject at runtime, mapping
information on a per call basis, it's perfect. I agree that duplicating
information in objects is not that great if it's not necessary. However if
no central object is used, like a central context, broker or other object,
to retrieve/create entity objects, you have to do it this way. Of course
you can create a static class which creates at application start the
repository in core and which is consulted by the entity objects, still,
this can lead to some slowdowns in performance. As I said, duplicated
mapping info at runtime is not that much of a problem, as mapping info is
fairly small and entities are not carried around long, at least they
shouldn't be, due to the fact that an entity that's rather old can get out
of sync sooner or later.

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 #148
"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...
I wouldn't be at all surprised to see const correctness in a future
version of C#.

While it would be a noble feature, as has been expressed several times
by various MS employees(I can probably still find references if you want
'em) because .NET & C# didn't have const in the beginning, the vast
amount of existing code(the framework most notably) that has no concept
of const may make it as much of a silly issue as it is in C++(cast it
away easily, etc). Realistically, adding const to C# really would mean
adding it to the BCL or its usage would be *heavily* marginalized. Just
as adding optional exception specs would effectivly do no good because a
very large portion of functionality doesn't have them, its an issue that
will have to be addressed.


I find this a non-issue. The thing is: *if* const is added, the
developer using const on his own code passing it to a BCL method will run
into trouble and this is correct. For THAT purpose he has to write a non-
const property. IF the BCL is set up correctly it works with base
classes/known interfaces ONLY anyway which do not specify const at all.

If const is added to the spec, developers can finally protect
object states of deep object trees or other objects easily and on a per-
property/method basis. This is essential for code working with THAT code.
It has nothing to do with the BCL, because passing a const object to a BCL
method which modifies it is incorrect by definition, so why should it be a
problem, the developer knows it is a const :)

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'.

That's all fine and clear but these other languages also don't have
the concept of generics in some cases. Furthermore, the future will
probably ask for features to be added some languages don't support. Should
the syntax of COBOL be the limiter on C#'s syntaxis? I really don't see
why. Sooner or later, MS has to let go of the 'common concept', because
it's nog going to work. Is it a tough call you can't use a C#'s object in
..NET Cobol? perhaps for the .NET cobol users, however if that means that
2000 .NET cobol users can limit C#'s syntax, used by millions, I don't
know but then something is seriously wrong with the vision for .NET.

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 #149
"Magnus Lidbom" <ma***********@ hotmail.com> wrote in
news:bv******** ****@ID-204195.news.uni-berlin.de:
Yes, there are cases where the need for const was so pressing that
the long way around of writing entire extra classes to do the job was
chosen since const isn't around. And this still, after all that work,
results in runtime errors instead of compile time errors, since the type
system cannot tell the purpose of the wrapper. And there is no standard
way of doing this, or of obtaining the readonly wrapper. The result:
more work, more reading docs, more confusing code, more time necessary
for maintenance, more bugs.

How does this mitigate the need for const?


Excellent, excellent wordings, Magnus :)

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 #150

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,...
0
10942
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
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();...
0
5696
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...
0
5884
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

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.