Microsoft Releases C# Language Reference
Snoop Baron writes: "Microsoft has released information about C# on their Visual Studio homepage; the article includes an early version of their C# Language Reference. After having browsed the C# Language Reference PDF I believe they have made some mistakes that Java thankfully avoids. What do you think?"
C hash
See C hash run
run c hash CRASH
C# $%^&
Because if you don't C sharp, you'll B flat. :P
--
Hand me that airplane glue and I'll tell you another story.
...it apparently just relies on the same standard class libraries as VB and friends. ugh.
DNA just wants to be free...
Java doesn't let you use primitives (int, short, etc) as classes without wrapping them yourself (lots of overhead). ... C# does.
So what? syntactical sugar, nothing more.
Java doesn't let you drop down to native code and turn off the garbage collector if you need to. Or use pointers if you want to talk to the underlying C-based OS. ... C# does.
Translation : Java doesn't allow you to break its programming model and create very intentionally unstable code. C# does.
If you want Object Oriented programming with raw C-like access to the O/S, use C++. That's what its there for (ask Bjarne. he says this every time the subject comes up).
Java doesn't have a "foreach" statement. ... C# does.
Syntactical sugar. Easily done by adding a foreach functional object (see C++ STL), using the collections classes. Yes, I'd rather see real generic programming (no casts) in Java like it is in C++, but until that's there, make do.
Java doesn't have property-handlers (eg. write functions that are treated as member variables - eg: a.setName("MyName") would become: a.Name = "MyName" - but it would still go through a function. These are great for encapsulation. C# has it - Java doesn't.
Syntactical sugar. I'd rather the code explicitly tell me that a function is or isn't being called. When i can't instantly look at a line of code and go "that's not calling a function" (which in C#'s case, i can't), then i won't trust the code.
Java doesn't have any versioning mechanism (other than the woefully inadequate @deprecated tag). ... C# does.
So C# now forces you to keep all of your mistakes around in every single file, just like other MS products like the Office file formats? No thank you. Roughly translated, C# mandates Code Bloat automatically for you.
Java doesn't support indexers (methods on a class - say List, which allow you to take the object of type List, and use it like an array - eg: List l; l[index] = "asjdasid" C#, however, does.
Syntactial sugar. In C++, that's operator overloading. I didn't realize "l.get(index)" was so fucking hard to type or read.
The Big Three (Ritchie, Stroustrup, Gosling) each said in the C++/Java Report interview that there was certainly room for more languages, possibly derived from the C family, provided it truly fulfills a programmer's needs.
But C# doesn't answer programmers' needs. Its a syntactical "wish list" that I can do without. Using these examples, I can write a C# subset preprocessor to translate into C++ in a day (note : i've not read the spec, only this checklist).
But I don't need it.
"But remember, most lynch mobs aren't this nice." (H.Simpson)
-- Joe
On the first day, Bill and Paul created BASIC, and MITS users rejoiced and made many illegal copies.
On the second day Bill created Micro-soft, such that when MITS tanks and Pertec buys it thinking they'd get BASIC, they didn't (nyah, nyah nyah!!)
On the third day Bill purchased QDOS and sold it to IBM - the IBM compatible crowd granted Msft a DOS monopoly and it did fill the coffers to a great overflowing.
On the fourth day Bill release Windows3, a grotesque abomination, yet being tied to the DOS monopoly it quickly ascended to 90% market share.
On the fifth day Bill unleashed a horde, Windows 95 to punish the Win3 desktop users and bind and chain them to a GUI standard, and a monsterous NT to abolish Novell, the faster file server in the
land, and to cause grevious crashing and blue screens of terror in the server room.
On the Sixth day, Bill embraced the Internet,
which at first arose and suprised the great Msft and threatened to make it obsolete, yet Bill fought back with the vigor of the damned and with the most agressive and grevious of bundlings tied IE to Windows, which was tied to the ancient DOS monopoly, thus fooling even the wise as to the Internet's true origins.
On the Seventh day, waxing vastly bolder still, Bill calls forth all demons at his command to punish the MITS software pirates and the people of Earth who are like them, enslaving humanity with strange proprietary languages, capturing even the guardians of hades, confusing their minds and drawing them into labyrinths of law and insanity.
And thus it is that the people of Earth were smitten and chained to their workstations of everlasting pain and damnation, yet suffer it greatly for it is by their own seeming choice.
And the great demon cackled with glee.
try { do() || do_not(); } catch (JediException err) { yoda(err); }
Wow, they've done the impossible. I just took a brief glance at the introduction to C#.
Here are some impressions:
- Similar syntax to Java with some annoying, non functional differences (e.g. Uses instead of import)
- No synchronized keyword or equivalent. This makes the language not very suitable for serverside development.
- No dynamic binding (at least I didn't see it mentioned). This is a key advantage of Java over C++ and allows for run time loading of new classes that may not even have existed at compile time.
- Non functional syntactic sugar. At least I don't see the advantage of having structs or enums when you can have inner classes or something similar.
- No inner classes. Another usefull feature of Java.
- No security model. Yet another feature that they forgot to implement. I guess you are stuck with whatever ActiveX does for you.
- No templates. Java developers have been screaming for this feature and several third party variants of Java exist providing this highly usefull feature. It is lacking in C#.
- Single inheritance. Glad to see that they adopted this limitation.
- Transparent use of COM objects. I suppose that is usefull but what about CORBA or JavaBeans?
- destructors, C++ syntax but Java semantics (i.e. finalize).
- No preprocessor. Apart from memory management, the preprocessor is probably the largest source of maintenance headaches so Yay!
Compelling reasons not to use C#:
- you gain little or nothing if moving from VB
- you loose a lot if moving from either Java or C++
- All C# objects are com components, so they are usable from outside C#. Why bother using it then?
- Vendor lock in. Do I need to explain this?
- Immaturity of language. If Java is a good example of how fast language adoption goes. It will take several years for C# get mature.
- It does not address the needs of Java users, C++ users or VB users.
- It does not contain anything you can't find in another language.
I sincerely hope this will die quickly. I know that MS can do better. I'm waiting for news on their intentional programming project for instance. This looks like it was implemented by their marketing department.
Jilles
Just after looking at this document I just wonder why it's called C# and not Java# because it's seem just about the same except for the "runs only on Windows platform" thing.
Java doesn't let you use primitives (int, short, etc) as classes without wrapping them yourself (lots of overhead).
C# does.
Java doesn't let you drop down to native code and turn off the garbage collector if you need to. Or use pointers if you want to talk to the underlying C-based OS.
C# does.
Java doesn't have a "foreach" statement.
C# does.
Java doesn't have property-handlers (eg. write functions that are treated as member variables - eg:
a.setName("MyName") would become: a.Name = "MyName" - but it would still go through a function.
These are great for encapsulation. C# has it - Java doesn't.
Java doesn't have any versioning mechanism (other than the woefully inadequate @deprecated tag.
C# does.
Java doesn't support indexers (methods on a class - say List, which allow you to take the object of type List, and use it like an array - eg:
List l;
l[index] = "asjdasid"
C#, however, does.
Need I continue?
Simon
Coming soon - pyrogyra
Combining C++ and Java does not strike me as an especially laudable goal. Mix up two Algol-family languages? Ugh.
As for the rest of the stuff, it actually isn't so new at all. Self, developed at Stanford and Sun, did all of these starting in the late eighties.
Sounds like a monstrously slow language, doesn't it? It's not. Self is the language that pioneered JIT compilation, and ten years ago ran benchmarks at 50% the speed of optimized C while maintaining full debuggability, GC, arbitrary precision ints, checking for stack overflow and a whole host of other goodies.
As for Java taking performance hits for bytecodes, keep in mind that JIT compilation can often produce better code than static compilation. JIT compilers can do all sorts of things that would fuddle offline compilers, like unrolling loops all the way to be perfectly flat. Takes memory - so what? We're throwing it out after a thousand iterations. Spend your time optimizing the code that actually is being used by observation in the field, rather than slogging through profiler output on test data.
As always, look before you say something is new - someone may have done it before.
-----
Klactovedestene!
Hey, you know I bet Sun is just shaking in their boots... yeah right. The biggest problem Microsoft has is defining any of these kind of standards right now it the same problem they had with Visual J++ and Visual C++. They are so Windows-centric that they forget about the importance of portability. Like MFC, and half the other shit they make which ends up stangling a developer to a particular platform. There's a reason Java will remain popular, and that's Sun's devotion to portability and stability.
kicking some CAD is a good thing
"enables developers to quickly build a wide range of applications for the new Microsoft .NET platform"
.NET.
Ahh, so that's what it's for.
It's sorta like, Visual C++ lets you make apps for Windows.
This lets you develop for
.NET, I certainly have mixed emotions about. As I do with this language... Most aren't positive, but at least the concepts seem to have their hearts in the right place.
.NET almost seems like it is preparing for Linux to become more dominant, as it mentions "built-in support to turn any component into a Web service that can be invoked over the Internet-from any application running on any platform." "Which could have been said built-in support to turn any component into a Web service," were it not trying to leverage the image a certain way...
Just a few thoughts.
Eh...
Yes, it can hide bugs. But on the other hand, it hides bugs reproducibly - i.e. if your program unwittingly depends on a variable being initialized, it's bad code, but at least it's code that's guaranteed to work. It can't fail in some bizarre situation as with uninitialized variables.
I still prefer the Java approach of having the compiler make sure there are no uninitialized locals (though sometimes it can bite back when you outsmart the compiler and it can't recognize a valid initializing situation). But note that global variables are guaranteed initialized - because Java can't make sure they're always initialized (that would entail a costly program-wide analysis), so it too sacrificies bug unmasking for guaranteed identical and correct exceution by initializing them all itself.
Well, I haven't yet had time to read the C# info -- since it's nicely enclosed in a Windows executable, making it useless for we Mac folks. However, it seems to me that Microsoft is doing a good job of trying to alienate developers as much as possible. I still have no desire to pick up what seems to be a platform-specific version of Java, when I have the platform-independent Java -- which, I might add, seems to be gaining firmer ground.
On that note, though (no pun indended)... What is to become of Java now that Microsoft has its own version? Certainly other operating systems will continue to support it, particularly Solaris and Mac OS X, but will Java support be dropped from later versions of Windows and how badly will this hurt the language?
Why objective C? The mac team at microsoft has been developing office, ie, etc for OSX for some time, and the higherups like the speed at which they are coming along. Obj C also has more tools for compiling cross platform, and MS is looking to take a lot of the same application apis and develop them on both NtT(2000) and OSX. Also, it looks like they are having some serious performance issues getting the C# compiler to spit out code that is clean on anything but a solid intel instrcution set. the optimizion sucks on alphas and ppcs, and there are even some strange little bugs that pop up when an app compiled on an pentium runs on an athlon and vice versa. This language has a long way to go, and given the alternatives, it looks like it make become like activeX. still there, but sucking balls and not doing anything useful.
On the whole, Microsoft seems to have taken Java, added many of the things people were asking for, and called it C#. Barring any big blunders, it's not a bad language. It's "give the customer what they want", but whether that is prudent language design is another question.
But, then, Java is evolving. And that's the crucial point: it's fairly easy to write a language description. It's much more difficult to implement it, work out the gotchas and bugs in it over years of practical use, and actually deliver a high performance, robust implementation with as many features as they stuffed into C#. Java may yet end up incorporating many of those features before C# even sees the light of day (if ever).
What should Java take to heart from this list? My favorites are: by-value structures, foreach syntax, automatic boxed/unboxed conversions, true multidimensional arrays, multiple classes per source files, checked/unchecked arithmetic, get/set methods, and conditional compilation. I think Java also ought to get a generic tuple type. All of those could be implemented without any changes to the JVM (by-value structures would require a new class attribute to actually make a difference in terms of performance). In fact, there are a number of extended Java compilers that do just that.
So, C# is a reasonable idea, but when it comes down to it, it's just like many other Microsoft "me too" announcements. Microsoft just can't seem to let anybody else define or lead an effort. But I don't think they'll be able to take over the world with this one. Java is pretty good, it's quite mature, and it's adding new features at a reasonable pace. Java will get most of C#'s features sooner or later, without changes to its VM. And Java has a big edge over C# when it comes to libraries. Even if Microsoft ever figures out technically how to hook up the Win32 API to C# (and doing that well is tricky), I doubt the result will be anywhere near as comfortable, complete, and safe as the Java APIs.
Hello, world
The canonical "Hello, world" program can be written as follows:
using System;
class Hello
{
static void Main() {
Console.WriteLine("Hello, world");
}
}
The source code for a C# program is typically stored in one or more text files with a file extension of .cs, as in hello.cs. Using the command-line compiler provided with Visual Studio, such a program can be compiled with the command line directive
csc hello.cs
which produces an executable program named hello.exe. The output of the program is:
Hello, world
Close examination of this program is illuminating:
o The using System; directive references a namespace called System that is provided by the .NET class library. This namespace contains the Console class referred to in the Main method. Namespaces provide a hierarchical means of organizing the elements of a class library. A "using" directive enables unqualified use of the types that are members of the namespace. The "Hello, world" program uses Console.WriteLine as a shorthand for System.Console.WriteLine.
o The Main method is a member of the class Hello. It has the static modifier, and so it is a method on the class Hello rather than on instances of this class.
o The main entry point for a program - the method that is called to begin execution - is always a static method named Main.
o The "Hello, world" output is produced through the use of a class library. The language does not itself provide a class library. Instead, it uses a common class library that is also used by languages such as Visual Basic and Visual C++.
For C and C++ developers, it is interesting to note a few things that do not appear in the "Hello, world" program.
o The program does not use a global method for Main. Methods and variables are not supported at the global level; such elements are always contained within type declarations (e.g., class and struct declarations).
o The program does not use either "::" or "->" operators. The "::" is not an operator at all, and the "->" operator is used in only a small fraction of programs. The separator "." is used in compound names such as Console.WriteLine.
o The program does not contain forward declarations. Forward declarations are never needed, as declaration order is not significant.
o The program does not use #include to import program text. Dependencies among programs are handled symbolically rather than textually. This system eliminates barriers between programs written in different languages. For example, the Console class could be written in another language.
[---]
Looks like a bastard child of C and Pascal. A Borland influence, maybe?
--
Evan
"$30 for the One True Ring. $10 each additional ring!" -- JRR "Bob" Tolkien
I just read through the language reference, here's my impressions of C#.
Being able to assign the get/set accessors for properties is a real plus. I always liked that about Delphi, and wished Java had a better way of doing that. The indexers are also neat. Nothing really revolutionary, but very useful.
Having primitives "boxed" and "unboxed" in objects as needed is also neat. Save loads and loads of that Hashtable.put("number 1", Integer.parseInt(1)) type code that is just a pain in the ass, without sacrificing the performance of making everything an object all the time. I like that.
I also like the foreach statement, as it does make the language a little more expressive (though nowhere near as expressive as Perl.) I like coding in Java all day, but the code is just so bland.
However, there does seem to be a lot of stuff left over from C/C++ days that is sort of questionable. Like the inclusion of structs and enums. The potential performance benefits of structs are intriguing, but losing much of the OOP nature of your code is not attractive. Enums seem to clutter the language needlessly.
Delegates are interesting, but it seems as if most of the functionality provided by them could also have been accomplished with use of interfaces. Curious however.
I really dislike the whole notion of the unsafe code blocks, and getting around the garbage colelctor when you want to. Why not use hook in a native interface like JNI to allow that sort of code? Even more, since all oject are COM objects, and since you can pull in outside COM objects so easily, that would seem to be a good fit.
The proliferation of modifiers and qualifiers for methos and classes and variables is quite confusing, but then I expected that, since MS has a heritage of that sort of thing in the Win32 API. Particularly odd is the "internal" modifier. I read it is meant to say "used by this project only." Huh? What happened to inheritance and the like?
In the same vein, I don't fully understand the Attribute support, after several readings. It seems as if you could provide your own modifiers and such, sort of a hybrid interface, but they don't seem to document it much either. How odd. Has anyone made sense of this yet?
The preprocessor can be useful sometimes, I agree, but in many cases it just clutters up the code. I'm somewhat disappointed to see this included. I felt Java's lack of preprocessor was a good step forward.
All in all, it's an interesting language that ties together existing principles and cleans up some of the aspects in the process. But as expected, it's nothing new, and since it is trying desperately to hold on to the legions of Win32 C++ programmers, many concessions were made to old-school thinking at the expense of robustness and security.
Anyone else have comments?
Well, at first glance this doesn't look like an internet language. It compiles into .exe files, and not into bytecodes or anything along those lines.
Of course, this should mean that this is not an internet language, and is just another tool for desktop programs or Windows LANs.
However, knowing MS, this is probably intended to compete with Java despite native compilation. I can even see how that might succeed, in the still-Windows-dominated Internet user environment. This, of course, allows all sorts of brutally bad secuirty holes (native code? hello? anyone home?)
Overall, the language seems to be a cheap replica of Java with some of the statements renamed and a different class set.
Your chronology is incorrect. Active X, the successor to OLE (Object Linking and Embedding), was announced several years before Java. The original purpose was to extend VBXs (Visual Basic Extensions) to other tools. OLE 2.0 was later merged with it. Eventually,ActiveX became "just a marketing term for a collection of technologies" according to Microsoft.
Java was designed for embedded systems (I believe). When the internet came along, it was only an internal project at Sun. Quite a few changes later, the Internet language we think of today was developed.
Given that Java was only half implemented, turning it into an 'internet' technology was easy. ActiveX was designed with entirely different assumptions in mind and couldn't make the leap. Don't assume that C# will follow the same path!
Given one hour to live, the student replied: "I'd spend it with professor FP who can make an hour seem like a lifetime."
Basically, C# is an attempt to combine the features of Java and C++. C# is fully object-oriented (there are no function definitions except as methods) language with many features to make complex programming easier and faster (a la Java).
However, unlike Java, C# compiles to machine code, not byte code. Therefore C# programs do not take the performance hit that Java programs do.
Some interesting features:
automatic garbage collection (can be overridden with the "unsafe" keyword)
explicit pass-by-reference
variables must be initialized before use
every object is a COM object
even primitive types (int, etc.) are objects and methods can be applied to them
no forward declarations
So, it actually IS something new, and (IMO), actually pretty interesting. Now what we really need is GC#, and we may get it, since it was submitted to a standards body.
Thank you for all of your great work in selecting those quotes. You've picked just the right ones that by taking the first word of each, I can decipher their true strategy:
"Embraces emerging Web programming standards"
"Extensive interoperability" (Read: "Extends interoperability"
"Eliminates costly programming errors"
Read the first word of every line... Embrace, Extend, Eliminate! Devious, huh?
Friends don't let friends misuse the subjunctive.
"Eliminates costly programming errors"
What's this, has Microsoft legislated good programming? Like the old saying goes, 'When a programming language is created that allows programmers to program in simple english, it will be discovered that programmers can not speak english'.
"Embraces emerging Web programming standards"E mbraces emerging web programming standards'
Originally 'Creates^H^H^H^H^H^H^HInnovates^H^H^H^H^H^H^H^H^H
"Extensive interoperability"
Everything is a COM object, so EVERYTHING can now be used by malicious ActiveX critters to cause new and improved and more effective destruction!
Read it for what it is, a Microsoft.NET vehicle.
You think I mean the Microsoft collective, don't you? No, I mean the Slashdot/Open Source collective. It seems that most of the people on Slashdot act as one combine collective intelligence, with just as much predudice and non-intelligence as a single person.
As one would expect, almost all of the high-scoring posts here are extremely negative, because the collective holds the opinion that Microsoft can not possibly create something good. Though some of these posts are correct, many are completely wrong. One score 5 post said nothing except that C# allowed implicit variable defining, and that this was bad. C# does not allow any such thing.
Anyone who is looking for an honest opinion of C# should not look here.
BTW, I am not a Microsoft supporter. I use Linux. I am not saying that C# is necessarily good, but it is no where near as bad as everyone here seems to think.
Go ahead, mod me down. I have karma to spare.
------
the following is from a reasonably serious Java developer's point of view:
Obviously this is a Java ripoff. That does not make it bad; in fact, if a language copies the good ideas in Java, that makes the new language good. In my *really* quick glance through the white papers, the best thing they've added are the new things that C# interfaces can define, like events and variables. Java interfaces don't have assertions, and sometimes those are really nice to have.
Bad things:
Speaking of Java itself, wanna bet that Microsoft deep-sixes J++ and discontinues its VM now that it has this, "suggesting" that new developers move to C#?
<spit> Lousy bastards. Would love to have those interfaces in Java, though. :)
"Honey, it's not working out; I think we should make our relationship open-source."
Here's an article from the other architect of delphi on the guy.
He was also the guy behind the WFC for java that started the lawsuit rolling between microsoft and sun.
My god! Do they know what the key signature for that looks like?!? No WAY I'm playing in a key with 8 sharps.
----
I can write in a language that doesn't really exist for a platform (.net) we may never see. Fortunately, I can use a vapor-protocol (SOAP) to communicate between these non-existent apps. I hope that MS will come up with some even-more-proprietary extensions so I can hook it all up to my Cairo-based BizTalk server.
Someday a Slashdot ID of 177180 will mean something.
> My god! Do they know what the key signature for
> that looks like?!? No WAY I'm playing in a key
> with 8 sharps.
Relax; it'll never be more than a minor
language, so there'll be only 4 sharps.
Chris Mattern
Innovations aside, here's what scares me the most:
..uh...27"
Variables in C# are automatically initialized by the environment.
Uh...does this mean they have a little paper clip drop down and say "Looks like you forgot to initialize your variable...don't worry..I'll assign it to