Slashdot: News for Nerds


Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

C# Under The Microscope

timothy posted more than 13 years ago | from the ooh!-it's-like-a-little-city! dept.

News 389

For anyone not following the story thus far, C# is here, courtesy of Microsoft, Anders Hejlsberg, and a raftload of other languages from which its features are derived (or added to). Napster's Nir Arbel here dissects what C# means to programmers used to other languages, and explains a bit about where it fits into the grand scheme of things. Be warned: Nir takes a pragmatic, low-dogma approach which may be unsettling to some readers. Please watch your head.

To Begin at the Ending

I'm a big fan of programming languages, possibly more than of actual programming. Every once in a while I hear about this new language that is just "brilliant", that "does things differently" and that "takes a whole different approach to programming". I typically then take the necessary time off my regularly scheduled C++ programming, learn enough about the language to get excited about the new one, but not enough to actually do anything useful with it, rave about it for a couple days, and then quietly and without protest go back to my C++ programming.

And so, when I learned of Microsoft's new up-and-comer, C# (pronunciation: whatever), I became duly excited and went forth to learn as much about it as possible.

Last things first: On paper, C# is very interesting. It does very little that's truly new and innovative, but it does do several things differently, and through this paper I hope to explore and present at least some the more important differences between C# and its obvious influences: C++ and Java. So, skipping the obligatory Slashdot "speaking favorably of Microsoft" apology, let's talk about C#, the language.

How is it like Java/C++?

In the look & feel department, C# feels very much like C++. More so than even Java. While Java syntax borrows much of the C++ syntax, some of the corresponding language constructs have a slightly different form of use. While this is hardly a complaint, it's interesting to note that the designers of C# went a little further in making it look like C++. This is good for the same reason it was good with Java. Being a professional C++ programmer, I use C++ way more than any other language. Eiffel, for instance, has a much cleaner syntax than either C++, C# or Java, and at face value it does seem as though one should bear with new syntax if this is going to lead to cleaner, more easily understandable code, but for an old dog like myself, not having to remember so much new syntax when switching to another language is nothing short of a blessing.

C# borrows much from Java, a debt which Microsoft has not acknowledged, and possibly never will. Just like Java, C# does automatic garbage-collection. This means that, unlike with C and C++, there is no need to track the use of created objects, since the program automatically knows when objects are no longer in use and eventually destroys them. This makes working with large object groups considerably simpler, although, there have been a few instances where I was faced with a programming problem where the solution depended on objects *not* being automatically destroyed, as they were supposed to exist separate from the main object hierarchy and would take care of their own destruction when the time was right. Stroustrup's vision of automatic garbage-collection for C++ sees automatic garbage-collection as an optional feature, which might make the language more complicated to use, but would allow better performance and increased design flexibility.

One interesting way in which C# deals with the performance issues involved with automatic garbage collection is that of allowing you to define classes whose objects always copy by value, instead of the default copy by reference, which means there is no need to garbage- collect such objects. This is done, confusingly enough, by defining classes instead as structs. This is very different from C++ structs, which are defined in exactly the same way; C++ structs are just classes where members are public by default, instead of privately. Another idea that was lifted directly off Java, and one which turned out to be very controversial is that of multiple inheritance. In what seemed like a step backwards, Java did not allow you to define classes that inherit from one than one class. Java did let you define "interfaces", which work like C++ abstract classes, but were semantically clearer: an interface is a functional contract that declares one or more methods. A class can choose to "sign" such a contract by inheriting it, and providing a working implementation for every method that the interface declares. In Java, you can inherit as many interfaces as you want. The rationale to all this being that multiply inheriting more than one class raises too many possible problems, most notably that of clashing implementations and repeated inheritance. On a side note, the cleanest separation between interface and implementation that I know of is that of Sather, where classes can provide either implementation or interface, but not both.

So what else is new?

One new feature that I mentioned already was that of copy-by-value objects. This seemingly small improvement is a potentially huge performance saver! With C++, one is regularly tempted to describe the simplest constructs as classes, and in so doing make it safer and simpler to use them. For example, a phone directory program might define a phone record as a class, and would maintain one PhoneRecord object per actual record. In Java, each and every one of those objects would be garbage collected! Now, Java uses mark-and-sweep in order to garbage collect. The way that this is done is this: the JVM starts with the program's main object, and starts recursively descending through references to other objects. Every object that is traversed is marked as referenced. When this is done, all of the objects that aren't marked are destroyed. In the phone book program, especially if there are thousands and thousands of phone records, this can drastically increase the time that it takes the JVM to go through the marking phase. In C#, you'd be able to avoid all this by defining PhoneRecord as a struct instead of a class.

Another thing that C# does better than Java is the type-unification system. In Java, all classes are implicitly descendents of the Object class, which supplies several extremely useful services. C# classes are also all eventual descendents of the object class, but unlike Java, primitives such as integers, booleans and floating-point types are considered to be regular classes. Java supplies classes that correspond with primitive types, and mapping an object-value to a primitive value and vice versa is very simple, but C# makes it that much simpler by eliminating that duplicity.

Personally, I found C# support of events to be a very exciting new feature! Whereas an object method operates the object in a certain way, object events let the object notify the outside world of particular changes in its state.. A Socket class, for instance, might define a ReadPossible event or a data object might release a DataChanged event. Other objects may then subscribe for such an event so that they'd be able to do some work when the event is released. Events may very well be considered to be "reverse- functions", in the sense that rather than operate the object, they allow the object to operate the outside world, and in my programming experience, events are almost as important as methods themselves.

While you could always implement events in C by taking pointers to functions, or optionally in C++ and Java by taking objects that subclass a corresponding handler type, C# allows you to define class events as regular members. Such event members can be defined to take any delegate type. Delegates are the C# version of function pointers. Whereas a C function pointer consists of nothing but a callable address, a delegate is an object reference as well as a method reference. Delegates are callable, and when called, operate the stored method upon the stored object reference. This design, which may seem less object-oriented than the Java approach of defining a handler interface and having subscribers subclass the interface and instantiate a subscriber, is considerably more straightforward and makes using events nearly as simple as invoking object methods.

Events are one example of how C# takes a popular use of pre-existing object-oriented mechanisms and makes it explicit by giving it a name and logic of its own. Properties are another example, even though they're not as much of a labor-saver as events are. It is very commonplace in C++ to provide "getters" and "setters" for private data members, in order to provide controlled access to them. C# treats such "protected" data members as Properties, and the declaration syntax of properties is such that you have to provide getter and setter functions for each property. In fact, properties do not have to correspond to real data members at all! They may very well be the product of some calculation or other operation.

And then, by far the ugliest, most redundant and hard-to-understand language construct in C# is the Attribute. Attributes are objects of certain types that can be attached to any variable or static language construct. At run-time, practically anything can be queried for the value of attributes attached to it. This sounds like the sort of hack someone would work into a language ten years after it's been in use and there was no other way to do something important without breaking backwards compatibility. Attributes are C#'s version of Java reflection, but with none of the elegance and appropriateness. In general, and especially in light of C#'s overall design, the Attributes feature is out of place, and inexcusable.

What is it missing?

Being an unborn language, there is much that C# does not yet promise to deliver, and for which it can't be criticized. First of all, there is no telling just how well it would perform. Java is, in many ways, the better language but one of the prime reasons it's been avoided is its relatively slow performance, especially compared to corresponding C and C++ implementations. It's not yet clear whether C# programs would need the equivalent of a Java Virtual Machine or whether they could be compiled directly into standalone executables, which might positively affect C#'s performance and possibly even set it as a viable successor to C++, at the very least on Windows. While there is much talk of C# being cross-platform, it is unclear just how feasible implementing C# on non- windows platforms is going to be. The required .NET framework consists of much that is, at least at the moment, Windows specific, and C# relies heavily on Microsoft's Component Object Model. All things considered, setting up a proper environment for C# on other platforms should prove to be a massive undertaking, that perhaps none other than Microsoft can afford.

Furthermore, while there is mention of a provided system library, it's not clear what services such a library would provide. C++ provides a standard library that allows basic OS operations, the immensely useful STL and a powerful stream I/O system with basic implementation for files and memory buffers. The Java core libraries go much further by providing classes for anything from data structures, to communications, to GUI. It is yet to be seen how C#'s system library would fare in comparison.

One thing that's sure to be missing from C#, and very sadly at that is any form of genericity. Genericity, such as it is implemented in C++, allows one to define "types with holes". Such types, when supplied with the missing information, are used to create new types on the spot, and are therefore considered to be "templates" for types. A good example of a useful type template is C++'s list, which can be used to create linked-lists for values of any type. Unlike a C linked-list that takes in pointers to void or a Java linked list that takes Object references, a list instantiated from the C++ list template is type-safe. That is to say, it would only be able to take in values of the type for which it was instantiated. While it is true that inheritance and genericity are often interchangeable, having both makes for a safer, possibly faster development platform.

The designers of C# have admitted the usefulness of genericity, but also confessed that C# is not going to support genericity on first release. More interestingly, they are unhappy with C++'s approach to genericity, which is based entirely on templates. It would be interesting to see what approach C# would take towards the concept, seeing as templates are pretty much synonymous with genericity at the moment.

To sum it up

Many now refer to C# as a Java-wannabe, and there is much evidence to support this notion. C# doesn't only borrow a number of ideas from Java. It seems to follow up on Java's sense of clean design. It's a somewhat sad observation then that C#, purely as a language, not only provides a fraction of the innovation and daring that Java did, it also falls just a little behind Java where cleanliness and simplicity are concerned. However, if you're someone like myself, who uses Windows as their primary development platform and needs to use C or C++ because he cannot afford the overhead that Java incurs, it's possible that C# would turn out to be a very beneficial compromise.

cancel ×


java (2)

KeyShark (195825) | more than 13 years ago | (#866880)

Granted Java has an overhead, but it's getting better and better every release. 1.3 with the new VM, hotspot, is incredibly fast. I wish i still had the url of the benchmarking of it. It beat C++ in speed on a couple of tests, granted they were the recursion which C++ doesn't handle well, but Java is getting much better. C# is going to have to show me something besides the speed factor to get me to switch.

Where do functions fit in? (2)

freebe (174010) | more than 13 years ago | (#866882)

Part of the uniqueness of C# is its conception of code reuse - for instance, instead of purchasing a commercial garbage-collector for your C++ code, you get one for free from C#. But where does this garbage collector reside? Is it in a shared library? If so, where and when does it get called? Is it a seperate process fork()ed off from the main process? Does the collector get compiled in to each and every program? Is it part of some system-level component that will be built in to the next Windows, that Linux will have to emulate? Inquiring minds want to know...

Instead of a Microscope... (3)

Dr Caleb (121505) | more than 13 years ago | (#866883)

Perhaps it should be reviewed with a tuning fork?

From all the reviews I've read, "See Sharp" doesn't.

Re:java (2)

vsync64 (155958) | more than 13 years ago | (#866962)

And then there's Lisp! I've seen benchmarks where good tail-recursive Lisp code beat FORTRAN at some numerical tasks.

Okay, obligatory plug over... =)

C# (1)

VAXGeek (3443) | more than 13 years ago | (#866966)

As with any new programming language, I suspect hype is going to factor in. I think this is more of a move by Microsoft to "innovate" a language. This way, there is no competitor at first. For instance, Borland/Inprise is NOT going to come out with a compiler for this right away, if at all, so Microsoft will have the 'best' C# implementation. The only use I can possibly see for it is if it's faster than Java, it'll make a nice language to program Win32 applications (instead of VB). It won't take all platforms by storm, but to Microsoft, all that matters is Win32 anyway.
a funny comment: 1 karma
an insightful comment: 1 karma
a good old-fashioned flame: priceless

Back to C... (4)

pb (1020) | more than 13 years ago | (#866969)

There's a C library that does garbage collection already. Actually, I think there are a few of them.

And it's a shame to not see good template (genericity?) support in C#. Or any language, for that matter.

I think choosing a good type system is where a lot of languages fall flat, and I'm not a big fan of the huge C++/Java Object/Type/Library approach, although I haven't seen a truly good solution to this problem yet. C, Pascal, Java, Perl, Scheme... They all have different ideas and solutions, and I haven't seen a "Right Way" yet. Although I think Scheme has the right idea with its first class data types, it still all needs some work.
pb Reply or e-mail; don't vaguely moderate [] .

This level of language... (5)

Chiasmus_ (171285) | more than 13 years ago | (#866978)

I think this whole "write in languages that are C, but easier" movement that's been going on for decades is a little weird.

If I want to use a medium-level language because I want absolute control and optimized speed, I'll use C. I don't want an "almost-medium-level-but-a-little-higher-than-that -level language". If I was looking for ease of use and didn't care about optimizing, I'd go with PERL, or, hell, even Quickbasic.

Granted, there's a need for these "weird-level" languages, and some people love them - but I think that C++ and Java nicely fill the niche. So, my first thought, which is even more valid, I think, in the face of this review, is "Why does Microsoft feel almost obligated to make an M$ version of *everything*??"

For GUIs and money managers and anything else aimed at "my mom", Microsoft is guaranteed to reign supreme, because "my mom" doesn't really care about performance issues or security or any of that. But my hunch is that, in light of some of the bugs and general ickiness covered in this review, few people are going to want to switch over to C#. I mean, what would be the advantage?? If you already write C++ and/or Java, why would you want to start writing stuff in C#? I just don't understand.

What's the point? (3)

HeghmoH (13204) | more than 13 years ago | (#866979)

Why do we need yet another object-oriented C? We already have C++ (fast but crappy) and Objective-C (slightly slower but way better), what does this C# thing add? I saw no compelling features in it that Obj-C doesn't already provide.

C#: Answer to the DOJ? (5)

KFury (19522) | more than 13 years ago | (#866983)

(I know I'll get thrashed for this, but my karma can take it)

It seems to me that creating a new 'standard' language, which neverltheless relies heavily on COM and .NET ties which only exist on Windows, is in part a tactical method to inhibit migration of Windows products to other platforms.

Let's say that C# is simply a better language to program for Windows than C++ is. Let's also suppose the hypothetical case where new Windows functionality comes along in future Win versions, and that this functionality is more easily taken advantage of using this new C# language. This gives developers the incentive to code new Windows products in C#. Note that C# has substantially different enough structures that porting from C# to C++ would not be trivial.

Now suppose that Linux (or another OS) starts gaining prominence in the next 2-8 years. As with any new OS, its main barrier to entry is lack of software. (The only reason Linux is viable is because of all the UNIX software it inherits.) In this time, Microsoft's pushing of C# has created a new software base for Windows that is relatively locked into place, unable to be ported to other platforms without significant effort.

Now I'm not saying this is evil. I'm not saying it's a conspiracy. Often languages built for specific environments are superior tools in those environments specifically because they're specialized.

It's just something to be aware of.

Kevin Fox

Re:For all the bashing C# gets here... (1)

Golias (176380) | more than 13 years ago | (#866985)

It's a new language form a major vendor. Would you rather we poke our heads in the sand and pretend that the Redmond Empire does not exist?

Re:java (2)

stubob (204064) | more than 13 years ago | (#867002)

and that's only on the application level. I have been hearing for over a year (1.2 release?) that servlets perform much better than cgi. Here's a couple links to evaluated benchmarks. Note the servlet link is from sun, so keep that in mind.
java [] and servlets []

That must be one really fast vm!

My karma is still less than my age.

Copy By Value vs Copy By Reference (2)

Anonymous Coward | more than 13 years ago | (#867007)

What is the difference?

P.S. I'm only 12, so take it easy on me.

All Java's are not created equal (2)

Anonymous Coward | more than 13 years ago | (#867009)

  • Java uses mark-and-sweep in order to garbage collect.
Not always. There are other approaches used, depending on the implementation.

This begs the question: since C# is tied to an implementation (COM), what's the likelihood that there will be competing implementations? On Windows, you have Java implementations from Symantec, IBM, Microsoft, Sun and even an open source one, Kaffe.

How many C# vendors do we expect? GNU C#? When you can't run it on a GNU operating system? Yeah, right.

Re:Back to C... (3)

HeghmoH (13204) | more than 13 years ago | (#867014)

With Objective-C, you can have pointers to objects and not have even the faintest clue what kind they are, yet you can still call their methods. I'm sure many proper OO languages support what you're looking for as well.

Using C# over C++ just for Windows?!? (2)

1alpha7 (192745) | more than 13 years ago | (#867017)

someone like myself, who uses Windows as their primary development platform and needs to use C or C++ because he cannot afford the overhead that Java incurs, it's possible that C# would turn out to be a very beneficial compromise.

If I'm already coding for a Winblows enviro, I already have C++. I damn sure am not switching to some new, barely supported language just for the "new toy coolness" factor.

Re:java (1)

Anonymous Coward | more than 13 years ago | (#867018)

It is impossible for Java to be "faster" than C++. They are just languages. I think what you meant is that a particular implementation of Java produced faster code than that of a particular C++ implementation.

What _I_ Like about C#.. (4)

JackDangers (66689) | more than 13 years ago | (#867023)

Some friends at work recently got back from a MS Developers Conference where they handed out CD's with Visual Studio 7.0 beta and a full version of Windows 2000 Professional (since Visual Studio 7.0 will only run on Windows 2000 Pro.) I loaded it up, read throught the C# book that was included, and was impressed.

C# is highly typed, so you don't spend hours looking through code trying to find a type mismatch.

It is early binding instead of late binding, meaning it is quicker! With Java (late binding), a file search and enumeration of 8000 files on our servers here at work took an hour and a half, and 50000 files with a C(early binding) app took 4 minutes, so C# takes the best of both. Also, because it is early binding, you don't have to worry about references to non-existant objects, when you are using DLL's for instance. C# automatically loads and reviews the routines contained in a DLL automatically, before compile, so a reference to myDLL. will bringup a popup list of the routines availible in that DLL.

Very cool stuff! It will be interesting to see if it takes over as the new, trendy programming language of 2000/2001, as Java has been for a few years.

New languages have potential, but C# doesn't (2)

stuyman (46850) | more than 13 years ago | (#867026)

There are going to be a number of things holding back C# that could've been solved if Microsoft had been designing a real language instead of trying to create a market for their visual studio line:

  1. True innovation: As this article makes clear, C#'s changes are purely incremental, nothing revolutionary is there that justifies the learning curve that a language will always include
  2. Clear, consistent design: C# is like a schizophrenic gerbil. It is stuck half way between Java and C#, and instead of extending them in a reasonable way they change the use of features such as structs.
  3. Non-open runtime librarys: Part of the reason C++ has taken off is because of the libstdc++, and java has taken off because sun has a JVM available for pretty much all platforms. C# doesn't, and the lack of a clear and free standard will relegate it to MSdom the same way VB was. (see my next point)
  4. No Real Standard: If Microsoft treats this like most of their products, each version will make frivolous and yet code-breaking changes to the standard. This means not only can you not keep emulation up to speed easily, but old C# code wont even work in say MSVisualC#3.666

And that's why I'm sticking with C, C++, perl, PHP, sh, and learning Java.

Does anyone have some performance numbers? (2)

Rombuu (22914) | more than 13 years ago | (#867034)

Does anyone who got a beta of the Visual from the MS PDC have any idea on how this performs? I mean, its taken Sun several years to come up with a decent performing VM for Java, and the CRL for C# sounds like it may have similar issues (despite the fact they claim everything runs as native code). If there are substatial performance imporovements from Java, that would definitely be another reason to move toward C# development (the Everything is a COM object is pretty slick too).

I think its interesting that the author of the article says C# has garbage collection like Java. I mean, wasn't LISP the first major language to have garbage collection?

Re:This level of language... (2)

Anonymous Coward | more than 13 years ago | (#867039)

Yes, that's my sentiment, too. It would have been a lot more logical (IMHO) to make the back-end of C# be C instead of compiled code (which I assume it does now). I've never understood why C++ implementations stopped doing this, since C++ itself doesn't offer anything over C. By doing this you'd have the benefit of having all your C# code instantly portable to every platform with a conforming C implementation (i.e. 99.99% of all platforms, and I think that's being conservative).

Re:C#: Answer to the DOJ? (4)

ucblockhead (63650) | more than 13 years ago | (#867040)

I find the concept of "every object is a COM object" worrisome because COM objects are anything but lightweight. Often, as a C++ programmer, I find a problem best attacked with small, lightweight classes, often entirely inline. They help keep the code simple while essentially compiling down to nothing. If every object is a COM object, that ability goes away. That small, lightweight class all of a sudden has all of this overhead to do things that I don't really care about for this particulr problem.

Which gets to a more theoretical problem. The purpose of COM, and models like it, is fairly specific. It is interoperability between seperate running programs, either locally or across a network. But who says I want to share every single object in my program with the outside world? What's the point in having a string class that could potentially be shared between programs if I've got no need to share it between programs?

It seems to me that people are going to find that to get C# programs to perform acceptably, they are going to have to design with big, heavy kitchen sink classes. And that worries me because that sort of design is, in my opinion, one of the biggest downfalls of most Windows software. (Especially Microsoft APIs.) I'm sick of having to instiatiate five classes and code a hundred lines of code just to find out if the damn CD player is in the "playing" state.

It seems to me that this is a case of having a hammer (COM) and seeing every problem as a nail.

If I were designing C#, I wouldn't make every object a COM object. Instead, I'd have some kind of "COMmable" attribute that could make some objects COM objects with little fuss. Put the control in the hands of the programmer.

And this differ's from Delphi how? (2)

sugarman (33437) | more than 13 years ago | (#867042)

Aside from the basic C-language syntax that is the basis for C#. (Serious question, no sarcasm intended. Implied, maybe, but not intentional 8)

With Kylix bringing many of these features to Linux soon, as well as the strength of the VCL and a powerful rad tool that will provide an easy migration path, why is C# a big deal?

Re:What _I_ Like about C#.. (2)

Pfhreakaz0id (82141) | more than 13 years ago | (#867044)

Wow! Early binding and all the advantages that brings... just like VB.

Huh? (GC) (1)

Anonymous Coward | more than 13 years ago | (#867061)

Can anyone make sense of this?

"there have been a few instances where I was faced with a programming problem where the solution depended on objects *not* being automatically destroyed, as they were supposed to exist separate from the main object hierarchy and would take care of their own destruction when the time was right."

Presumably, the objects would have to have their own threads to do this - but if so, then the thread has a reference to the object so it can't be GC'd. What's his problem?

Re:C#: Answer to the DOJ? (1)

Evangelion (2145) | more than 13 years ago | (#867065)

You're acting like current application-level C++ code on Windows can easily ported to Linux.


Re:What's the point? (1)

Anonymous Coward | more than 13 years ago | (#867066)

The one thing that C# does offer is garbage collection. To my knowledge, only POC and Stepstone offer GC, which means that you can't assume that it's there if you're coding in Objective C. Perhaps if NeXT had kept their grubby little hands out of ObjC, implementations would have long ago added garbage collection instead of relying on release pools.

Besides that, though, I agree that C# does seem pretty useless.

For good "template" support: try ML (5)

Tom7 (102298) | more than 13 years ago | (#867068)

ML has an excellent implementation of parametric polymorphism (sometimes thought of as "templates"). You can define a function that counts the elements in a list of anythings:

fun length nil = 0
| length (h::t) = 1 + (length t)

which has type: 'a list -> int
(meaning the function takes a list of anything, and returns an integer).

Through the mechanism called "functors", you can specialize a generic structure (say "sets", or "mappings", or "arrays") with some types and operations to create a new type. Signatures let you make these types truly abstract (paired with type safety, a very powerful notion).

All of this is type safe (with proofs). Most of it is accomplished statically too, so there's little run-time overhead. It is indeed scheme with "some work".

I'm a bit confused. (2)

Shadowlion (18254) | more than 13 years ago | (#867072)

One interesting way in which C# deals with the performance issues involved with automatic garbage collection is that of allowing you to define classes whose objects always copy by value, instead of the default copy by reference, which means there is no need to garbage- collect such objects. This is done, confusingly enough, by defining classes instead as structs. This is very different from C++ structs, which are defined in exactly the same way; C++ structs are just classes where members are public by default, instead of privately.

One new feature that I mentioned already was that of copy-by-value objects. This seemingly small improvement is a potentially huge performance saver! With C++, one is regularly tempted to describe the simplest constructs as classes, and in so doing make it safer and simpler to use them. For example, a phone directory program might define a phone record as a class, and would maintain one PhoneRecord object per actual record. In Java, each and every one of those objects would be garbage collected! [snip] In C#, you'd be able to avoid all this by defining PhoneRecord as a struct instead of a class.

I'm a bit confused.

If I follow this correctly, it's implying that C# is faster (in this instance) because you don't have to mark/sweep through all of the objects allocated in order to garbage collect all of the objects. They've been copied by value, not by reference, so you don't need to hunt down all of the references.

Doesn't this only work, however, if you're actually copying the objects? If I allocate several thousand PhoneRecord objects, but don't assign one to another, wouldn't C# and Java be equivalent in the speed of garbage collection?

It seems like this particular benefit of C# is only useful in a limited number of situations. I can't honestly say that I've ever really needed to create many thousands of objects in Java or C++ by allocating/cloning an existing object each and every time.

Can somebody confirm that this is, indeed, the correct understanding, and perhaps provide a situation where this would be genuinely useful?


Re:Back to C... (1)

Anonymous Coward | more than 13 years ago | (#867073)

Ya, I don't know why people seem to be flocking to the Simula school instead of the Smalltalk school. Objective C is a good argument for how Smalltalk can be compiled and be fast. If you make heavy use of protocols (which admittedly uglies up your code), the difference in performance between ObjC and C is negligible.

Not see sharp (2)

cybercuzco (100904) | more than 13 years ago | (#867074)

I always prononce it "see pound" which makes more sense since most people are farmilliar with the pound key but not the musical notation for sharp. (please enter your voice mail password and press the pound key)

Attributes (5)

EAG (166855) | more than 13 years ago | (#867077)

Attributes aren't really the C# version of reflection; reflection lets you look at the normal things you'd expect it to, and it also lets you look for attributes.

Why should you care?

Well, attributes are really useful in cases where you want to pass some information about the class somewhere else but you don't want to make it part of the code.

With attributes, for example, you can specify how a class should be persisted to XML.

[XmlRoot("Order", Namespace="urn:acme.b2b-schema.v1")]
public class PurchaseOrder
[XmlElement("shipTo")] public Address ShipTo;
[XmlElement("billTo")] public Address BillTo;
[XmlElement("comment")] public string Comment;
[XmlElement("items")] public Item[] Items;
[XmlAttribute("date")] public DateTime OrderDate;

At runtime, the XML serializer looks for those attributes on the object it's trying to serialize, and uses them to control how it works.

You can also use attributes to communicate marshalling information, security information, etc.

The nice thing about attributes is that it's a common mechanism, and it's extensible, so you don't have to invent some new mechanism to do something similar.

Or, to look at it another way, attributes are just a general mechanism for getting information into the metadata.

Garbage Collection (1)

Tom7 (102298) | more than 13 years ago | (#867079)


Defining garbage collection as part of a language doesn't really require you to specify how the compiler should implement it. But most of the time, the garbage collector is part of the runtime system and is triggered on a timer interrupt (or when running out of memory on an allocation). This is all up to the compiler writers to determine.

Re:Back to C... (1)

pb (1020) | more than 13 years ago | (#867090)

That's cool; is there some sort of method naming convention?

What I like about Scheme is that you can query the datatype to see what it is, and it will be an atom or a list; atoms are like scalars, and lists just need to be parsed recursively.

Perl doesn't really support that well for its scalars, and arrays and hashes sort of have their own namespaces, and look like they came from BASIC. But at least you can get types from references.

And C is downright horrible on this because a pointer could be anything! You'd have to make a struct with a field that identifies it, always in the same place, or something similar. But you have the power to do whatever you want... sort of...

On the other side of the fence, Java has a type for everything, and is correspondingly complex, too.

Those are the issues I see, anyhow.
pb Reply or e-mail; don't vaguely moderate [] .

Re:java (4)

odysseus_complex (79966) | more than 13 years ago | (#867091)

I would also like to point out a fallacy in the article. The author states that, "Java uses mark-and-sweep in order to garbage collect," which is incorrect. The JVM spec does not specify which garbage collection algorithm is to be used, much that one must be used. So, the gc could be mark-and-sweep, copying, generational, or reference counted. Heck, it could even be an incremental collector, in which case overall application timing becomes a moot point.

So, in this case, the analysis of time-to-collect is misplaced unless there is reference to a specfic VM.

I recommend reading the VM spec. I've read it 5 or 6 times myself.

Re:Back to C... (2)

Keith Russell (4440) | more than 13 years ago | (#867095)

Actually, in O'Reilly's interview with Anders Hejlsberg [] , Anders mentions that they have generic classes running in the lab:
Hejlsberg: Yes. Microsoft Research in Cambridge has created a generics version of the common language runtime and the C# compiler. We're looking at how to move that forward right now. It's not going to happen in the first release, that much we know, but we are working on making sure that we do things right for the first release so that generics fit into the picture.
He also mentions that generics would be implemented in the Common Language Runtime, which would allow C#, Managed C++, and Visual Basic to all share generic classes.

Every day we're standing in a wind tunnel/Facing down the future coming fast - Rush

Geeks of all flavors (1)

cheezus (95036) | more than 13 years ago | (#867099)

I have to disclaim this post with the following statement. Please do not take it as a troll

I do not like C or C++

ouch. I can feel people's flames already. But here's why: I started programming in basic on an Apple II when I was about 8 years old. Later moved on to Pascal, and then Ada as my college into CSCI courses (yes, Ada and pascal suck dirty balls). Then i learned java. Java and I have a love affair now. Not only did I have an excellent instructor who made me think of the entire world as a bunch of objects, but the language also fits the way I think. Automatic garbage collection is a godsend, and object references make more sense to me than pointers (although some of the pointer arthimetic stuff in C is really cool). I also like strongly typed languages. Strangely enough, I love perl too, mostly for the reason that there are no data types (per se). In perl it makes sense, because of what i use it for... scripting and CGI. But when I am writing a program that i need to function correctly I like to have somebody watching my back. When I was learning C and C++, and to this day when I program in those languages they always manage to compile my code and do stuff they aren't supposed to.

So C# looks pretty cool. Mostly because it looks like it will protect me like Java, and let me program on windoze (I'm not a big fan of windows, but let's face it... I don't get paid for writing free software). I'm wonding how adoped C# will be. Will it be incorporated into DevStudio with VB and VC++? And being an up and comming language, will there be lucritive jobs for the people who know it? I graduate from the University in a couple of years, but i've been looking at jobs and dice and monster to see what's out there, and it seems like aren't a whole lot of java coders comparted to C/C++ coders, thus they get paid more. Is there going to be a sudden demand for C# coders in a few years? if there is, maybe I should start learning it


Re: Pronunciation: whatever... (4)

Dawn Keyhotie (3145) | more than 13 years ago | (#867101)

Well, I'm glad I'm not the only person getting tired of having the (preferred) pronunciation given with every single mention of the languages name: C# (pronounced see sharp). Ugh. How about Java (pronounced Java), C (pronounced see), Eiffel (eye full), Pascal (pascal), perl (perl). No explanation needed there!

Anytime you come up with a name where you have to explain the pronunciation every time you use it, you know that its a real lamer. Its a dead give-away that you worked too hard, stayed up too late, and got too cute.

Of course, there _are_ lots of ways to say C#. I always think 'hash' everytime I see '#', and if you use the hard sound for the letter C, you get K-hash, or simple Cash. Which I think fits, considering the orifice from which it issued.


Re:java (1)

cybercuzco (100904) | more than 13 years ago | (#867102)

not if i can write more code that produces more usable functions in Java than I can in C++ in a given amount of time. In that case Java, as a language, would be faster than C++

Re:What _I_ Like about C#.. (4)

vyesue (76216) | more than 13 years ago | (#867104)

> C# is highly typed, so you don't spend hours
> looking through code trying to find a type
> mismatch. Incompatible type for declaration. Can't convert Context to Community.
Community context = (Context)contextE.nextElement();

yeah, that took a couple hours to track down. phew!

Re:C#: Answer to the DOJ? (1)

KFury (19522) | more than 13 years ago | (#867105)

s/easily/more easily than C# be/

Kevin Fox

power languages (3)

Tom7 (102298) | more than 13 years ago | (#867114)

I think it's an unfortunate misconception that C is the ultimate "power language" because it gives you so much "control". There are lots of advanced languages around (Eiffel, Haskell, ML come to mind) which are more powerful than C precisely because of their restrictions. (You can reason about your programs more precisely since you know certain behavior is impossible). Java has some of this (safety, at least) and I think that makes it better for most applications than C++.

I'll agree with you here, though: aside from a few cosmetic improvements, C# is not really any better than Java.

Weird-level language? (1)

deacent (32502) | more than 13 years ago | (#867116)

Granted, there's a need for these "weird-level" languages, and some people love them - but I think that C++ and Java nicely fill the niche.

You seem to imply OO language where you say weird-level language. I thought that it was just a different design paradigm. Sometimes a project makes more sense if you think of it in objects than in terms of operation.

So, my first thought, which is even more valid, I think, in the face of this review, is "Why does Microsoft feel almost obligated to make an M$ version of *everything*??"

MS has NIH syndrome, plus they have an overwhelming need to be in contol. Not so much for the sake of power. I think it's more that they've become accustomed to making the rules instead of following them. I think that, if they could, they'd create their own variety of oxygen (not backwards compatible, of course).


Re:Using C# over C++ just for Windows?!? (2)

ucblockhead (63650) | more than 13 years ago | (#867118)

Well, as another Winblows programmer, I suspect that the gain would be if you are doing anything in COM. As we both know, doing anything concerning COM in C++ is like banging yourself in the head with a pointy rock. C# seems to make this transparent.

Which also adds a concern in my mind, as I suspect that Microsoft will have lots of incentive to make COM even harder to deal with in C++.

Re:I'm a bit confused. (1)

EAG (166855) | more than 13 years ago | (#867120)

Value types are allocated inline, which means either on the stack or contained within an object.

If, for example, you allocate an array of 1000 value types, you're allocating 1 chunk of memory that's big enough to hold all 1000 objects.

If you do that with a reference type, you get an array of 1000 references to 1000 independently-allocated objects.

Re:For good "template" support: try ML (1)

pb (1020) | more than 13 years ago | (#867122)

That actually sounds really interesting; I'll have to check it out.

I take it there's a bit of a learning curve, though? :)

pb Reply or e-mail; don't vaguely moderate [] .

Re:Where do functions fit in? (1)

EAG (166855) | more than 13 years ago | (#867124)

In the .Net implementation of C#, the garbage collector is in the runtime, and is used by all the .Net languages.

Somewhat related to both points... (1)

TheDullBlade (28998) | more than 13 years ago | (#867126)

What do people cling to C's hideous syntax when they write a new language? Not only is it, IMHO, a bad syntax choice, but it messes you up when you go to learn it and you expect things to work like they did in C.

I wrote a C/C++ preprocessor that lets you use Python-style whitespace-significant code, called Cugar [] to escape the ugliness of C. I just don't understand why people keep pushing back toward it.

Despite rumors to the contrary, I am not a turnip.

Early/Late binding (3)

Acy James Stapp (1005) | more than 13 years ago | (#867138)

I think you are a bit confused about early/late binding. Early binding is the process of determining the address of the function to call (given it's name) at compile, link, or load time. This happens once, so it is fast. Late binding is the process of determining the address of the function to call each time it is called. In C++, late binding is used for virtual functions, and early binding for non-virtual functions.
There are optimizations that enable late-binding to be more efficient (such as a vtable). Java implementations should be able to determine (via the final attribute) that a function can be early-bound instead of late-bound. There are also C++ compilers that can eliminate virtual function calls by doing link-time program analysis.

Re:C#: Answer to the DOJ? (1)

Saint Stephen (19450) | more than 13 years ago | (#867139)

I must correct some things you have gotten factually incorrect. While .NET is AKA "Com+ 2.0", all of COM is gone from it.

No IUnknown, no GUIDs, no stuff in the registry, no IDispatch, no VARIANTs, no DCOM, no RPC (replaced with Soap), and you have implementation inheritance.

It's not COM. It's component based programming but it has completely thrown out all of what was in the "COM" section of MSDN.

Re:java (2)

AMK (3114) | more than 13 years ago | (#867141)

Benchmarking servlets against regular CGI is a bogus comparison. Are servlets faster than Python/Perl/whatever using FastCGI, Persistent CGI, or an embedded Apache module? Are they more convenient to write? Doubtful, on both those aspects...

Re:Does anyone have some performance numbers? (1)

Anonymous Coward | more than 13 years ago | (#867143)

I don't have any raw numbers but I can tell you that it is blazingly fast, faster than any comparable code in Java that I've tested. Because of the way their GC works- sweeping all used memeory into the local cache - it has even beaten similar Visual C++ code. Love them or hate them, this is one of the coolest things I've ever seen from Microsoft. It makes building components and web sites a pleasure. What they've done with Web Services is awesome too.

Re:Copy By Value vs Copy By Reference (2)

PsychoKiller (20824) | more than 13 years ago | (#867148)

I don't know who was the moron who modded this as flamebait.

Anyway, good question. I think what he was referring to here is the habit of C++ to copy objects by copying the address of the variables. This is silly because if you are making a copy of something, you usually want to duplicate it, not just have pointers going back to the original object. I guess what C# does when it is copying is it always does a copy by value, making it easier on the programmer.

I'm not sure how much programming experience you have, so this might be way over your head. When I was twelve I was programming in BASIC, but kids these days are getting smarter.

PS. If you don't know C or C++ yet, learn them! I wish I had learned them when I was young. Instead I wasted my time with BASIC.

Re:What _I_ Like about C#.. (3)

lordpixel (22352) | more than 13 years ago | (#867149)

C++ uses a mixture of early and late binding. So does Java. I'd be stunned if the same wasn't true of C#. Late binding is the only way to do some things. Perhaps C# does more early binding than Java.

Then there's the question of Java's Hotspot, which can remove the late binding overhead in Java at runtime once its optimised a piece of code. It can even de-optimise and switch back to late binding then re-optimise if you starty doing dynamic class loading. This is a big and complex subject, and I'm not sure I could explain it here even if I had the time...

I submit the most likely reason for the performance of your Java program is that it wasn't as well written as the C++ one. Binding is a tiny tiny part of the difference between the 2 languages. There any many other factors which are more likely to account for the difference.

As for the DLL thing - that sounds great - except whe nyou come to deploy your application the user doesn't have the same version of the myDLL that you did on you super dev box. Hence the user gets a reference to a non existant object. Early binding really has nothing to do with this. It sounds like its being used to implement a nice feature in the IDE, not a solution to the age old library versioning problem that people are discussing in the Lets Make Unix not suck thread
Lord Pixel - The cat who walks through walls

Better gc performance? (1)

greysky (136732) | more than 13 years ago | (#867150)

Ok, he tries to make the argument that garbage collection would be faster than in java because you can declare data structures that aren't objects so they won't have to be gc'd, giving the example of a phone number class in java. Then he says that all the primitives are now objects. Doesn't this nullify the performance benefit? Granted the phone number struct is not an object but the number(s) it contains is(are).

Re:This level of language... (3)

J.Random Hacker (51634) | more than 13 years ago | (#867151)

As to why compilers abandoned generating C, I can answer that readily. Two things come immediately to mind.

(1) The ability to do source level debugging is nearly completely lost in translation from C++ to C.

(2) It is much easier to optimize code when you are going from a symbolic representation to RTL or some other near-machine-level representation than it is when going from symbolic code to some other symbolic code with uncertain semantics. While the translation is *possible* the results are not elegant, efficient, or readable.

Programming languages: C++ still king? (1)

AstynaxX (217139) | more than 13 years ago | (#867153)

So far from the various articles and discussions on C#, C++ still seems to come out ahead. How so? here's the short list:

1. C++ allows for you to import and/or write code blocks in C. 2 languages for the price of one in a sense, which is very useful if, say, the C implementation is easier to code up then the corresponding C++ implementation, but you don't want to lose C++'s other strong points[such as simplified I/O, at least as compared to C]

2. Templated classes. It was mentioned above, C# lacks these, as do many other languages it seems. While the use of them could be cleaned up quite a bit, the idea of template classes is very sound. It allows for the easy set up of a container class that holds basically any other class you put into it. For example, a matrix in C++ is little more than an array of arrays, all of which can also be templated to hold int, float, char, etc. As a simple side project, I once made a 3D matrix by simple templating arrays into a 2d matrix. In C#, it appears doing this would not be nearly as easy or straight forward.


Re:Using C# over C++ just for Windows?!? (1)

SpryGuy (206254) | more than 13 years ago | (#867154)

Well, the advantages are allegedly many...

Writing in C# (or using 'Managed C++' which also buys you garbage collection) allows you to write COM objects and to interoperate with other languages (C#, Managed C++, VB, ??) transparently. The whole .Net thing is about a common runtime platform, where the language itself doesn't matter. Got an object written in VB? You can inheret from it and extend it in C#. And vice-versa. You can pass data transparently back and forth (though gawd knows what is going on underneat the covers as far as a performance hit). I think all strings are Unicode underneath... as long as you never have to fiddle with BSTRs again, I'll be very happy.

- Spryguy

Re:What _I_ Like about C#.. (1)

rmull (26174) | more than 13 years ago | (#867155)

1) C# may be strongly (highly?) typed, but it seems to me that that is rather negated by the absence of anything resembling templates - how do you handle basic collections? Unless a reference has a type implicitly associated with it, you throw away alot of your advantages when you start to use these untyped data structures.

2) I've not the slightest idea what early binding and late binding mean, but there must be SOME advantage to late binding if it's used at all...

Re:And this differ's from Delphi how? (1)

Anonymous Coward | more than 13 years ago | (#867156)

You've never really _used_ the VCL, have you? From my experience, it's buggy and inconsistent. The IDE also has a habit of occasionally crashing without warning. I like Delphi the language, but the flaws in the VCL, and the fact that you're in most cases tied to it, really hurt. Really, what the people on my dev team wanted was to be able to replace Delphi with J++. We didn't care about the license issues with Sun, we just wanted to do our work, dammit! So, C# may allow us to get away from Delphi. Don't get me wrong, I love Java. But COM pays the bills (very well).

Re:Copy By Value vs Copy By Reference (1)

Rumble (6258) | more than 13 years ago | (#867157)

not sure why this was modded as flamebait... I'll bite on this seemingly innocuous piece nonetheless.

(this description has a C bias) Copy by value and copy by reference are two ways that data can be transfered about in a program (i.e. passed as a parameter to a function). If the copy by value method is used, the destination function, call it bar(), will get it's own copy of the data that it can modify (the data will be physically copied to another location in memory that bar() can use). Any changes that bar() makes on the data won't affect what the data was before the function call was made.

The copy by value method is useful in certain situations and might be seen to be desirable since the original data won't get affected, however it has the additional overhead of utilizing more memory and taking longer to "set up" since all of the original data must be copied.

Copy by reference means you pass a reference to the original data to the function foo(). foo() now has access to all the original data. Any modifications that foo() makes will be reflected outside foo() as well. This has the advantage of speed since the original data doesn't need to be copied, as well as the fact that less memory is used up on the stack.

When programming in C++, for example, except for primitive data types, you will almost always want to pass objects by reference.

Re:java (2)

Anonymous Coward | more than 13 years ago | (#867158)

  • Are servlets faster than Python/Perl/whatever using FastCGI, Persistent CGI, or an embedded Apache module?
Unless someone has a developed a JIT for those, then yes, Java is faster.
  • Are they more convenient to write?
That depends.

My site uses PHP for a lot of the "dynamic content" type stuff. It's quick and easy and it works pretty fast. Complex "web-based applications" are written with Servlets. I don't know if I'd call them "convenient" to write, but they are easier to debug, faster to execute, easier to integrate securely with back-end systems, scalable and maintainable.

Often, if there's a convenient way of doing something, you're eating somebody's dust. In a dog-eat-dog world, I want to eat dogs, not dust.

Issues with C# (1)

Anonymous Coward | more than 13 years ago | (#867159)

While everyone beats on Microsoft for doing things with its Windows platform and "innovating" software which further ties it to Windows, I think that there is some merit in Microsoft.

Microsoft writes software. Software has a purpose. The extent to which that software can fulfill its purpose is the way to judge that software. Slashdot readers tend to judge software by how accessible (i.e. open source) it is to them as programmers.

Microsoft products (nowadays) tend to have the ability to be programmed. Sometimes this takes the form of Macros, sometimes VBA, sometimes scripting or batch files. The beauty is that people who aren't computer geeks use this stuff, and they get things done.

C# will fill a lot of holes. It will be used to create stand-alone applications with COM objects, COM .DLLs, server side interpreted p-code, and anything else you want with it. Lay to rest your fears that you need to port to C#. COM is the MS answer to language porting.

"News for Nerds. Stuff that matters." is an appropriate title for this site because it is quite aparrent (via the feedback), that most users of this site are nerds that do things in the nerdiest fashion possible. I happen to be a nerd who has to support MS at school...

Anyway, my beef with free software (in particular Linux), is that it is NOT free. Free software takes time to learn and use. How much do you get paid per hour to learn and use Linux? The fact that I do means that Linux is free for me. Is it free for my mom? No. Is it free for my sister? No. The free software movement needs to come to terms with the fact that unless you make software usable to people who don't have the time to pick up the manual, your software won't be used.

I am personally a big fan of the GIMP. I wish that the latest win32 release could load a JPEG on a 2-processor NT machine... I haven't updated my older version (I have 2 computers at my desk) for fear that it won't work on a 1 processor machine, too.... Playing with free code vs playing with commercial code, I can say that the free code needs to mature in usability for the rest of the world before it makes a dent in the software industry. I welcome the market share to open source software, but sarcastically say, "yeah, that'll happen soon...".

Re:This level of language... (1)

Malc (1751) | more than 13 years ago | (#867160)

Oops, I tried to moderate the parent comment and screwed it up trying to scroll down the page with my mouse wheel. So, to undo my "Flamebait" moderation, here's a useless comment.

Re:C#: Answer to the DOJ? (1)

ucblockhead (63650) | more than 13 years ago | (#867168)

I'm not so sure even that is true, unless you worked very, very hard to make your code portable from the outset.

I've been involved in ports between OS/2 and Windows, and usually the GUI code made any application level program worth nothing on the new system. Better to just treat it like a spec. and recode. And OS/2 and Windows are a lot closer together than either is to Linux.

Re:Not see sharp (1)

tomblackwell (6196) | more than 13 years ago | (#867170)

See Octothorpe.

A look at C# (5)

_prime (181525) | more than 13 years ago | (#867172)

I recently went to a brief presentation on C#, done by some Comp Sci folks just back from the MS developer conference.

A few points I recall:

  • It does require a virtual machine. It forms a layer of abstraction called the "Common Language Runtime." The name of the VM itself is "NGWS". Performance questions led to answers along the lines of it being comparible to Java; there were indications that MS engineers believed it would eventually run faster than a compiled language due to the virtual machine's ability to optimize code execution for individual processors and systems.
  • They had a look "under the hood" of the Virtual Machine only to discover that it looked *strangely* just like MS's Java VM. Apparently they changed the variable/function names but the programmer who was taking a look said the code itself looked the same. They commented that they could actually run Java code on the system without problems, providing it didn't refer to any of the special Java class libraries.
  • Visual Studio 7 (?) would be known as Visual Studio .NET and would feature C# and the VM. They remarked that the beta release they received was quite stable.
  • The VM would run on everything from Win98 up (not sure about 95).
  • They went into some detail on MS's new strategy. Basically they are hoping to capture the Middle Tier market with C# services running on the VM (NGWS), accessible remotely via SOAP. On top would be ASP+ (internet) and Win Forms (enterprise).

Someone asked why we need another language, especially one so close to Java. The presenter(s) explained that MS basically wanted to offer a VM based Java-like language, but was unable to add their own extensions to Java fit in with their new strategy (remember the lawsuit from Sun?). They remarked that perhaps Sun made a mistake in their desire to keep MS from making non-standard alterations to the MS implementation of the Java VM. MS, as usual, just went ahead and created their own new standard. Now we have another language to pull developers away from Java.

Re:Not see sharp (1)

J.Random Hacker (51634) | more than 13 years ago | (#867175)

na -- it should be pronounced see-hash, since it makes a hash of lots of good design ideas... ;-)

Gripes and rebuttals (3)

Edward Kmett (123105) | more than 13 years ago | (#867176)

I dislike the syntax used for C#'s structs. Since it is identical to the syntax used to access a class, you cannot identify without digging up the location of the source definition of the object whether or not you are passing by value or reference into the function.

my_int bar(my_int x) {
return x;
my_int foo() {
my_int y = 2;
return bar(y);
foo returns different results depending on whether or not my_int is a struct or a class. You cannot tell if modifying the object will modify the original or not without looking for the original class definition which can be buried pretty much anywhere in c#, because it has abandoned the rigid formalism that Java used of one public class per file and the name of the file matching the class.

Mind you, Microsoft will probably sell a nice Visual Studio plugin which looks up the source definition and shows you if its a class or struct, and which allows you to hyperlink to the definition (witness MSVC and VB), but I'm examining the language, not Microsoft's tools.

I disagree with the author of this article about the presence of Attributes. Attributes (as ugly as they are) create an avenue to extend the metainformation provided by the language. Since the attributes reside at the class rather than instance level, the glut of their presence is not intolerable. Their presence is necessary to fully specify COM parameters, they can act as a reflection tie to documentation, provide editor bindings to source code, etc.. in one place, rather than java's comparatively hackish javadoc approach of differentiating /* and /**. Its new, its different, but I can accept it and already see uses for it.

However, I do not see the need for Events to be a language level construct. With the introduction of generics/templates they could be implemented as a generator/listener template with a common superclass and subscribers tracked in a static list per event template used. No extra nomenclature need be added to the language to describe what is just another pattern afterall. In the absence of generics I suppose they did the best they could, but its another case of pandering to their present programming paradigm (pardon the alliteration).

I do miss the presence of java's inner classes and either c++'s templates or some other form of constrained generics (can anyone say Eiffel?).

In fact the lack of any form of generic will probably keep me from using the language as I am a pattern junky, and templates/generics are key to avoiding a lot of cut&paste code when using similar patterns heavily.

Apple releases a new language called C#++ (4)

efuseekay (138418) | more than 13 years ago | (#867177)

Despite the success of C#, programmers began to complained that though C# provides much of the functionality of Java with the flexibility of C++, there exists a middle ground between C++ and C#.

C#++ is desiged to fill that middle ground.

CaptChalupa, a MicroSlash programmer, said, "I love C++, and always programmed in C++. But the lure of the C#, which my colleagues have raved all over, is tugging me. The reason I don't want to abandon C++ is because I still like to keep the flexibility of collecting my own garbage. C#++ is the answer that may just finally pull me away from C++."

Meanwhile, in another development, Microsoft Applications Inc. has announced the development of a new language called "C##".....

Re:Back to C... (1)

Anonymous Coward | more than 13 years ago | (#867178)

Yes some of the nice things about Smalltalk languages (ObjC) over Simula languages (C++) are:
  1. Classes are objects
  2. Methods are objects

I'm sure you've read David Stes on comp.lang.objective-c go on and on about blocks (which is the idea that blocks of code are objects, too). It doesn't seem very practical in a compiled language, but you never know.

But to answer the question about how messaging works in ObjC, basically (assuming there isn't an appropriate protocol), the function objc_msg_lookup() will be called. It will then return an IMP (pointer to a method), most likely _i_MyClass__methodName, but possibly _i_MySuperClass__methodName, etc.

Re:Back to C... (2)

HeghmoH (13204) | more than 13 years ago | (#867179)

Ok, I haven't been doing Obj-C for too long, so this may be innacurate or incomplete yada yada.

I've only done work using my own code within a free set of libraries called Swarm [] , so I don't really know if there are method naming conventions between sets of code and the like. I think many common operations would be named the same. Basic things like object creation/destruction are certainly named the same.

Objective-C is more-or-less straight C with smalltalk classes grafted on top. Things like int, float, and C-style arrays aren't classes of any kind. However, most Obj-C compiler libraries have classes for arrays and other types of object collections. If you have an object of type id (literally, just a pointer to some object), there are some standard methods to see whether it's a particular class, whether it responds to a particular method or protocol set. There's been mention in comp.lang.objective-c about a higher-order-messaging scheme that one of the people is putting together to help handle things like performing actions over entire arrays, and it's done entirely within the language (no compiler changes). I haven't looked into it too much, but it looks pretty neat.

I'm so excited, I can hardly contain myself (4)

askheaves (207302) | more than 13 years ago | (#867180)

Since the first day I heard about this language, I have been excited about it. The more that I read about it, the more I can't wait to see that pretty little brown MSDN box come in the mail with my copy of Vis Studio 7.

As a Microsoft-whore, the ability to develop with the new tools of VS7 (which, BTW, features C#, VC++, Managed VC++, and VB all running in the same IDE with concurrent, multilanguage debugging... baby!) has taken over. I am working on a project that requires two WinCE portions and a data management system. The things I've read have made me make the conscious decision to do no code development on the data management portion until VS7 is in my hand and on my machine.

This month's Visual C++ Developers Journal has a cover to cover exposé on VS7. This is a link to the online article. /08aug00/bn0008/bn0008-1.asp

"Blue Elf has destroyed the food!"

Re:I'm a bit confused. (1)

Acy James Stapp (1005) | more than 13 years ago | (#867181)

This is especially useful for numeric programming. A programmer's mental model of numbers is such that assignment = copying. Say you have a complex number class, 'complex'
Which is more error-prone:
(good c++ code, bad java code)
complex a;
complex b;
b.imaginary = 1.0;
(a is not changed if you have copy by value, but is changed if you have copy by reference (as in java))


(good java code)
complex a;
complex b;
a=new complex(b);
b->imaginary = 1.0;
(a is not changed, but this is nasty looking)

(pardon my probably incorrect java syntax, but the idea should be clear)

The other issue is memory usage. An object with an embedded complex number will use sizeof(complex) (probably 16 bytes). But an object with a reference to a complex numbers will take (sizeof(complex)+allocation overhead+reference size), typically 28 bytes, or almost twice as much memory! Not to mention cache coherency issues.

In summary, value objects are good.

Does C# exist yet?? (1)

Gorimek (61128) | more than 13 years ago | (#867182)

Is there a working C# implementation?

Correct me if I'm wrong, but I get the impression C# is just vaporware so far.

Re:Not see sharp (3)

cybercuzco (100904) | more than 13 years ago | (#867183)

and youd have to be smoking hash to code in it.

Re:Ack! Significant whitespace! (2)

Deven (13090) | more than 13 years ago | (#867184)

I shudder when I think of programming with significant whitespace. It's what has kept me from picking up Python in earnest--at least until I write a conversion program that turns braces into the whitespace that python likes (in Perl :-).

To think that C would be made *better* by the addition of significant whitespace gives me the chills.

Agreed! I've been told a number of times that Python is a good language, but that one design flaw (making whitespace significant) has kept me from wanting to touch it. It would be okay for the compiler to generate a warning for incorrectly-indented code, but to generate incorrect code instead is simply inexcusable. Grafting this abomination onto C is a disturbing prospect indeed.

C# = ? (1)

DrQu+xum (218745) | more than 13 years ago | (#867185)

C# = 13 pounds (base 10).
Coincidentally, that's how much the documentation weighs. Problem is, it's on 13 pounds of CD-ROMs.

Moving target? (2)

jaoswald (63789) | more than 13 years ago | (#867186)

Does this mean that C# will be as much of a moving target as C++ was for the first 10 years of its existence?

(I don't mean to sound surprised, as this is a Microsoft language, which needs continuous "innovation" to maintain market-share.)

To me, one of the huge reasons not to use C++ was that, even though I had learned an earlier version years ago, when I came back a few years later, Bjarne had added a few new features that were now "essential" to implement some "crucial" paradigm. E.g., suddenly templates are crucial to programming in the true C++ religion. Never mind that compilers took years to get them properly and consistently implemented, while hackers seemed to keep pushing templates harder and harder for compile-time code generation, in ways that were bound to activate any subtle, lurking bugs in a compiler. Same with exceptions, RTTI, et al.

My main gripe is that it is hard enough to deal with languages where people keep coming up with half-solutions to new problems by changing the language definition. How much worse will it be when Microsoft, with its commercial interests, gets in the game?

Disappointed about boxing/unboxing (2)

JohnZed (20191) | more than 13 years ago | (#867187)

Microsoft played up the fact that their approach to boxing/unboxing would be fairly innovative in C#, and this got me pretty psyched. Basically, boxing is a way to convert primitive objects (ints, etc.) to instances of the generic C# 'object' class. That way, you can treat primitives like objects, but without the performance loss in cases where you just want them to be plain old primitives (I imagine something similar happens with structs?).
Sadly, I took a skim through the "Introducing C#" book, and noticed that boxed primitives are completely distinct objects from their unboxed versions. So, if I do "int x = 10; Object xobj = x;", the new xobj is completely unrelated to x from now on. I can later do "(int)xobj += 100; print(x)", and x will still be 10.
In other words, this is (as far as I can tell, please correct me otherwise!) exactly identical to doing "xobj = new Integer(x);" in Java, just 'syntactic sugar' as they say. You could add this pretty trivially to Java with few little tweaks to the front-end (and maybe somebody should).
Really elegant boxing would allow you to treat primitives as full, first class objects. Then you could, for instance, have a synchronized block use an integer as its lock object. Or you could store an integer in a collection (say, a hashtable) and have the hashtable entry properly updated as the original int is changed (as if it were any other mutable object). These aren't huge deals in the grand world of language design, but their efficient implementation would actually be kind of interesting.

Sharp Move? (2)

Anonymous Coward | more than 13 years ago | (#867194)

I've been thinking about this one for a couple of days and all actually fits in. Assume the following events:

C# will be ignored by SUN/IBM etc. for the next 2-3 years since they heavily back Java and are reluctant to invest in competing technologies.

While being ignored by their competitors Microsoft does some heavy promoting of C# to windows developers and succeeds into making it the primary windows development environment. Ofcourse using Visual Studio. (I think this will be easy due to the current gap between Visual Basic, which is too simplistic to do any serious component development in, and Visual C++, too hard, ever used ATL? C# fills the gap nicely where Java fills the same gap on other platforms.)

Higher level Windows API's are wrapped in C#-accessible classes or components and a lot of the code implementing this is ported to C#/IL. Using the same strategy as with Windows, there are 2 APIs: one public and one internal.

C# is accepted by ECMA into the standarization process. The language and associated libraries are standarized. The standard process progresses fast backed by Microsoft and it's partners. Except for Microsoft itself, no-one tries to keep up.

Microsoft looses its appeal is split up into an OS and an Apps company. The Apps company keeps Visual Studio.

The IL and libraries (.NET framework?) are ported to a different operating system (e.g. Linux) and most code that would run only on windows now runs on that other platform with minimal effort. Ofcourse only when the Microsoft implemented libraries are installed and paid for.

Effect: Microsoft Apps company doesn't need the Windows OS anymore and controls the API used in most commercial applications on several platforms and also has a secret internal API that they can use for pushing too powerfull players out of the market.


Re:java's overhead (2)

Spud the Ninja (174866) | more than 13 years ago | (#867197)

Even if speed is a big issue, you can still used Java. The least platform-independant stuff to program is the user-interface. This is were Java shines, I think. I don't care how slowly it runs, Java can keep up with my mouse clicks!

For serious number-crunching, using JNI to hook into some optimised native libraries, which can be built with a minimum of platform-dependant code if you don't count Makefiles, all-but-negates any speed loss that going with a purely Java solution would give you.

My understanding is that C# can also call libraries like this, and that it's way easier for other languages to call C# methods than Java methods. But with it's heavy dependance on COM, I'm not sure how widespread C# could be outside of the Win32 system. Does it even provide it's own windowing toolkit, or does it jack into the exiisting OS calls?

Love, Spud.

Re:Copy By Value vs Copy By Reference (1)

Mongoose (8480) | more than 13 years ago | (#867199)

Aw, that's cute... =)

Copy by value - ( aka deep copy )
You allocate new space for an object and copy it
from the orignal. Kind of like making Xeroxs -
you have an exact copy of the orignal but it's
a new copy.

Copy by ref - ( aka shallow copy )
You point to the old copy. It's like only having
one copy of a paper and when someone wants a'copy'
they have to reall barrow it from bob.

- Mongoose

wolf wolf, I like Kittie

Re:Copy By Value vs Copy By Reference (2)

Just Some Guy (3352) | more than 13 years ago | (#867200)

In my experience, I rarely want to make an actual bitwise copy of something. If I already have one copy in memory, chances are that I don't want another one.

According to the review, C# copies by reference by default, just like C++ and Java. It can be coerced into copy-by-value, though, on the rare occasions that you can't work around it.

I do agree with your other points, though. The kid wasn't baiting, and I too wish that I hadn't wasted my time with BASIC.

Genericity (1)

vanicat (162345) | more than 13 years ago | (#867203)

When i read this, one thing make me realy react : no, template aren't the only way to do genericity, the ML way of doing it, or better the OCaml way are fare better : they are type safe, whith no duplication of code. More precisly, it's easier when programing object in ocaml to make generic function than to make non generic one, and all this whith out any lost of efficacity in size or speed.

Doesn't make sense to me either. (1)

Tom7 (102298) | more than 13 years ago | (#867204)

If structs can contain object references, then they must be observed by the garbage collector as well, even if they are allocated on the stack.

I'm pretty comfortable with garbage collection but I don't get what he's trying to say here. Can the poster elucidate us a little?

C# vs Java ? Gimme a compiler! (2)

jabber (13196) | more than 13 years ago | (#867205)

The one argument for C#, and against Java, seems to be performance. If C# delivers better performance than Java, than C# will be better. I'd argue that, but I left my asbestos undies at home.

Well... Where are the Java bytecode-to-native compilers to make this a non-issue?

Seems to me that improving the performance of an existing language (albeit at the cost of platform independence, obviously) would be much simpler than developing a whole new language to include the piece that Java is missing - a native compiler.

Re:C# (3)

Anonymous Coward | more than 13 years ago | (#867206)

speaking of compilers, wouldn't it be funny if Sun released a compiler for C# that didn't follow the language specifications exactly as Micrsoft has detailed them?

I wonder who would win that court battle...

Ack! Significant whitespace! (3)

stevens (84346) | more than 13 years ago | (#867207)

Quoth the poster:
...C's hideous syntax...
I wrote a C/C++ preprocessor that lets you use Python-style whitespace-significant code, called Cugar to escape the ugliness of C.

I shudder when I think of programming with significant whitespace. It's what has kept me from picking up Python in earnest--at least until I write a conversion program that turns braces into the whitespace that python likes (in Perl :-).

To think that C would be made *better* by the addition of significant whitespace gives me the chills.


Re:Attributes (1)

NaughtyEddie (140998) | more than 13 years ago | (#867208)

So they let you add massive redundancy to your codebase?

[XmlElement("shipTo")]public Address ShipTo;

That'll be changed incorrectly by a developer within a week.

If a language needs specific attributes, they should be built into the language in such a manner as to eliminate this sort of pointless redundancy.

Re:Copy By Value vs Copy By Reference (1)

Rumble (6258) | more than 13 years ago | (#867209)

What's wrong with BASIC? I spent years programming in BASIC in elementary/middle school. Up in Canada, all we had were Apple 2's in the schools anyways, and my old man had an apple2 at home as well. You can do a lot of cool stuff with BASIC with very little knowledge of underlying computer hardware and it is reletively simple to understand the procedural programming methods required (at least, last time I used BASIC, then again, it was almost 11 years ago!). C would have been the absolute WRONG choice back in those days. I have no regrets about my BASIC heritage, he he :)

Re:Back to C... (1)

Matthew Weigel (888) | more than 13 years ago | (#867210)

And it's a shame to not see good template (genericity?) support in C#. Or any language, for that matter.

How do you figure? C++ templates are a hack to deal with the lack of a base class; other OO languages (Java, Objective-C, C#,Smalltalk...) let you do generic things by operating on the base class, from which all objects inherit. Also, with interfaces, you can define an operation that only affects classes that know about the operation, without worrying about where in the class hierarchy the class is.

I think choosing a good type system is where a lot of languages fall flat, and I'm not a big fan of the huge C++/Java Object/Type/Library approach, although I haven't seen a truly good solution to this problem yet.

Would you mind explaining this a bit? What do you mean by 'Object/Type/Library' approach to typing?

Re:Programming languages: C++ still king? (1)

SpryGuy (206254) | more than 13 years ago | (#867211)

Um... C# lets you import and use objects written in C++ or VB as well as those in C#. In fact, that's part of the whole point of the .Net thing. It's "language neutral". You write in the language you're most comfortable with. Others can then use your objects in the language THEY are most comfortable with. (as long as there's a language wrapper that uses the common runtime... so far, I'm only aware of "Managed C++", C#, and VB ... though they talked about COBOL, Fortran, Perl, Pascal, etc. being ported to use the runtime)

Just FYI.

- Spryguy

Re:Not see sharp (2)

angst_ridden_hipster (23104) | more than 13 years ago | (#867212)

Cocktothorpe (C-Octothorpe).

With apologies to Don Macpherson at Bell Labs, originator of the word "octothorpe."
bukra fil mish mish
Monitor the Web, or Track your site!

Re:Geeks of all flavors (2)

NaughtyEddie (140998) | more than 13 years ago | (#867226)

C# will be integrated with DevStudio.

No-one knows the future; C# may succeed on the Windows platforms and be a vital line on your resume, or it may flop totally and be rejected by developers, and M$ may drop it in 2 years.

As for C and C++, I find it amusing that the one part of C which you like (pointers) is the one aspect which has taken the most criticism over the past few decades!

You don't really explain why you dislike C/C++ - apart from having someone "watching your back". Well, the solution is to learn to write robust code. Run-time errors are useful, but if you're shipping software it shouldn't have any, so run-time error checking is a waste of the end-user's time.

I mean, I could understand it if you hated the C syntax, or C pointers, or C++ backasswards compatibility with C, or the appalling non-portability of C. But if you dislike C because it reveals your subtle bugs to you, then you should really learn how to write bug-free code. It's a much better thing to have on your resume than knowing ANY specific language. And C/C++ are going to be around for a while.

Re:Copy By Value vs Copy By Reference (1)

pergamon (4359) | more than 13 years ago | (#867228)

Automatic copy by value is a sticky language concept. Where does the copying by value stop?

In other words: What if I have an object with an array filled with a billion other objects. Then I've got another object with a reference to the first object. What if I want to make a copy of this object? Does it then make a copy of the billion objects in the first object?

Re:C# vs Java ? Gimme a compiler! (1)

catseye_95051 (102231) | more than 13 years ago | (#867229)

You ask:

"Where are the Java bytecode-to-native compilers to make this a non-issue? "

The answer is, in Java. It's called a JIT and in fact does a better job compiling in many cases then a static compiler can due to the richness of information available to it at run-time.

This mistake is what's wrong with the article too- it's built on false prmise. Yo uand the article author both need to go read Chris Rijk's benchamrking report (Binareis v. Bytecodes) at

Re:Copy By Value vs Copy By Reference (1)

MadHobbit (68381) | more than 13 years ago | (#867232)

It's pretty simple...

(Note that the exact mechanics of this vary from language to language, but the idea is the same)

Say you have an object in memory, 100 bytes big. Your program uses a reference to find the object in memory and do useful things to it, like change it. Now, if you copy it by reference, you make a new reference to the same object -- You have one object and two references. However, if you copy it by value, you make a new copy of the object, and a new reference pointing to the new object.

If you copied by reference, then the two references affect each other; make a change using reference A, and the change is reflected in reference B. It uses less memory (since there's only one copy of the data) and is a faster operation (there's less data to duplicate). However, garbage collection is difficult, because the object can only be safely deleted once ALL references are gone.

During a copy by value, the data is replicated, so making changes with reference A doesn't affect reference B. You need more memory (200 bytes -- there's now two copies of the original object) and copying the data takes time. However, garbage collection is very simple, because there's no possibility of two references to one object. Once you remove the reference, the object can be deleted.

This type of discussion is appropriate to a language like Java, where there are no pointers, only references to objects. In C or C++, you have variables (like "int num") and pointers ("int *numptr"). Pointers act as references and are used to copy objects by reference. It's a bit more complex, since pointers are often used to generate references to variables, so the same object is sometimes copied by value and sometimes by reference....

Hope this helps...I think I made sense :-) And everyone feel free to jump in if I messed anything up -- I despise Java from the pit of my being, so I don't know it that well. C is more my thing.

Re:Back to C... (3)

Snocone (158524) | more than 13 years ago | (#867233)

That's cool; is there some sort of method naming convention?

That problem is addressed through the use of protocols. Some are formal, like the reference counting protocol for instance (implementing them is known as "adopting" that protocol), informal protocols can be defined at will. Note that this also gives you basically all the design capabilities of C++'s multiple inheritance with none of the associated problems.

"Protocols free method declarations from dependency on the class hierarchy, so they can be used in ways that classes and categories cannot. Protocols list methods that are (or may be) implemented somewhere, but the identity of the class that implements them is not of interest. What is of interest is whether or not a particular class conforms to the protocol--whether it has implementations of the methods the protocol declares. Thus objects can be grouped into types not just on the basis of similarities due to the fact that they inherit from the same class, but also on the basis of their similarity in conforming to the same protocol. Classes in unrelated branches of the inheritance hierarchy might be typed alike because they conform to the same protocol."

-- Object-Oriented Programming and the Objective-C Language [] , p.99.

What I like about Scheme is that you can query the datatype to see what it is,

In Obj-C you can ask an object what it is, if what it is is a kind of some of other thing, if it responds to a given message (note that through the use of categories, this capability may be added at runtime), conforms to a given protocol, yadayadayada.

On the other side of the fence, Java has a type for everything, and is correspondingly complex, too.

Obj-C is, well, C. You add just as much or little complexity as you wish.

Makes some sense to me. (1)

Len (89493) | more than 13 years ago | (#867236)

Well, clearly, if you create a bunch of structs and then fill them with refs to other heap-allocated objects, you've defeated the purpose of reducing garbage collection.

But if your structs contain only "simple" data that can be contained directly in the structs (like ints or something, I don't know the details of C#), then you can avoid garbage collection on the bunch of structs.

I'm sure this would be a useful optimization in some situations, but I don't think it will be all that common. The garbage collector is still going to bear the brunt most of the time. Fortunately, garbage collectors are more efficient these days than back when I was using Interlisp.

Re:java (2)

Anonymous Coward | more than 13 years ago | (#867237)

Okay. In C#, I can write an operating system and get the same perforemance as C by restricting myself the the C subset. What about Java?

In C#, I can write the C# portable runtime. Can you write a full Java VM in Java? Nope. What about one with JIT, etc.? No frigging way.

C# gives me the power to drop down to the low level where I need it, but gives me the power to do so without having to jump through a thick, slow, clumsy layer like JNI.

As someone who has done a lot of JNI programming, C#, instead of being the total turnoff I thought it would be, has me very interested. It's cleaner, safer and more powerful than C and C++ and has no features that are inherently more expensive from a performance point of view. If C# gets support outside of MS, then it will be a fantastic opportunity for C and C++ programmers since it lets us do things (like high performance graphics, etc.) that we can't do in the only other real alternative (Java).

I've spent the last two years doing nothing but Java development. Real, tens-of-thousands-of-lines-of-code development. I like Java, but there are huge parts of it (all of, all of Swing, etc.) that are seriously broken.

The only thing I think C# doesn't do that I really wish it did was provide for Eiffel-like assertions and invariants. Aside from that, it's a really nice language.

Now, the problem is that the .NET stuff may be tied to MS platforms..
Load More Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Create a Slashdot Account