Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: Re: C++, C# or Java by stvn
in thread C++, C# or Java by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-24 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found