473,842 Members | 1,958 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
> > > - unsafe code

I think that if you would not allow mixed managed/unmanaged code, then no one is going to jump on .NET since too much tested code exists and it will take years to port to .NET code. The transition process is slo, but the
programs wil become more and more stable.


.NET has nothing to do with C#. C# is a new language specification with no
support for any kind of legacy code whatsoever.


I was refering to 2 situations regarding unsafe code.

1. C++ .NET creates mixed managed/unmanaged code .NET dll's. In my opinion
these contain "unsafe code".
I program in C# but uses these (unsafe) C++ dll's in order to have something
operational. No need in 2 years development throwing in the garbage and
restart redesigning from scratch.

2. I also convert existing C++ source code to C# code and in that case,
unsafe block is the closest thing to the original C++ code, and the fastest
way to convert things.

I would be crazy to tell my boss that I need 2 years development before he
gets the next release of the version of the program that does exactly the
same thing I have now. No, I prefer to start using C# using existing and
tested unsafe C++ code, to extend my program, and when I find time the
unsafe C++ code gets converted to safe C#.

Basically I would never jump to C# if I didn't have the possibility for
unsafe code in the transition process.
Nov 15 '05 #31
> > > - Objects can't exist on the stack
Objects on the stack are an open door to the dreaded buffer overflows.
I think that this is a very good step forward towards stability of the
software.


Which dreaded buffer overflow are you referring to? How is allowing

structs on the stack okay while objects aren't?

It isn't!! Structs on the stack can cause buffer overflows too, this is why
I avoid the struct in the first place and use the class instead.
I only have one struct in my code, and that is to dynamically map a record
to a file that I read in. This file has variable size records.

Bufferoverflows will still exist in classes, but if they are not located on
the stack, then it cannot be misused by worms and viruses as return address
to execute code.


Nov 15 '05 #32
> *** NO MULTIPLE INHERITANCE ***!!!

Biggest fault of C# in my opinion.

Multiple enheritance makes the code pretty complex and almost unreadable
adding more potential bugs to the code!
So far I never needed it, and I did write >1 million lines of code in Delphi
and C++ in the last 11 years.
Nov 15 '05 #33
<Ol**********@s kyscan.be> wrote:
It isn't!! Structs on the stack can cause buffer overflows too, this is why
I avoid the struct in the first place and use the class instead.


In safe code, you can't have buffer overflows. If you believe you can,
please give an example.

--
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 #34
> > C# allows non-deterministic destructors:
Garbage collection with destructors means the destructors can be called
at unpredicatable moments
during execution.
That is the nature of GC. The thing to remember is: you shouldn't use
destructors for deterministic management (eg. clean-up) of resource

(that's what Dispose is for). Destructors are there as a safety net in case a
consumer doesn't explicitly call Dispose. The Dispose pattern in my opinion is valid, because the only way to get deterministic finalization, is if the consumer knows he needs something to be managed "now" - so he MUST call
something... whether that something is a memory deallocation keyword or a
Dispose function is rather irrelevant. Bottom line: if you want to know that clean-up code is being called "now", use Dispose. That is deterministic. Of course, C# isn't the only language that uses a GC and deals with the same
issue, but I'm betting you don't like any of them either ;-)

In my opinion, Constructors and Destructors should only perform actions that
guarantees that it will not crash.
Mainly initializing variables, allocating memory, copying,....

Then we have a second set of methods that actually open an close
files/resources/connection/....
This way, a file is closed, memory freed, connections closed,... outside the
destructor and it doesn't matter then when the destructor is then called.

Nov 15 '05 #35
> > It isn't!! Structs on the stack can cause buffer overflows too, this is
why
I avoid the struct in the first place and use the class instead.


In safe code, you can't have buffer overflows. If you believe you can,
please give an example.

Probably not, but if you use structs then you also probably need unsafe code
blok too because I do not see any other reason to use Structs than to map
the structs to a memory block. For example, loading a file in binary data
and map the structs to that memory in a dynamic way.

I would not know why I would use structs for something else.
Nov 15 '05 #36
<Ol**********@s kyscan.be> wrote:
It isn't!! Structs on the stack can cause buffer overflows too, this is
why I avoid the struct in the first place and use the class instead.
In safe code, you can't have buffer overflows. If you believe you can,
please give an example.


Probably not


More than that - definitely not!
but if you use structs then you also probably need unsafe code
blok too because I do not see any other reason to use Structs than to map
the structs to a memory block.
So you don't use ints, DateTimes, bytes etc yourself? Those are all
structs.
I would not know why I would use structs for something else.


Convenient stack-based allocation, basically, and simple value
semantics.

--
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 #37
> > > > It isn't!! Structs on the stack can cause buffer overflows too, this
is
> why I avoid the struct in the first place and use the class instead.

In safe code, you can't have buffer overflows. If you believe you can,
please give an example.


Probably not


More than that - definitely not!

Don't bet on that "definitely not!".
Hackers are very resourcefull people you know.
I would not know why I would use structs for something else.


Convenient stack-based allocation, basically, and simple value
semantics.

I very rarely need these things like that so far.
I avoid custom made Structs, I prefer to use the classes instead, far more
flexibel in use.

Ints, DateTime and other generic structs are logical to use, but so far even
in C++ I do not need custom structs unless using it as a memory mapper.
Everyone programs in a different way. ;-)
Nov 15 '05 #38
"Andreas Huber" <ah****@gmx.net > wrote in message
news:40******** **@news.bluewin .ch...
A poorly written library is going to be poorly written, no matter
what. in a RAII-type world, they can make mistakes. in the
IDisposable workd, they can make mistakes.... are you saying that
c++ is less prone to resource management mistakes by library vendors
than c#?


I would say that C++ with non-deterministic finalizers, would be a
much worse C++. That's all.


Why? Are you suggesting that GC, Finalization and Dispose is more
error-prone than C++ style reference-counted pointers and RAII?


No I am not suggesting that, you are mis-attributing something that is
completely unrelated to what I stated.

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

"Andreas Huber" <ah****@gmx.net > wrote in message
news:40******** **@news.bluewin .ch...
christopher diggins wrote:
"Sami Vaaraniemi" <sa************ ***@jippii.fi> wrote in message
news:bv******** **@phys-news1.kolumbus. fi...
While some of your comments about C# do have a point, most of the
time the case is that you can work around the issues in one way or
another.
Yes I agree there are work-arounds for a good programmer. But nothing
to prevents less experienced programmers from going in and doing a
heck of a lot of damage. My problem is using other people's code,
which is crucial for any kind of serious development.


Which is true for just about every language feature. Writing good programs
always has required and always will require thoughful use of the language
features one has at his/her disposal. As always: A fool with a tool (or C#
for that matter) is still a fool.
One *can* write much more expressive code because of C# attributes and
that's all that matters. BTW, the same is true for C++ macros (much less
frequently though).


The argument that all features that increase flexibility are neccessarily
equally good falsely assumes that all potential for programmer error are
also equivalent. Some language features lead to relatively insignficant
bugs, while others lead to potential disastrous consequences. For more on
the differences between classes of programmer error see my article on scale
of magnitude for Programmer Error in Programming Languages at
http://www.heron-language.com/scale-of-errors.html.

On the other hand to lend support to your argument there is a definite
advantage of increased expressiveness. I need to give credit to C# for
achieving that.
Regards,

Andreas


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

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
9452
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
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
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
3
3142
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.