D vs. C#

Yigal Chripun yigal100 at gmail.com
Sun Oct 21 03:54:14 PDT 2007


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
regarding properties - even in D they aren't perfect:
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#.



More information about the Digitalmars-d mailing list