Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: C++, C# or Java

by stvn (Monsignor)
on Apr 02, 2004 at 23:13 UTC ( [id://342180]=note: print w/replies, xml ) Need Help??


in reply to Re: C++, C# or Java
in thread C++, C# or Java

Mono or no Mono, I would not consider C# unless you want to sell your soul to Microsoft. It copies Java (bad idea since Java ain't great anyway) and doesn't really do much but try to subvert it.

I have to disagree with this. C#, IMO, is a major improvement upon Java. Much of what I hated about Java is fixed in C#, and having read many of your gripes about Java in various posts, I actually think you might agree with me.

I hate Java's primative types. IMO, it's a bad attempt by Java's designers to be "pure" about things. Its a pain to upcast primatives into objects, and then the OO syntax is overly tedious. To me its a waste of resources, both CPU and programmer. C#'s approach may not be as "pure", but its alot cleaner for the end-programmer. These 2 lines are basically equivalent:

int i = 5; System.Int32 i = 5;
No tedious new Integer(5) syntax like Java. The simplistic explaination is that int is an alias to System.Int32, but thats not the whole story. The CLR (Common Language Runtime) manages all your types, so int i = 5 is managed as a primative up until it is needed to be an object (System.Int32), at which point the CLR will "box" the (much smaller) primative type into the (really only slightly larger) object type. And because C# has operator overloading (unlike Java), it really makes no difference to your code what it is anyway. It all for free and behind the scences. Sure, this is not okay if we are writing a device driver, but you wouldnt use Java to write a device driver either, so that is of no consequence.

Then there are delegates. I love my anonymous subroutines, I loved them in Javascript, and I love them in Perl (and of course, LISP, SCHEME, etc too). They are the much smarter and sexier evolution of C function pointers. C#, not to be left out in the cold, has delegates. They are basically a type-safe anonymous subroutine on crack! They are too detailed to get into here, but suffice to say, if you ever found your self writing an object in java where all you really needed was an anonymous method, you should check out delegates. (Yes, I know about the Pizza compiler, but thats not Java, thats Pizza).

Casting in Java sucks, its unsafe and a serious source of headaches. And yes, you guessed it, C# is the Extra-Strength Tylenol for your Java headaches once again. Consider the all to common, fetching from a Collection casting idiom:

MyType i = (MyType) c.get(5);
If i is not a MyType derived object, you are in trouble and get an exception. But in C#, you can do this:
MyType i = c.Get(5) as MyType;
If i is not a MyType derived object, you get null in i. Which is much easier to test for than it is to handle exceptions.

And what about foreach, another Perl favorite of mine. C# has it too:

foreach (MyType i in c) { # do something with i }
Thanks to an optimization in the C# compiler this handles all your type casting for you, and just as above, if its not a MyType derived object, its null.

These are just a few things I liked about C#, there is plenty of other cool stuff, like properties and events that really IMO go way past what Java is trying to do in its all too restrictive "pure" OO box. Give it a look, you might like it.

-stvn

Replies are listed 'Best First'.
Re: Re: Re: C++, C# or Java
by flyingmoose (Priest) on Apr 03, 2004 at 00:56 UTC
    all good info, but to be fair to my much despised java, 1.5 is finally adding generics (and foreach loopage). My "copied Java" statement is true at face value. C++, Java, and C# all follow the same basic syntax and paradigm. I'm glad to see casting made cleaner, and exceptions paired down. Casting in java is painful. Yet, it is a rip off -- I was present at several early Microsoft C# dog-and-pony shows, and the similarities were very clear. The reps couldn't even break out a "why this is better than Java" line ONCE -- and when CLR came up, the best they had was "some group in Poland is trying to make C#" work. They don't care -- they just embrace and extend as usual. However my chief beef with them, and this still remains, is they have zero interest in anything but Windows, and the Mono folks are doing their best to clone something they really don't like (Windows Forms), so we're looking at what....GTK for Mono as alternatives? Microshaft isn't going to let that fly. I suppose if you are on a Windows platform, it's probably better than Java (no doubt, hard to be worse) and it may make due if it's still as powerful as C at lower levels, but you still...ultimately...have a language that should have been compiled down to exe (no runtime) and should not be MS specific.

    How is the API? You still bound to MSDN hell? That's another big issue with Microsoft. Inconsistant API's that actually make the inconsistancies (which are many) in Java look tame. Sometimes they take Unicode, sometimes they take UTF-8, always clashing on types... The Windows SDK and DDK are pure evil. How clean are sockets? memory mapped files? authentication? Have these been cleaned up at all from the DDK and SDK? Probably not.

    And our poster is still looking for a good employer language. C# ain't there yet, except in the early adopter type of shops (which, IMHO, are the suicidal shops).

      Bruce Eckel at least thinks that Java's generics may not be such a good idea. article 1, and article 2 give some specifics.
        It is well known what how C++ templates can screw around with debugging and code maintainability. I'm not a big fan of Bruce. He often states the obvious and thinks he invented it. I was just giving a few examples of java *finally* starting to address language deficiencies, but I think they are doing it in a poor way. Checked exceptions are still a royal PITA too -- lots of little nit-picking things here and there add up in the long run.

      java, 1.5 is finally adding generics
      Yes, I heard about that, FWIW C# 2.0 plans to have generics as well, along with (from what i have seen) true anonymous methods, iterators and partial classes (maybe like Eiffel's deffered classes, I am not 100% sure I still have stuff on my "to be read" list about this).
      However my chief beef with them, and this still remains, is they have zero interest in anything but Windows
      Well, can't argue with that, but are you aware of Rotor? It runs on BSD and Mac OS X, granted I tried it early on and opted instead for Mono, but it at least shows M$ cares ;-P
      and the Mono folks are doing their best to clone something they really don't like
      Not being a Mono folk, I cannot really speak for them, but I get the impression they actually do like it.
      I suppose if you are on a Windows platform, it's probably better than Java (no doubt, hard to be worse)
      I'm on Mac OS X,.. and I like it better than Java ;-) but i clearly have some issues, so dont take my word for it.
      How is the API?
      A lot better than the old Win SDK (although my experience with that is very limited), from what I understand though, alot of what was so bad about it before was that it was never really "designed", but instead just clobbered together over the years.

      The C# class libraries are very similar to Java, but being not so strict/purist about OO there are some places where it is alot cleaner. On some level they are very much the same since they provide alot of the same basic services.

      And our poster is still looking for a good employer language. C# ain't there yet, except in the early adopter type of shops (which, IMHO, are the suicidal shops).
      I disagree, my boss has been finding more and more demand for it out there, which was one of the reasons I learned it, so we can get some of that work. We are consultants, so we have to flow along with the trends a lot. It has actually been out for quite a while too, I have BETA release discs going back several years, so its not really early adopter territory.

      And again, no matter what you think about the evil that is M$, the C# and the CLR are pretty well designed and throught out concepts, really not too different that the Perl6/Parrot stuff if you really think about it. But anyway that discussion is for another node.

      -stvn
Re: Re: Re: C++, C# or Java
by podian (Scribe) on Apr 05, 2004 at 16:03 UTC
    Java is also trying to fix these things. In version 1.5, they have:

    a) boxing

    b) generic types (C++ STL)

    c) foreach

    d) bettern version of enum

    and several others

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://342180]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2024-03-28 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found