473,854 Members | 1,967 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 7301

"Andreas Huber" <ah****@gmx.net > wrote in message
news:40******** **@news.bluewin .ch...
cody wrote:

[snip]
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).


Iam not sure yet was the "indirect visitor" pattern is but iam sure
it can be better
solved using composition or interfaces.

It would be great if you could explain me a little about "indirect
visitor".


Sorry, I meant "acyclic visitor". Here's a good article:

http://www.objectmentor.com/resources/articles/acv.pdf


The base classes in acyclic visitor are abstract (no implementation) , and
therefore, they can be expressed as interfaces. While C# does not support
multiple inheritance of classes, it does support multiple inheritance of
interfaces which makes implementing acyclic visitor in C# trivial (see
below).

That said, there are probably legitimate uses of MI where base classes have
implementation, too. In this case you could use composition or delegates to
get similar functionality.

using System;

namespace AcyclicModemVis itor
{
// IVisitor is a degenerate base interface for all visitors.
public interface IVisitor
{
}

// We could make this into an interface, too.
public abstract class Modem
{
public abstract void Accept(IVisitor visitor);
}

public interface IHayesModemVisi tor
{
void Visit(HayesMode m hm);
}

public class HayesModem : Modem
{
public override void Accept(IVisitor visitor)
{
IHayesModemVisi tor hv = visitor as IHayesModemVisi tor;
if (hv != null)
{
hv.Visit(this);
}
else
{
Console.WriteLi ne("*** ERROR: {0} cannot visit HayesModem",
visitor.ToStrin g());
}
}
}

public interface IZoomModemVisit or
{
void Visit(ZoomModem zm);
}

public class ZoomModem : Modem
{
public override void Accept(IVisitor visitor)
{
IZoomModemVisit or zv = visitor as IZoomModemVisit or;
if (zv != null)
{
zv.Visit(this);
}
else
{
Console.WriteLi ne("*** ERROR: {0} cannot visit ZoomModem",
visitor.ToStrin g());
}
}
}

//-------------------------
// ConfigureForDOS Visitor
//
// This visitor configures both Hayes and Zoom modems
// for DOS.
//
public class ConfigureForDOS Visitor : IVisitor, IHayesModemVisi tor,
IZoomModemVisit or
{
public void Visit(HayesMode m hm)
{
Console.WriteLi ne("ConfigureFo rDOSVisitor visiting {0}", hm);
}

public void Visit(ZoomModem zm)
{
Console.WriteLi ne("ConfigureFo rDOSVisitor visiting {0}", zm);
}
}

//--------------------------
// ConfigureForUni xVisitor
//
// This visitor configures only Zoom modems for Unix
//
public class ConfigureForUni xVisitor : IVisitor, IZoomModemVisit or
{
public void Visit(ZoomModem zm)
{
Console.WriteLi ne("ConfigureFo rUnixVisitor visiting {0}", zm);
}
}
class MainClass
{
[STAThread]
static void Main(string[] args)
{
// Create a bunch of modems to visit -
// in DOS, we have both Zoom and Hays modems
Modem[] dosModems = new Modem[] {
new ZoomModem(),
new HayesModem(),
new ZoomModem(),
new HayesModem()
};

// In Unix, we have only Zoom modems
Modem[] unixModems = new Modem[] {
new ZoomModem(),
new ZoomModem()
};

Console.WriteLi ne("Visiting DOS modems...");
ConfigureForDOS Visitor dosVisitor = new
ConfigureForDOS Visitor();
foreach (Modem modem in dosModems)
{
modem.Accept(do sVisitor);
}

Console.WriteLi ne("\nVisiting Unix modems...");
ConfigureForUni xVisitor unixVisitor = new
ConfigureForUni xVisitor();
foreach (Modem modem in unixModems)
{
modem.Accept(un ixVisitor);
}

Console.WriteLi ne("\nTrying to visit DOS modems with Unix
visitor...");
foreach (Modem modem in dosModems)
{
modem.Accept(un ixVisitor);
}
}
}
}

Nov 15 '05 #111
.. wrote:
Comparing C++ (unmanged) to C# is like apples to oranges, both are
fruits but very very different.

However if you comprae C++/CLI to C# then I will listen. Both are in
the same world, managed.


What the heck has that to do with const correctness (there is an
experimental C# compiler that supports const)?

Regards,

Andreas

Nov 15 '05 #112
> C# is the exact oposite. C# goes a long way to protecting
programmers from themselves, and boosts productivity at the cost of being
less flexible.
You aren't serious? Where is C# less flexible than C++? The ability to
change public
fields into Properties at any time is a good thing which isn't possible in
C++.
In C++ you have to rethink lots of things when you are attempting to change
a line of
code since you can introduce a lot of suble bug the compiler cannot catch
for you.
When you think Flexibility=="I can do every stupid thing I want, the
compiler won't hinder me" then yes, C++ is more flexible.
However, clearly both are needed, and neither language is
going to die anytime soon. Hell, if COBOL is still around, just imagine how long C++ will be ;-)

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

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #113
> > the problem with const correctness is if you change your mind and want
that
a method is able to change the parameter, you have to change all const
specifiers in the whole library and all dependent apps!


No, that's the *good* thing about const correctness. Otherwise, all
that changes is the documentation (you do document whether or not
methods will change data within parameters, don't you?) and people may
well not notice. They may well be making an assumption that you're
*not* going to change things. At that stage, the code is broken, but
you don't know it. With const correctness, the compiler *tells* you
that the code is broken, and you can examine every invocation of the
method and see whether it's still okay or whether you need to create a
copy.


Assumed I have a class Called DB_Connection. Further assumed I have
a method Read() in it. Knowing that a Read() doesn't alter the connection
itself I make the method const. Every clint that uses my class gets a "const
DB_Connection"
passed since they don't need to change the object.

Now I have the idea to increment a counter in the connection each time the
Read() method is used. Now what? I have to remove const from the Read()
method.
Additionally I have to remove const from every variable/parameter which
passes a "const DB_Connection". Stupid, isn't it.

Nobody should care about wheather an object is altered since you can always
safely alter a self-contained object. Additionally this encourages
programmed to make their objects more selfcontained and safe.

The only problem still are not fully selfcontained generic containers like
pointers arrays and lists. You can use a readonly wrapper here, an
enumerator or an readonly indexer.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #114
Attributes
[Transaction"Aut oComplete"]

cuts out so many transaction management steps.

unsafe

when the going gets too experimental, unsafe is the way out because it
is usually the experimental who really holler over techniques (they
possess or have borrowed is of course a different issue) that are not
supported by technology.

Microsoft(?!)
I wouldn't talk too much if I were you about a company which can really
buy the mud out of everywhere just to get to know the critique and its
supporters!

The rest of course have been tackled better by others.

with regards,
J.V.Ravichandra n
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandra n+J.V.&cob=aspn etpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID= P3966388&BN=999 &PN=2
- Or, just search on "J.V.Ravichandr an"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #115
>Normally you don't have to care wheather an object is changed or not since
all objects should be self-contained


Of course you must care! Whether an object is changed or not is crucially
important - the fact that an object is self-contained is completely
non-sequitor! You appear not to really understand the issues.

Nov 15 '05 #116
Cody -- see inline

"cody" <do************ *********@gmx.d e> wrote in message
news:bv******** ****@ID-176797.news.uni-berlin.de...
C# is the exact oposite. C# goes a long way to protecting
programmers from themselves, and boosts productivity at the cost of being less flexible.
You aren't serious? Where is C# less flexible than C++? The ability to
change public
fields into Properties at any time is a good thing which isn't possible in
C++.


That's not at all true. The __declspec(prop erty) has been around for some
time... By many novice VC++ programmers, it is often overlooked as just a
COM extension (and in fact, the documentation leads one in that conclusion),
but it's there and it works well (albeit not a particularly portable
construct)... For the programmer that implements it, it is rather tedious -
but for the consumer/client of the class, it is just as efficient and
cosmetically appealing as class properties in other implementations .

Consider this rather absurd hack:

/* *************** *************** *************** ** */
class SomethingWithPr ops{
public:
__declspec(prop erty(get=get_Hi ddenValue,put=p ut_HiddenValue) )
int PropValue; // not the real value, just a crutch for the declspec
private:
int realValue; // yep - this is the real property value
SomethingWithPr ops(){
PropValue=0;
}
public:
int get_HiddenValue (){return realValue;}
void put_HiddenValue (int val){realValue= val;}
static SomethingWithPr ops* Create(){
return new SomethingWithPr ops();
}
};
/* *************** *************** *************** ** */
int _tmain(){
Console::WriteL ine(S"Hello World");
SomethingWithPr ops *a = SomethingWithPr ops::Create();
a->PropValue = 100; // doing a property in VC++
printf("This is the value from property: %d",a->PropValue);
return 0;
}
In C++ you have to rethink lots of things when you are attempting to change a line of
code since you can introduce a lot of suble bug the compiler cannot catch
for you.
That's not true for the general case (and consider subtle versus suble).
The probability of introducing a bug when changing a line of code is vastly
more dependent upon the level of expertise of the programmer (and the
general degree of attention being offered by the programmer) making the
change.

Novice VB/C# programmers can write pretty sophisticated apps. Novice C++
programmers get in a heap of trouble. Expert VC, Expert C#, and Expert VC++
programmers are, for all intents and purposes, equally good at 99.9% of the
apps. The problem is that great time lag between expert level amongst the
languages cited.
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.

However, clearly both are needed, and neither language is
going to die anytime soon. Hell, if COBOL is still around, just imagine

how
long C++ will be ;-)

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...
regards
roy fine

--
cody

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

Nov 15 '05 #117

"cody" <do************ *********@gmx.d e> wrote in message
news:bv******** ****@ID-176797.news.uni-berlin.de...
Nobody should care about wheather an object is altered since you can always safely alter a self-contained object. Additionally this encourages
programmed to make their objects more selfcontained and safe.


This is just wrong. Self-containment has little to do with constness.

Consider e.g., the CDC class in MFC that wraps the Windows device context.
CDC has an internal state that includes knowledge of all GDI objects
currently selected into the device context. The class is self-contained in
the sense that you cannot access the state directly (unless you access the
underlying device context handle but that is beside the point).

The class has a bunch of const methods, e.g., void DPtoLP(LPRECT lpRect)
const. The constness means that the user of the class can safely call the
member function and not have to worry whether the object's internal state
changes because of the call. This is a big deal.

If the method was not const, you'd have to pour over the documentation to
see whether the method changes the internal state. If the documentation is
vague on this point, you might end up saving the object's state prior to the
call and restoring it afterwards, just to be on the safe side. This would be
a major inconvenience and also a performance hit.

Regards,
Sami
Nov 15 '05 #118
> 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?
There should be constant fields and constant(immuta ble) classes, but not
constant objects.
You cannot change someones eye-color. This applies to ALL human, so it would
be stupid to say:
you can change the hair color of this human but not the haircolor of that
human.
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?
making a class immutable makes copies also avoids copiing and allows faster
code,
without having the disadvantages of c++ const correctness.
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?"


ALL real world objects are self-contained. Once ocreated, you cannot modify
the
genetic structure of a lifeform. But you can cut its head off for example,
nobody can
prevent you doing this.
If you are thinking of animals, what animal can be safely modified without
restriction?
If you don't want that someone touches the animal don't give it to him or
make a box(wrapper) around it.
Which computer programs or class-systems are perfect models of the real
world?
Programs are for the real world and are modelling real-life processes.
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?
It would be stupid to pass the galaxy to a human. all humans should be
contained in the galaxy.
the galaxy shoud manipulate the humans, not the other way around. if your
program is well designed
you will need no const correctness.
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.


C++ will still be important in 20 years. maybe not as important as today but
it will be there.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #119
[snip]
Sorry, I meant "acyclic visitor". Here's a good article:

http://www.objectmentor.com/resources/articles/acv.pdf

The base classes in acyclic visitor are abstract (no implementation) ,
and therefore, they can be expressed as interfaces. While C# does not
support multiple inheritance of classes, it does support multiple
inheritance of interfaces which makes implementing acyclic visitor in
C# trivial (see below).


Yep, I know. I just posted this because the OP made yet another unfounded
blanket statement:

<quote>
Multiple Inheritance is just bad style used by poor
programmers.
All Multiple Inheritance scenarios are best solved using composition
instead.
</quote>

Note that he isn't distinguishing between classes and interfaces...
That said, there are probably legitimate uses of MI where base
classes have implementation, too. In this case you could use
composition or delegates to get similar functionality.


I think that interface-only MI is enough for most scenarios and that it was
probably a good decision to not provide it for classes as that allows for
spectactular performance improvements with cross-casts.

Regards,

Andreas

Nov 15 '05 #120

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

Similar topics

14
3754
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
2564
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
1954
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
9752
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
10371
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
9518
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...
1
7918
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
7082
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
5750
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
4563
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
4162
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3188
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.