www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D vs. C#

reply Mike <michi_w2001 yahoo.de> writes:
Hi,

I have some advanced knowledge of programming with C and C++.
While I like C for its simplicity and speed, it lacks some important
functionality (like OO). I'm not very fond of C++, since it is quite clumsy.
(But you know all that already)

Anyway, I was looking for a new programming language for little projects. I
looked into the specs of the D language and became quite fond of it. Anyway, I
hear a lot of good things about C# as well.
I am not experienced enough to compare the two simply on the basis of their
specifications. I tried finding some comparison on the internet but failed to
find anything more recent than from 2003.

I was wondering about the advantages of either and languages, and in which case
one is more appropriate than the other and I hope you can help me out!


Many thanks in advance,
Mike
Oct 20 2007
next sibling parent reply Kyle Furlong <kylefurlong gmail.com> writes:
Mike wrote:
 Hi,
 
 I have some advanced knowledge of programming with C and C++.
 While I like C for its simplicity and speed, it lacks some important
functionality (like OO). I'm not very fond of C++, since it is quite clumsy.
(But you know all that already)
 
 Anyway, I was looking for a new programming language for little projects. I
looked into the specs of the D language and became quite fond of it. Anyway, I
hear a lot of good things about C# as well.
 I am not experienced enough to compare the two simply on the basis of their
specifications. I tried finding some comparison on the internet but failed to
find anything more recent than from 2003.
 
 I was wondering about the advantages of either and languages, and in which
case one is more appropriate than the other and I hope you can help me out!
 
 
 Many thanks in advance,
 Mike

C# provides all the niceties of a RAD IDE and a cohesive and very broad standard library. You get this at the price of performance. C# is not native, but runs in a VM like Java. While it does do some JITing, D and other compiled languages will always be faster. Additionally, I think D has a bit cleaner syntax, though C# is a huge step up from C++ in that respect. Oh, and if it matters to you, D templates and metaprogramming blow anything C# has out of the water, yielding the potential for even more performance increases.
Oct 20 2007
parent "Dave" <Dave_member pathlink.com> writes:
"Kyle Furlong" <kylefurlong gmail.com> wrote in message 
news:ffdqe7$pvi$1 digitalmars.com...
 Mike wrote:
 Hi,

 I have some advanced knowledge of programming with C and C++.
 While I like C for its simplicity and speed, it lacks some important 
 functionality (like OO). I'm not very fond of C++, since it is quite 
 clumsy. (But you know all that already)

 Anyway, I was looking for a new programming language for little projects. 
 I looked into the specs of the D language and became quite fond of it. 
 Anyway, I hear a lot of good things about C# as well.
 I am not experienced enough to compare the two simply on the basis of 
 their specifications. I tried finding some comparison on the internet but 
 failed to find anything more recent than from 2003.

 I was wondering about the advantages of either and languages, and in 
 which case one is more appropriate than the other and I hope you can help 
 me out!


 Many thanks in advance,
 Mike

C# provides all the niceties of a RAD IDE and a cohesive and very broad standard library. You get this at the price of performance. C# is not native, but runs in a VM like Java. While it does do some JITing, D and other compiled languages will always be faster. Additionally, I think D has a bit cleaner syntax, though C# is a huge step up from C++ in that respect. Oh, and if it matters to you, D templates and metaprogramming blow anything C# has out of the water, yielding the potential for even more performance increases.

D also supports inline asm, C-like pointer syntax (w/o C#'s 'unsafe' and 'fixed') and easy use of C lib. routines. The price for most of that is a non-moving GC, but I think that those can be developed to rival the speed of the moving GC's. D's built-in array slicing mitigates a lot of the need for a super-fast GC as well.
Oct 20 2007
prev sibling next sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Mike wrote:
 Hi,
 
 I have some advanced knowledge of programming with C and C++.
 While I like C for its simplicity and speed, it lacks some important
functionality (like OO). I'm not very fond of C++, since it is quite clumsy.
(But you know all that already)
 
 Anyway, I was looking for a new programming language for little projects. I
looked into the specs of the D language and became quite fond of it. Anyway, I
hear a lot of good things about C# as well.
 I am not experienced enough to compare the two simply on the basis of their
specifications. I tried finding some comparison on the internet but failed to
find anything more recent than from 2003.
 
 I was wondering about the advantages of either and languages, and in which
case one is more appropriate than the other and I hope you can help me out!

Choosing D over C# makes sense if 1) you care about getting every little last bit of performance out of your code (http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=dlang&lang2=csharp) or 2) you care about your apps not requiring a 20MB runtime/VM to work. and maybe 3 - 3) you care about portability. Though I think Mono makes it a non-issue? Other than that, I haven't used C# but I hear good things too. And obviously the community is much bigger, which translates to greater likelihood that someone will already have code you can steal that does some niche thing you need to do. And Microsoft's C# development tools certainly knock D's out of the water. oh and I forgot #4 reason to use D instead of C# -- 4) you want to be one of the "cool" kids. :-) --bb
Oct 20 2007
prev sibling next sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Mike wrote:

 I have some advanced knowledge of programming with C and C++. While I
 like C for its simplicity and speed, it lacks some important
 functionality (like OO). I'm not very fond of C++, since it is quite
 clumsy. (But you know all that already)

Lots of us escapees from C++ here using D, but myself I know Java more than I do C#. Although Java and C# probably has similar pros/cons when compared to the D language.
 Anyway, I was looking for a new programming language for little
 projects. I looked into the specs of the D language and became quite
 fond of it. Anyway, I hear a lot of good things about C# as well.

You might also want to check out Vala, which looks like C# but compiles to C. More info at http://live.gnome.org/Vala (requires GLib and uses GObject system) --anders
Oct 20 2007
prev sibling next sibling parent reply Yigal Chripun <yigal100 gmail.com> writes:
Mike wrote:
 Hi,
 
 I have some advanced knowledge of programming with C and C++.
 While I like C for its simplicity and speed, it lacks some important
functionality (like OO). I'm not very fond of C++, since it is quite clumsy.
(But you know all that already)
 
 Anyway, I was looking for a new programming language for little projects. I
looked into the specs of the D language and became quite fond of it. Anyway, I
hear a lot of good things about C# as well.
 I am not experienced enough to compare the two simply on the basis of their
specifications. I tried finding some comparison on the internet but failed to
find anything more recent than from 2003.
 
 I was wondering about the advantages of either and languages, and in which
case one is more appropriate than the other and I hope you can help me out!
 
 
 Many thanks in advance,
 Mike

I personally see no reason to use c#. My main points are: 1) it's a poor imitation of Java. Java may have its cons but at least they try to be consistent with the design of the language - every new feature goes through a JSR. this may make the language to evolve in a slower rate though. compare that to the MS approach of including the kitchen sink. the language has many features meant for corner cases which makes it bloated. on the other hand other features were discarded like the covariance of return types, which is heavily used in Java land. 2) who needs another proprietary language?? that's the most important issue for me. the mono project is a VERY stupid idea. it's a lost cause and a wasted effort - trying to play catch-up to MS while it constantly introduces breaking changes to the spec. just look at another project that needs to be compatible to MS - Samba. they need to jump through hoops to make it work - and that project is a necessary evil to make Linux and windows boxes work together. the best way to look at this is through history, check MS' past actions. for example if you look at VB. the new VB.net is a very different beast than the classic VB. from what i hear, half the vb coders like the new features a lot, while the other half claim MS ruined the language. no one asked the community what they want. i also bought software written with .net v1.1 which was abandoned due to .net v2 being not compatible with previous versions, forcing the company to rewrite the software from scratch which they didn't do due to lack of resources. 3) i don't see enough commitment from MS to the .net platform. Sun for example is fully committed to its Java platform as you can see by yourself - most (if not all) of their software is written with Java. can you say the same about MS? I don't think so. besides various toy utilities not even one major piece of software from MS is written with .net. in my book, if even MS itself prefers c++ for its products why should should i think anything different? _conclusion_ - if you want to run on a VM use Java it's open source and free. if you're looking for something more high-level, there are many other languages built on top of the JVM, I'd recommend checking Scala for example. you could also use a dynamic language such as Python or Ruby (i personally like Ruby syntax more). if you want a language that compiles to native code, providing you with all the power of C++ but with all the niceties of a modern language with a GC, than take a deep look at D. note that D is open source, except for the back-end of the official compiler made by Walter. however there is at least one other working compiler which uses gcc as its back-end. all round D is a much improved version of C++ with many new features already built-in in a consistent way. just my thoughts..
Oct 20 2007
next sibling parent reply David Brown <dlang davidb.org> writes:
On Sun, Oct 21, 2007 at 01:25:55AM +0200, Yigal Chripun wrote:

 1) it's a poor imitation of Java. Java may have its cons but at least they 
 try to be consistent with the design of the language - every new feature 
 goes through a JSR. this may make the language to evolve in a slower rate 
 though. compare that to the MS approach of including the kitchen sink. the 
 language has many features meant for corner cases which makes it bloated.
 on the other hand other features were discarded like the covariance of 
 return types, which is heavily used in Java land.

C# fixes many problems with Java, at least in my opinion. C# 2.0 adds generics which cover many of the cases of templates. It has full support of the VM, so executes efficiently and safely.
 2) who needs another proprietary language?? that's the most important issue 
 for me. the mono project is a VERY stupid idea. it's a lost cause and a 
 wasted effort - trying to play catch-up to MS while it constantly 
 introduces breaking changes to the spec.

C# is not proprietary. It is an ECMA and ISO standard. What makes mono stupid? I've done development under mono and found it to work quite well. Where they play catchup is not the language but Microsoft's ever expanding proprietary libraries. A big advantage C# has over D is that it is a standard, and there are multiple implementations. It's tradeoff choices may not be appropriate for all applications (using a VM most importantly). I think for the most part, D is a better language. David
Oct 20 2007
parent reply Yigal Chripun <yigal100 gmail.com> writes:
David Brown wrote:
 On Sun, Oct 21, 2007 at 01:25:55AM +0200, Yigal Chripun wrote:
 
 1) it's a poor imitation of Java. Java may have its cons but at least 
 they try to be consistent with the design of the language - every new 
 feature goes through a JSR. this may make the language to evolve in a 
 slower rate though. compare that to the MS approach of including the 
 kitchen sink. the language has many features meant for corner cases 
 which makes it bloated.
 on the other hand other features were discarded like the covariance of 
 return types, which is heavily used in Java land.

C# fixes many problems with Java, at least in my opinion. C# 2.0 adds generics which cover many of the cases of templates. It has full support of the VM, so executes efficiently and safely.

What exactly is broken in Java that C# does better, in your opinion? from what i see, anything that needs fixing is being fixed within the Java community and I personally trust their decisions a lot more than MS. Adding properties to a languages isn't considered "fixing" it, it's just a convenience feature. On the other hand, removing covariance of return types is a very big mistake. there are others of course, but that one really pissed me off.
 2) who needs another proprietary language?? that's the most important 
 issue for me. the mono project is a VERY stupid idea. it's a lost 
 cause and a wasted effort - trying to play catch-up to MS while it 
 constantly introduces breaking changes to the spec.

C# is not proprietary. It is an ECMA and ISO standard. What makes mono stupid? I've done development under mono and found it to work quite well.

well, who is to prevent MS to publish a new "standard" every year? as I mentioned in my original post, I as a consumer got burnt on this exact issue. I paid 70$ for a piece of software i planned to use until the end of my degree. and that's quite expensive for a student in Israel. That piece of software was only scraped due to inability to port to a newer version of .net in order to support Vista and improve speed. MS didn't provide any way for them to upgrade except for re-writing the whole thing, which the company just didn't have the resources for. conveniently for MS as the company was making a product that competed with One note. and even today there are several features that they implemented much better than MS. that's just one way MS uses to push small ISVs that compete with it off the market.
 
 Where they play catchup is not the language but Microsoft's ever expanding
 proprietary libraries.

you can't really separate a language from it's standard library. almost every piece of code is dependent on that. have you used printf in your C program? well that's part of the standard C library. try to write an application without the standard library, and i assure you you won't get far. unless of course you're writing a kernel and need to implement printf by yourself.i don't think most application developers will go for that. hence, a change in the standard library would have the same effect as a change in the language itself. that's why Java takes a very cautious approach towards changing/deprecating parts of its standard lib. today, i can take a legacy Java 1.1 application and with minimal changes and probably a flag to the VM, i can run it on a modern Java 6 VM. that's a program written about 10 years ago. Can't say the same thing about a program written with any of MS tools.
 
 A big advantage C# has over D is that it is a standard, and there are
 multiple implementations.  It's tradeoff choices may not be appropriate for
 all applications (using a VM most importantly).
 

would you call Microsoft's document format standard? being a standard means being accepted as the default by all parties, not just by one.
 I think for the most part, D is a better language.

i agree fully with that.
 
 David

Oct 20 2007
next sibling parent reply Reiner Pope <some address.com> writes:
Yigal Chripun wrote:
 David Brown wrote:
 On Sun, Oct 21, 2007 at 01:25:55AM +0200, Yigal Chripun wrote:

 1) it's a poor imitation of Java. Java may have its cons but at least 
 they try to be consistent with the design of the language - every new 
 feature goes through a JSR. this may make the language to evolve in a 
 slower rate though. compare that to the MS approach of including the 
 kitchen sink. the language has many features meant for corner cases 
 which makes it bloated.
 on the other hand other features were discarded like the covariance 
 of return types, which is heavily used in Java land.

C# fixes many problems with Java, at least in my opinion. C# 2.0 adds generics which cover many of the cases of templates. It has full support of the VM, so executes efficiently and safely.

What exactly is broken in Java that C# does better, in your opinion? from what i see, anything that needs fixing is being fixed within the Java community and I personally trust their decisions a lot more than MS. Adding properties to a languages isn't considered "fixing" it, it's just a convenience feature. On the other hand, removing covariance of return types is a very big mistake. there are others of course, but that one really pissed me off.

C# has lexical closures, operator overloading, structs, and nullable types. I don't feel as dismissive of properties as you do because, in conjunction with operator overloading, they lead to a much cleaner (IMO) code look and feel than Java. Instead of writing foo.setAmount(foo.getAmount().add(5)); you get the much cleaner foo.Amount = foo.Amount + 5; which you are in fact allowed to rewrite to foo.Amount += 5; Another nice feature is C#'s System.Reflection.Emit package, which allows you to compile new code at runtime -- a useful optimization which can be used, for instance, for regexes. -- Reiner
Oct 21 2007
next sibling parent reply Yigal Chripun <yigal100 gmail.com> writes:
Reiner Pope wrote:
 Yigal Chripun wrote:
 David Brown wrote:
 On Sun, Oct 21, 2007 at 01:25:55AM +0200, Yigal Chripun wrote:

 1) it's a poor imitation of Java. Java may have its cons but at 
 least they try to be consistent with the design of the language - 
 every new feature goes through a JSR. this may make the language to 
 evolve in a slower rate though. compare that to the MS approach of 
 including the kitchen sink. the language has many features meant for 
 corner cases which makes it bloated.
 on the other hand other features were discarded like the covariance 
 of return types, which is heavily used in Java land.

C# fixes many problems with Java, at least in my opinion. C# 2.0 adds generics which cover many of the cases of templates. It has full support of the VM, so executes efficiently and safely.

What exactly is broken in Java that C# does better, in your opinion? from what i see, anything that needs fixing is being fixed within the Java community and I personally trust their decisions a lot more than MS. Adding properties to a languages isn't considered "fixing" it, it's just a convenience feature. On the other hand, removing covariance of return types is a very big mistake. there are others of course, but that one really pissed me off.

C# has lexical closures, operator overloading, structs, and nullable types. I don't feel as dismissive of properties as you do because, in conjunction with operator overloading, they lead to a much cleaner (IMO) code look and feel than Java. Instead of writing foo.setAmount(foo.getAmount().add(5)); you get the much cleaner foo.Amount = foo.Amount + 5; which you are in fact allowed to rewrite to foo.Amount += 5; Another nice feature is C#'s System.Reflection.Emit package, which allows you to compile new code at runtime -- a useful optimization which can be used, for instance, for regexes. -- Reiner

until there's a consistent interface, meaning that there are no differences between a field and a property i would avoid them. for example you can't do someObject.someProperty++; I'm sure that this one is on the list though. generally speaking: I regard properties a a convenience feature because you demonstrated yourself how to implement the same code with Java. properties also allow for more abuse: in strictly OOP design you should avoid getter/setters for every field. the best way to design OOP is if you want to perform an action on some object, send it a message and it should perform it by itself, rather than providing getter/setter and the action performed outside the object. example: --- object.doSomething(params); --- is more OOP correct than: --- a = object.getField(); b = doSomthing(a, params); object.setField(b); --- also compare D foreach loop with Ruby's: collection.each block which is much better from an OOP design point of view. the only place where you _need_ every field to have getter/setter is if you're writing a bean that would be processed by some automated tool like the visual designer of an IDE. properties allow easy misuse of that. with lexical closures you mean delegates, right? well, they are expanded in c# to inner classes. so in fact all the features you've mentioned are either part of the library, or could be part of the library (nullable types) and non provides a true fix for something wrong in Java. all those feature are ways to have shorter syntax than Java. I.E. niceties. most could be achieved in Java, and some would probably be added to Java (there's a debate regarding closures). so in fact nothing is broken in Java, it's just has a verbose syntax that frankly i don't like either. It all come down to prettiness of the syntax, not the design of the semantics of the language itself. on the flip side, how can I get covariant return types without changing the language? and as Janice already replied, you don't get a say with C#.
Oct 21 2007
next sibling parent reply =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
Janice Caron wrote:
 Also, the fact that one can write a getter function without a setter
 function allows one to define properties which are read-only to the
 outside world, but read-write to the containing object, which again is
 something you can't do with a plain member variable.

In C# you can: class Foo { public readonly string Bar = "Hello"; // or public string Baz { get { return m_bar; } } } The first one is read-only everywhere. The second is read-only in the outside but member functions can change the value of m_bar. I still miss read-only local variables, though. -- Julio César Carrascal Urquijo http://www.artelogico.com/
Oct 21 2007
parent Yigal Chripun <yigal100 gmail.com> writes:
Janice Caron wrote:
 On 10/21/07, Julio C=C3=A9sar Carrascal Urquijo <jcarrascal gmail.com> =

 In C# you can:

I think you can in /every/ language. I only posted that point because I disagreed with Yigal who said that properties were a bad thing. =20

and breaking of OOP encapsulation. therefore they are a useful shortcut=20 for experienced programmers but they don't add new functionality to the=20 language and therefore do not fix anything in the language design.
Oct 21 2007
prev sibling parent Yigal Chripun <yigal100 gmail.com> writes:
Janice Caron wrote:
 On 10/21/07, Janice Caron <caron800 googlemail.com> wrote:
 On 10/21/07, Yigal Chripun <yigal100 gmail.com> wrote:
 object.doSomething(params);
 ---
 is more OOP correct than:
 ---
 a = object.getField();
 b = doSomthing(a, params);
 object.setField(b);


Also, the fact that one can write a getter function without a setter function allows one to define properties which are read-only to the outside world, but read-write to the containing object, which again is something you can't do with a plain member variable.

you're correct with you comment but that just shows that you're a true c++ programmer and completely missed my point. I haven't said that fields are better than properties. what i meant was the use of encapsulation from the OOP perspective. In pure OOP, method calls are considered messages to objects and the objects have attached behavior that handles its inner state. if you want to manipulate its inner state, the proper OOP way is to have the object contain such behavior itself and all you need to do is to send the object a message, rather than get its inner state with a getter and perform the action yourself. the latter breaks encapsulation from an OOP perspective. properties are easy to misuse by a programmer to break said encapsulation and implement the latter instead of the former design. that's not to say that getters should be avoided, on the contrary, please do use them when _appropriate_.
Oct 21 2007
prev sibling next sibling parent Yigal Chripun <yigal100 gmail.com> writes:
Janice Caron wrote:
 I don't think the original poster cares about Java though. The
 question was, D vs C#. Java's not a contender.
 
 I love D. It's getting close to everything I want a language to be.
 The features it doesn't have now, it might have in the future, because
 through discussion on this newsgroup, we, the users, get a say. (And
 that is one thing you absolutely cannot say about C#).
 
 I don't like C#. The name (C sharp) suggests it should be geared
 toward writing music, but it isn't. That's just pretentious. Seems
 like just another aspect of Microsoft's attempts at world domination.
 And certainly, you won't get a say in any decision they make.

I completely agree with the above post. regarding your first point: I've mentioned Java, and also a bunch of other languages because I wanted to list all the possibilities I consider worth checking. I didn't even mentioned functional languages yet... Maybe Scheme is a good candidate? I don't know. Personally I like the way D combines the best practices of all styles in a proper way.
Oct 21 2007
prev sibling parent Ary Manzana <ary esperanto.org.ar> writes:
Janice Caron escribió:
 I don't like C#. The name (C sharp) suggests it should be geared
 toward writing music, but it isn't.

I've written a chord-position calculator for a guitar in Java, and I'm sure it would have been much easier in C# because of it's name. At least I wouldn't have to store the string "C#" since I could obtain it by reflection.
Oct 21 2007
prev sibling next sibling parent Ary Manzana <ary esperanto.org.ar> writes:
Yigal Chripun escribió:
 What exactly is broken in Java that C# does better, in your opinion?

The only thing I don't like about Java is that generics are not true generics. They are lost in runtime, the compiler erases the type before compiling. So, for example: class Zoo { void foo(List<Dog> dogs) { } void foo(List<Cat> cats) { } } won't compile, because the method "foo(List)" is duplicated. Also you can't have generics of primitive types...
Oct 21 2007
prev sibling parent reply =?UTF-8?B?SnVsaW8gQ8Opc2FyIENhcnJhc2NhbCBVcnF1aWpv?= writes:
Yigal Chripun wrote:
 What exactly is broken in Java that C# does better, in your opinion?
 from what i see, anything that needs fixing is being fixed within the 
 Java community and I personally trust their decisions a lot more than 
 MS. Adding properties to a languages isn't considered "fixing" it, it's
 just a convenience feature. On the other hand, removing covariance of 
 return types is a very big mistake. there are others of course, but that 
 one really pissed me off.

Auto-boxing in C# works as expected. In Java you have to take care of implementation details that really don't concern to your code: C# Int32 a1 = 1, a2 = 1; Int32 b1 = 128, b2 = 128; Console.WriteLine(a1 == a2); // True Console.WriteLine(b1 == b2); // True Java-the-language: Integer a1 = 1, a2 = 1; Integer b1 = 128, b2 = 128; System.out.println(a1 == a2); // true System.out.println(b1 == b2); // false This is because they cache the first 127 integers as a singleton while you'll get different objects for 128 and up. Also, Generics don't guarantee that a collection will only contain elements of the same type: List<Integer> lint = new ArrayList(); List lobj = lint; lobj.add("hello"); // WTF? And how come in Java you have to check your enums for null before using them? :D void foo(Color c) { if (null = c) // throw something. switch (c) { case Color.red: break; case Color.green: break; case Color.blue: break; default: break; } } Java-the-vm is a great implementation and I expect with anticipation a lot of useful languages to evolve on top of it, but Java-the-language isn't really a great example of language design.
 2) who needs another proprietary language?? that's the most important 
 issue for me. the mono project is a VERY stupid idea. it's a lost 
 cause and a wasted effort - trying to play catch-up to MS while it 
 constantly introduces breaking changes to the spec.

C# is not proprietary. It is an ECMA and ISO standard. What makes mono stupid? I've done development under mono and found it to work quite well.

well, who is to prevent MS to publish a new "standard" every year? as I

And who is to prevent SUN from publishing a new "standard" every year? The might have open sourced it's implementation but they still control the certifications that allow you to call your implementation *JAVA*.
 would you call Microsoft's document format standard? being a standard 
 means being accepted as the default by all parties, not just by one.

Do you mean Microsoft's OOXML? Yes, it was accepted by ECMA last December. I think that qualifies as a "standard". http://www.ecma-international.org/publications/standards/Ecma-376.htm
 I think for the most part, D is a better language.

i agree fully with that.
 David


I'm not defending Microsoft of its monopolistic practices but C# is a very nice language and it has a very comprehensive library with independent implementations. Mono's implementations even has a more liberal license than Java's GPL. I'd like you to take a closer look at Mono's C# and reconsider your position. Of course I still prefer D when speed is important but the huge class library in Mono is certainly appealing. Maybe Tango in a couple of years will be there and this conversation can be dropped. -- Julio César Carrascal Urquijo http://www.artelogico.com/
Oct 21 2007
next sibling parent reply Sean Kelly <sean f4.ca> writes:
Julio César Carrascal Urquijo wrote:
 Yigal Chripun wrote:
 What exactly is broken in Java that C# does better, in your opinion?
 from what i see, anything that needs fixing is being fixed within the 
 Java community and I personally trust their decisions a lot more than 
 MS. Adding properties to a languages isn't considered "fixing" it, it's
 just a convenience feature. On the other hand, removing covariance of 
 return types is a very big mistake. there are others of course, but 
 that one really pissed me off.

Auto-boxing in C# works as expected. In Java you have to take care of implementation details that really don't concern to your code: C# Int32 a1 = 1, a2 = 1; Int32 b1 = 128, b2 = 128; Console.WriteLine(a1 == a2); // True Console.WriteLine(b1 == b2); // True Java-the-language: Integer a1 = 1, a2 = 1; Integer b1 = 128, b2 = 128; System.out.println(a1 == a2); // true System.out.println(b1 == b2); // false This is because they cache the first 127 integers as a singleton while you'll get different objects for 128 and up. Also, Generics don't guarantee that a collection will only contain elements of the same type: List<Integer> lint = new ArrayList(); List lobj = lint; lobj.add("hello"); // WTF? And how come in Java you have to check your enums for null before using them? :D void foo(Color c) { if (null = c) // throw something. switch (c) { case Color.red: break; case Color.green: break; case Color.blue: break; default: break; } } Java-the-vm is a great implementation and I expect with anticipation a lot of useful languages to evolve on top of it, but Java-the-language isn't really a great example of language design.

Technically, the auto-boxing issue is related to the implementation rather than the language design (unless that behavior is actually in the spec). Generics, however, are utter garbage. They are useful as a convenience tool for not manually casting and that's about it. Opinions about MS aside, I think C# is a better designed language than Java. Sean
Oct 21 2007
parent =?UTF-8?B?SnVsaW8gQ8Opc2FyIENhcnJhc2NhbCBVcnF1aWpv?= writes:
Sean Kelly wrote:
 Technically, the auto-boxing issue is related to the implementation 
 rather than the language design (unless that behavior is actually in the 
 spec).  Generics, however, are utter garbage.  They are useful as a 
 convenience tool for not manually casting and that's about it.  Opinions 
 about MS aside, I think C# is a better designed language than Java.
 
 
 Sean

Yes, it is in the "The Java Language Specification, Third Edition" at least: If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2. http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.7 -- Julio César Carrascal Urquijo http://www.artelogico.com/
Oct 21 2007
prev sibling parent reply Robert Fraser <fraserofthenight gmail.com> writes:
Julio César Carrascal Urquijo Wrote:

 Java-the-vm is a great implementation and I expect with anticipation a 
 lot of useful languages to evolve on top of it, but Java-the-language 
 isn't really a great example of language design.

I agree that C# is probably a better-designed language (to a rather small extent) than Java, but I think the reason is "hindsight is 20/20". C# aimed basically to be a better version of Java, since the paradigms and ideas work well for large corporate codebases, and to that extent it worked. I've done very little C# coding, but I do remember appreciating closures (it's a shame D doesn't have them), and I never shed a tear for checked exceptions. I don't agree, however, that "Java-the-language isn't really a great example of language design." For a large codebase, Java is a extremely well-designed language (despite its couple quirks), which is why it has been so successful, and continues to be so successful. I think a lot of people with C/C++ backgrounds look at Java and cite the numerous problems with it, many of which can be wrapped up into the statement "It takes me two pages of code in Java to do what I can in one in C++" or "the performance sucks". The latter of those issues is mostly a non-issue, since if you're running a company running a large server-side software platform with 300 developers or designing a new cellular phone you want everyone to easily deploy applications on, the software engineering benefits of Java far outweigh the slight additional hardware costs. The first point (that coding in C/C++ is easier than in Java) is a more interesting one, but I think it stems from this implicit assumption that Java is just C++ with all the low-level, complex, and cool stuff ripped out. However, I think Java is more like Smalltalk with C/C++ syntax forced onto it. You _can_ write Java like you would C++ and end up with a total mess (look at Descent fro a Java port of the DMD front-end... you'll see what I mean), but at it core, Java is meant to be written in a more object-oriented style than even C++, and the "objects-for-everything" idea actually works. It's just something you need to subscribe to pretty completely; if you're complaining about having to type "new" all over the place or the lack of free functions, you are not one with the zen of OO programming. Of course, I'm a huge Smalltalk fan, and only actually worked to any great extent (more than a few smaller projects) in Java and Perl (the latter of which has scarred me permanently), so I may be a bit biased. In fact, even when I look at D, I'm looking at it from the perspective of a highly OO programming style.
Oct 21 2007
parent =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
Robert Fraser wrote:
 I agree that C# is probably a better-designed language (to a rather small
 extent) than Java, but I think the reason is "hindsight is 20/20". C# aimed  
> basically to be a better version of Java, since the paradigms and 

 well for large corporate codebases, and to that extent it worked. I've done 
 very little C# coding, but I do remember appreciating closures (it's a shame 
 D doesn't have them), and I never shed a tear for checked exceptions.

Off course is strange to call Java a bad example of language design in favor of C# but you should note that the reasons I gave (Namely boxing, generics and enums) *where developed first on C#* and then bolted on top of Java. The hindsight argument doesn't apply to these three reasons. The problem I'm trying to point is that Java-the-language was pretty much dormant since 1995 and then they added these *features* at the same time in Java 1.5 in response to C# 2.0. These leaky abstraction all have broken behavior that they now have to support for, who know how many years. That's what I call bad language design.
 Of course, I'm a huge Smalltalk fan, and only actually worked to any great 
 extent (more than a few smaller projects) in Java and Perl (the latter of 
 which has scarred me permanently), so I may be a bit biased. In fact, even 
 when I look at D, I'm looking at it from the perspective of a highly OO 
 programming style.

I'm still learning Smalltalk (Squeak). I'm at the point where I can understand what a piece of code does but still don't get what is that I gain by writing code in this style. Any pointers to obtain the Zen experience? :D -- Julio César Carrascal Urquijo http://www.artelogico.com/
Oct 21 2007
prev sibling next sibling parent "Janice Caron" <caron800 googlemail.com> writes:
I don't think the original poster cares about Java though. The
question was, D vs C#. Java's not a contender.

I love D. It's getting close to everything I want a language to be.
The features it doesn't have now, it might have in the future, because
through discussion on this newsgroup, we, the users, get a say. (And
that is one thing you absolutely cannot say about C#).

I don't like C#. The name (C sharp) suggests it should be geared
toward writing music, but it isn't. That's just pretentious. Seems
like just another aspect of Microsoft's attempts at world domination.
And certainly, you won't get a say in any decision they make.
Oct 21 2007
prev sibling next sibling parent "Janice Caron" <caron800 googlemail.com> writes:
On 10/21/07, Janice Caron <caron800 googlemail.com> wrote:
 On 10/21/07, Yigal Chripun <yigal100 gmail.com> wrote:
 object.doSomething(params);
 ---
 is more OOP correct than:
 ---
 a = object.getField();
 b = doSomthing(a, params);
 object.setField(b);

I think that's wrong.

Also, the fact that one can write a getter function without a setter function allows one to define properties which are read-only to the outside world, but read-write to the containing object, which again is something you can't do with a plain member variable.
Oct 21 2007
prev sibling parent "Janice Caron" <caron800 googlemail.com> writes:
On 10/21/07, Julio César Carrascal Urquijo <jcarrascal gmail.com> wrote:
 In C# you can:

I think you can in /every/ language. I only posted that point because I disagreed with Yigal who said that properties were a bad thing.
Oct 21 2007
prev sibling next sibling parent reply David Brown <dlang davidb.org> writes:
On Sat, Oct 20, 2007 at 04:49:39PM -0400, Mike wrote:

 I was wondering about the advantages of either and languages, and in
 which case one is more appropriate than the other and I hope you can help
 me out!

A couple of comparisons I can think of. - D does nested classes "right". C# requires you to explicitly put the parent class as a field in the child class, which is clumsy. - C# generics (recent versions that have them) are true strongly-checked generics. Somewhat less flexible than templates, but less prone to strange errors. Some people find them more difficult to understand, I find them clearer. - C# has a stronger separation of managed and unmanaged (gc or not) data. It is more work to call C functions, and it isn't as good at manipulating data structures directly. - The .NET libraries are much richer, a lot more like Tango. Dave
Oct 20 2007
parent Ary Manzana <ary esperanto.org.ar> writes:
David Brown escribió:
 On Sat, Oct 20, 2007 at 04:49:39PM -0400, Mike wrote:
  - The .NET libraries are much richer, a lot more like Tango.

Especially the SortedList, which is... a dictionary! :-P (well, that's the part I hate most of their library: collections... and also that a red-black tree is an internal class)
Oct 20 2007
prev sibling parent Radu <radu.racariu void.space> writes:
Mike wrote:
 Hi,

 I have some advanced knowledge of programming with C and C++.
 While I like C for its simplicity and speed, it lacks some important
functionality (like OO). I'm not very fond of C++, since it is quite clumsy.
(But you know all that already)

 Anyway, I was looking for a new programming language for little projects. I
looked into the specs of the D language and became quite fond of it. Anyway, I
hear a lot of good things about C# as well.
 I am not experienced enough to compare the two simply on the basis of their
specifications. I tried finding some comparison on the internet but failed to
find anything more recent than from 2003.

   

both languages and their respective development arsenal are well suited for a specific pool of tasks. C# has the benefit of a corporate backing with great toolset, vast libraries, good documentation and a large community. Purely as a language, I consider it as mediocre, a better Java as others put it, but this doesn't necessary subtract the potential value of it when combined with the library, IDE, documentation, community and industry support (jobs...). D on the other hand is a better,cool language, with some great potential. Even if right now it's library set is not as vast and orthogonal, progress it made every day on improving the situation. IDE's and debuggers are developed (some already usable), packaging, build and distribution solutions are provided. It's community, even if small, packs a lot of smart people, a situation rarely seen on Java or .Net side :) and you learn *a lot* form them. Now, purely addressing your needs for a language geared towards developing small utilities you have to options(in my opinion of course): If you are distributing your programs to a limited audience like a corporate department or to an environment you can easily control .net + C# is the easiest and painless way. On the other hand if you are distributing you apps. to a larger audience, especially if you are doing it for profit, .Net will cost you dollars! Its large framework and sometimes its perceived lack of responsiveness plus the large resource hogging (a common sin of the VM be it Java or .Net), can be roadblocks for attracting potential users. Here D and its compiled nature can help you greatly, the lack of a vast library is an advantage now as you can control what goes in, the performance is better (if you code correctly) and your users are happy. You will be happier as the language puts a smile on your face most of the times :). That being said I hope I was of some help. Regards, Radu
Oct 22 2007