The Spec# programming system is a new attempt at a more cost effective way to develop and maintain high-quality software. Spec# is an extension of the object-oriented language C#. It extends the type system to include non-null types and checked exceptions. It provides method contracts in the form of pre- and postconditions as well as object invariants.
Finally! If some of you ever tried socket programming in .net you will very well know why strict exception checking would be a must in c#.
Others would disagree that checked exceptions “would be a must” Check out some of Bruce Eckel’s writings on checked exceptions in java.
I thought C# was supposed to have been developed with all of Java’s hindsight. Guess not.
This was announced quite awhile ago, what’s the news on it?
Dispite what the Java purists tell you, C# is really nothing like Java. Any developer that has spent at least 2 days of C# development beyond the “Hello C#” canonical example will know that C# has a lot of features missing from Java.
Like what features?
Value types, generics with RTTI, pseudo-closures, operator overloading, properties, ref and out parameters, a preprocessor, unsigned numeric types, delegates, multidimensional arrays, what is essentially a very convenient FFI, and probably other things that I’m missing.
those are not really “advantages” over Java – or any other modern language. they are simply results of language design desicions. Maybe all has posible pros-cons.
if you go next Java (Mustang) forums, you will see same stuff over and over again. This is because people could not get that Java is not C++.
http://forums.java.net/jive/forum.jspa?forumID=23&start=0
Most of the cons i can say is making the language more complex and unsafe. Same likes it that way, some likes a language aspect trying to please everbody. Java is simpler in this aspect, easier to learn. People thinks Java should behave like C++ – or C# , but it really should not.
And a last note: Please talk about currently implemented features. i can talk Java Mustang, or Dolphin if you want.
The poster asked what features that C# had that differed from Java. Instead of demonstrating that you are a Java zealot you could have taken my post for what it was. I will talk about whatever features I want that are part of the language specification.
I don’t really care what your opinion is regarding whether these are “advantages” or not. I expressed no opinion regarding anything.
It isn’t even clear to me what I listed that you think are aspects of C++. C#’s generics are runtime constructs, don’t offer specialization, and only take type parameters. They’re safer than Java’s in that type-correctness is preserved and isn’t compromised by reflection. They’re completely different than C++’s templates.
C++ has no anonymous functions, although libraries like Boost Lambda FC++ add vaguely similar features. They’re hardly a C++ feature.
Well I could go on, but really I don’t feel like it. Neither C# nor Java are especially “modern” languages in much other than their age. Neither are especially simple, either.
Like what features?
– User defined value types: important for high-performance and numerical applications
-out and ref parameters
-true generics in .NET 2.0 – not a compiler trick like Java 5 that just boxes everything into objects
-java finally got enums – who knows why it took them so long
-delegates – much cleaner callback mechanism than java’s anonynmous methods. It’s horrible that java has these stupid adaptor classes all over the place.
-unsafe code and pointers – much easier interop with native code than JNI
-unsigned integer types
-much less “academic” class libraries in my opinion – the .NET framework libraries tend to have little static helper methods that are not as “pure” from an academic point of view, but most programmers like them. look at IO for example
-java finally got variable length parameters which allows it to have a proper printf-like method
– no checked exceptions (which i consider nice. others might disagree)
Overall the CLR (the common language runtime) is more advanced than the JVM. For example, the JVM will most likely never be able to run a language like C++, such as the CLR can.
I’m sure there’s more I’m forgetting.
I think Microsoft and Sun are both starting to realize the importance of dynamic languages. Post .NET 2.0 and post Java 6 are both supposed to have changed to their runtime engines to make them more conducive to dynamic languages.
|- User defined value types
|-out and ref parameters
|-java finally got enums
agree, i would also add the field getter/setters.
|-delegates
There are actually numerous ways to implement delegate-like functionality in java, some can be used just like the c# delegates. Example: http://www.onjava.com/pub/a/onjava/2003/05/21/delegates.html?page=2
Yes, the api does not make use of this, thats a valid argument.
|-unsigned integer types
oh yeah, they would be very nice if half of the .net api would not be ignoring their existence. Try to do endian conversion on them for example.
|-much less “academic” class libraries in my opinion
So much less, that a good part of them does not work at all, or works completely differently under win2k and winxp. Look at Socket for example.
|- no checked exceptions
It can be quite a pain to empiricaly find out that the documentation forgot to mention that a certain method can throw a completely unexpected kind of exception. This especially happens when running multiple threads or asyncronous calls. Well yes, you can catch a generic exception and that catches everything, but it does not help in handling the error condition at all. At least the ide could try to enforce exception declaration like Eclipse does. In fact the way eclipse warns about unhandled exceptions and allows to autocomplete the declaration or add the try/catch block makes the strict exception checking very confortable. Intellisense has a lot to catch up in VS.NET.
Delegates
Events
Properties
ref/out parameters
Explicit interface implementation
Strange my friend was just swearing at monitor while developing beyond “Hello C#” applications. He used to program under Java with IDEA. i asked their honest opinions several times, he says it is no different than Java in most cases but IDE (Vs.net) is just horrible comparing with IDEA for anything more serious than “Hello World”, there is not enough mature OS libraries, stack traces are pityfull. He does not like the framework (such as Collections) structure as well. He is an experienced person in both languages by the way. So, i guess you have gound stg he did not see there (mAybe you have never programmed in Java, or did it 5 years ago?)
If there’s anything I learned about C# and Java, it is there is no easy answer to checked vs. unchecked exceptions. There are some very persuasive arguments either way, and anyone who says that one is definitely better than the other is under-informed.
But anyway, all this should become irrelevant. Because of… contracts! Pre- and post-conditions and invariants. In my opinion, designing with these in mind is much smarter than designing around exceptions. Not that they make exceptions obsolete, but they truly become exceptional – as they should be! Whereas contracts should become everyday and iron-clad – as they also should be.
Before you start pushing another CS concept, why don’t you get Microsoft programmers to first at least LEARN how to code exceptions. Personally, I like Microsoft’s “Pray” design decision. I can bill hours and hours of time trying to prove and track down program flows and attempt to doc the call hierarchy to prove all thrown exceptions are explicitly caught. ( NOT. )
There’s BS and LAZYNESS on Microsoft’s side.
There’s TRUTH and High Productivity on Java’s side of the argument.
There’s still programmers out there that don’t code ELSE clause to their IF statements, and there’s still programmers that don’t code Exceptions in their business objects. Hopefully, you don’t aspire to be one of these.
I withdraw my previous comment.
This new Extension looks Very Good.
Too bad it’s alpha. C# can’t compete with Java without it.
http://blogs.msdn.com/sriram/archive/2005/06/18/Digging_Into_SpecSh…
I like C# because it is so much less verbose than Java.
e.g. I don’t need to implement a whole class to implement delegates. The library is also (in most places) very clean in comparison to Java. Compare System.IO.
The Java community lost me because Sun dragged their feet…
The C# compiler has the option of allowing unsafe code, and it also has the option of treating warnings as errors. With so many different views on whether it’s a good or bad thing, wouldn’t it be nice to have the option of enforcing exception checking?
I am totally convinced of the usefullness of static program verification. I don’t know the future of programming, but my bet is that in some way or another, this will be an important part of it.
I am an Open-Source enthousiast, and it freaks me out to see MS making such good progress in this field. One of the most proper implementations so far was ESC/Java, and MS hired at least one highly competent member of the ESC/Java team. I’ve been lurking at the Spec# mailinglist, and things seem to be moving forward steadily.
As far as I know, there has been about zero progress in this field in Open-Source land. I am worried.
Nice to see some educated posts for once about Java vs C#/.NET
If you spend more than 5 mins using it you will see there are alot of things different as stated in posts above.
I think one reason why C# and .NET are making such fast advances is simply because its a very focused project. They need what they need to get done.
I’m very much a open source advocate, but I’m very much a .NET advocate as well (.NET/Portable.NET/Mono).
But open source projects just aren’t as focused as companies are. I get paid to write code that our company needs. I don’t get paid for functionality I think we need, or what I WANT to work on.
Almost all open source developers are guilty of it, I know I am. I don’t join an open source project that needs me, I join a project working on something I enjoy, so does everyone. I work on features I enjoy etc etc.
Most successful open source projects I think have been funded in some sort of manner to try and focus a few people on the important things. But this isn’t always the case obviously.