“C# and Java are both nice languages. They reach similar goals through similar means, although C# adds some syntactical touches to Java, such as the foreach keyword and a more pleasant extends/implements construct. Unfortunately, the improvements are outweighed by the instances of regression. In this article, I’ll compare the languages, while trying to avoid dipping to the JVM and CLR level.” Read the article at Builder.com. Update: A similar comparison article, about security.
Goto does exist in Java too. Its called break. Gotos are useful if you use them correctly. For instance, they provide a clean way of breaking out of a deeply nested loop. Take a look at section 14.14 of the Java Language Specification.
SOAP isn’t really integrated into C#. Its integrated into .NET. To say that its tight integration to C# is limiting is plain wrong. C# developers can still choose not to use SOAP.
Aside from that, I agree with most of what the article says.
This article is just propaganda — consider a subtitle like “Java: All the greatness of C++ without the hassle” — and you get the picture…
I’m sorry, but in my opinion the arguments against C# aren’t exactly solid resounding reasons to call it ‘Worse’.
On a different note, operator overloading is the same sort of sin on a more subtle level. When ‘+’ can mean anything depending on the type of the operands, the functioning of code is no longer transparent and unintentional side effects abound.
Excuse me? One of the more powerful languages (for data mining) IMO is K…have you looked at that language? You think C# uses operands in a complex way…..
C# contains a simple mechanism for marking regions of code as unsafe. Within these unsafe regions, the safeguards put in place by Java and later C# to prevent programmers from directly altering memory locations and using point arithmetic are suspect.
I have been programming in C# for a long long time now, and haven’t once needed to handle memory myself. The beauty of .Net is that it offers completely managed code *so you don’t have to*.
This binding to non-.NET objects is similar to the functionality offered by the Java Native Interface (JNI), but it’s more insidious. Whereas JNI was designed to carefully limit the interaction between Java code and native code with well-defined interfaces, .NET makes calling off to native object files so invitingly simple that developers can do so without realizing they’re throwing platform portability out the window in the process.
Ok, so MS have allowed C# programmers to access existing DLLs? And? The .Net framework is windows-only, so why worry about platform portability?
Perhaps the scariest feature in C# is its owner. Microsoft has made a good show of opening up C# and .NET for non-Windows platforms, but it is largely all show. Its CLRs for non-Windows platforms are problematic and buggy
Errrrm….arent most C# and .Net programmers Windows-based? and aren’t the other platforms (apart from BSD) not fully .Net compliant anyway – Mono, the OSS implementation of .Net, isn’t even MS!!
However, the Eclipse IDE, which includes Java support, has pulled ahead of Visual Studio in stability, ease of use, and offered features.
I don’t know where to start. All I can say is you have *got* to be kidding me.
The bottom line, however, is that C# doesn’t do much, if anything, better than Java, and it’s measurably worse in a few areas. When selecting between these two largely identical languages, pick the one that’s slightly better and battle-tested: Java.
As suspected, i can paraphrase this article as:
“I use java, C# is cr*p in my opinion, MS suck, use java”
Nothing of interest to read here, tho thats just my opinion, I just dont go spouting it and attempting to pass it off as a serious article. This guy should try using C# and .Net for a year and see how productive it is. I’m not saying its better than Java, but for a 1.0 release, its pretty darn close.
Having said that, Java will always be *the* server apps language of choice.
It doesnt even touch all the fancy things in C# which would interest me (as I have no C# experience). Stuff like attributes, or semi-stack allocation. Instead it does the usual Java proponent babble that I have heard a thousand times before, like ‘blablabla goto’, ‘blablabla type-safe’, ‘blablabla operator overloading’, ‘blablabla must protect developer from shooting himself in the foot’…
At least the conclusion is honest: if you want a language that is exactly like Java and you hate every single feature that is not in Java, then you should keep using Java…
I have been programming in C# for a long long time now
Hot damn, I didn’t know C# was that old.
Gotos are useful if you use them correctly.
STFU, by your definition everything can be useful if used correctly. Thats the same argument C++ programmers have been making about pointers, yet most modern languages are moving away from pointers and using references.
SOAP isn’t really integrated into C#. Its integrated into .NET. To say that its tight integration to C# is limiting is plain wrong. C# developers can still choose not to use SOAP.
Did you fuckin read the article? The author made the exact point.
If you really disliked the article, and wish to rate it, don’t use the form on builder.com.com, use this one instead:
http://skadus.ath.cx/Builder.htm
It’ll let you rate it at 0, below the normal minimum of 1.
ummm…..refrences are pointers…they both refer to an address in memory.
GOTO’s are good? are you kidding me? talk about spaghetti code.
there is a reason structured programming does not use GOTOs.
sure they are great when you are lazy but they are a painin the butt to debug and to maintain.
Yes, and BREAK is not the same as GOTO.
ummm…..refrences are pointers…they both refer to an address in memory.
references are constant pointers.. big difference
Just use Objective C. Please, I really wish more people would use it.
constant pointer in C++
In Java reference refers to class instances, while C++ pointers refer to memory address.
Get your facts straight
One thing I like about Java and C# is their creators wish to make languages that eliminate things that are easy to misuse and prone to introduce bugs.
Well, why is the goto statement STILL there. You NEVER need goto. Well it’s good to have in situations where very high performance is needed (like a process scheduler etc.) but I don’t think that both of these languages are suited for this.
Operator overloading is very good and make som things easier and doesn’t any complexity in my point of view. Adding two strings together is a very good example of this. It’s easy and intuitive.
I can agree with the author about ‘unsafe’ blocks in C#. MS tries to suit everyone and the language does too much. Introducing managed code into otherwise GC-based code is plain stupid. Java has managed to survive without this feature and I don’t think that C# will kill C/C++ for these situations!
A language like C# need library code to do something useful. Well, the .NETframework is not going to be an ECMA standard. The Mono project is good but without some sort of ‘proof-of-compatability’ I wonder what companies will think about developing .NET applications for other platforms than Windows.
I think C# is a very good language (but it could be better) and the .NET framework is a cliché of a microsoft product – Another HUGE product to be judged by all the developers forced to use it even if they don’t like it. Maybe I’m overreacting a little here;-) I don’t like the framework because its too dependent on Windows technology (no easy task porting it in some aspects) and its too large (typically MS).
C# is like Java (too much perhaps?) and the latter has matured and has a class library which is implemented on many platforms. It also has a wide acceptance in the industry. MS must accept they have lost the monopoly they once had in the PC market. I wish MS had a more opened mind!
All these languages have roughly the same features, roughly the same ‘power’ (see the link at the bottom for my definition of power). The elimination or inclusion of a few extranious features (goto, pointers, etc) is a moot issue. If you are a good programmer you won’t get any significant gain by using any one over the other. It will take you roughly the same amount of time (discounting availability of any 3rd party libraries that already do what you want) to implement anything in any of those languages. That all assumes you are a _good_ programmer.
If you are _not_ a good programmer you can’t be transformed into a good programmer by using a more feature restricted language. You have to study hard and program often to transform yourself into a better programmer.
Here’s a great article that may or may not illustrate my points, but it is certainly worth a read.
http://www.paulgraham.com/paulgraham/avg.html
Hot damn, I didn’t know C# was that old.
Regarding your other replies, this smells just like cynism, so just FYI, some people started screwing around with C# before the .NET framework or the initial VS.NET were final. Both of them were in beta for some longer time.
there are a number of facile and poorly researched viewpoints being peddled in this article that i feel moved to respond to:
1. sloppy syntax pitfalls: the goto statement
is extremely valuable for producing more readable code in a number of cases.
Djikstra’s argued against gotos a long time ago, when sloppy use of this keyword was prevalent. This led to the development of powerful structured programming approaches to replace gotos. However, since then, a number of authors have pointed out the need for gotos to increase the clarity of code. Just a couple of examples:
http://www.flashdaddee.com/Books-Technical/InsideCsharp/ 32ch11d.htm
http://citeseer.nj.nec.com/mcconnell92treebased.html
2. Weaker security.
The author simply failed to understand the C# security mechanism. It’s much more powerful and integrated that offered by Java. In fact, Java has two security mechanisms with overlapping functionality – very confusing. One of the reasons that many people avoid Java for numerical algorithms is its horrendous performance. Sometimes the ability to write optimized code is crucial. Also, take a look at how people are porting C++ toolkits (Gtk,Qt) to C# with ease. This would be torture through the JNI – which is really a low-level C API onto the Java VM – talk about unsafe code! The techniques that C# offers have very important uses.
3. The author fails to mention a number of incredibly powerful features of C#:
Examine Reflection.Emit, Codedom, System.Xml namespaces, the ability to query a graph of objects through XPath, delegates, custom meta-data (Attributes), support for jagged and non-jagged (true multidimensional) arrays. There is so much power here, it’s just very hard to see how Java is going to survive.
This article is one in a long line of shallow treatments of C# and Java comparisons. The author should do his homework.
Forget it man, I’ll take Eiffel over Objective C any day.
here, read this and you decide
http://archive.eiffel.com/doc/manuals/technology/oo_comparison/
Ehm…HOW is the C++/C# extends/implements syntax better than Java´s way of doing the same thing??
I prefer english over stupid shortcuts like “:” any day.
This subject rages on for ages … I’ve never offered my opinion, which was recently enhanced by a friend who pointed something out to me. Alot of people use this crap:
do {
if (err){
break;
}
} while (FALSE);
// do cleanup.
This is obfuscated code. It’s not clear that you’re breaking to go do your cleanup and leave the function, vs. breaking for some other reason … where as this is vastly superior, as it explicitly makes intent clear:
if (err){
goto cleanup;
}
cleanup:
// do cleanup.
This make the code obvious and clear. Anyone who says the first is clearer, is really arguing b/c they learned it that way, and are used to it. Of course the friend who pointed this simple comparison to me, often seems to likes to use like 4 labels in a function, NOW THAT I DON’T LIKE, but to each his own. The goto for the cleanup scenario, is really valueable.
“references are constant pointers.. big difference ”
const int *foo
same damn thing
“constant pointer in C++
In Java reference refers to class instances, while C++ pointers refer to memory address”
and you can use pointers to point to objects in C++.
it is all the same Java just gives you a little abstraction so you don’t have to work with the nitty gritty of the addressing.
Those are two very different function.
break is a very clear command. It is used for breaking out of loops, breaking out of if statements, and breaking out of switch statements. It is not supposed to be used to jump around code, and cannot be used like that. It will go to the next line after the loop/if/switch/etc.
goto is used for jumping around code. It is not intended to be used to jump out of code really, but more to jump around code. It is considered bad coding to use goto to jump around code. You could use a loop and function calls to achieve the same thing, but in a much cleaner and safer fashion.
I agree with you the first example is not good programming.
But I think the other one is not one good example either!
You are modelling something around “invisible blocks”.
Of course it is a matter of taste, but I don’t like to read code where the coder jumps close to anywhere inside a function.
I would probably make the cleanup code a function that would be called in place and then followed by a return or something similar.
But maybe I’ve programmed too much Lisp lately as I would have liked to implement this using recursion. Well, recursion is beatiful. The code gets short and don’t ever get into this battle of gotos!
“1. sloppy syntax pitfalls: the goto statement
is extremely valuable for producing more readable code in a number of cases.
Djikstra’s argued against gotos a long time ago, when sloppy use of this keyword was prevalent. This led to the development of powerful structured programming approaches to replace gotos. However, since then, a number of authors have pointed out the need for gotos to increase the clarity of code.”
I dunno about this point. I will take Djikstra’s side on this one for a while.
you read my mind.
realy, why was goto invented? becasue they did not have a way to make seperate functions and call them so they section off a peice of code with a flag and when you need to use the code you say goto<blah>
so why would you need a goto again? thats right so your program can become unpredictable…gotcha.
I don’t have any C# experience, but I’ve been working in C++ for 5 years and have 1 year of Java experience.
To GOTO or NOT to GOTO
In high level languages like C# and Java, I think GOTO is somewhat out of place. Most of the valid uses of GOTO are handled well by Java’s labelled break/continue mechanism. In C++, GOTO is valid, but only in highly optimized areas of code. I strongly disagree with Voltaire 42’s example. While it may seem clearer at first, it will be much more difficult to maintain. What will it look like when somebody inserts code between the loop and the cleanup: line? The “flow” of the program will be much more difficult to follow.
Operator Overloading
While operator overloading is a “sexy” feature of C++, I honestly haven’t ever found a place where it improves the readability of the code. It brings along with it a whole host of problems (such as making sure a+b == b+a and a++ == ++a. It isn’t rocket science, but it does sometimes involve counterintuitive behavior (especially when overloading non-arithmetic operators). While complex math code makes good use of this feature, but most code is fairly simple logic, not complex math. I just don’t feel that the added complexity is worth it for the 1% of problems out there that benefit from operator overloading.
The operator overloader question really comes down to one’s preference for power/elegance vs. simplicity/consistency. When used properly, these features can produce some wonderfully elegant solutions. However, generally, maintainability is improved when the programmer is restricted to more intuitive and consistent constructs. Neither side is 100% correct, but these feature certainly require a more experienced/skillful developer.
c# is improved language over java. ms saw everything that java did wrong and fixed it. how about little things like SIGNED DATA TYPE? hmm why is that missing from java? is that not boneheaded design decision?
that is not to mention that C# is faster than Java and will soon come with every windows computer on the planet. java on windows is old and decrepit and no one wants to run java applications. with .net u can’t tell u are not running a native application, it is that fast and blends in so well
*sigh*. Gotos have their places, and if used correctly do enhance readability. Did anyone even look at the JLS? Anyway, here’s an example of why gotos are useful, and do not contribute to spaghetti code. Let’s assume that you have a 2D array of names, and you want to go through all elements, looking for the name John.
String[][] names;
int xPos, yPos;
boolean bFound = false;
for(int y = 0; y < names.length; y++)
for(int x = 0; x < names[y].length; x++) {
if(names[y][x].compareTo(“John”) == 0) {
//found John
xPos = x;
yPos = y;
bFound = true;
break exitLoop;
}
}
exitLoop:
That’s in Java. In C++ or C, replace break with goto. If you work with loops within loops, breaks and gotos are useful. The code I presented above is possibly the cleanest way of breaking out of nested loops. The alternative would be to insert numerous boolean checks in the loops themselves, deteriorating performance, and obfuscating the code.
Yes, I do RTFM. Perhaps you should too.
Actually it’s the unsigned datatypes that are missing from Java. In any case, my opinion is that Java and C# are in the same ballpark feature wise, but I’ve seen Microsoft play the old “roach motel” scam far too many times to want to ever invest a significant amount of time and money into something they have so much control over. So, for political reasons, I choose Java (or better still, Python!)
References(in Java) aren’t constant pointers. With constant pointers, you can’t change what the pointer is pointing to. As such, this code would be illegal.
int a = 5, b = 7;
int* const p = &a;
p = &b;//illegal. Changing what pointer points to.
This is totally different from what references are in Java. In Java, references [u]are[/u] pointers. They behave exactly like pointers do, minus the ability to perform pointer arithmatic.
sure, gotos and breaks would be useful in that situation, but you could also just ass in the loop a check for a flag variable and when you find what you are looking for set the flag to what ev er it needs to be to not be valid in the loop test and you break out. is that a little slower? sure. is it harder to read? not if you comment it so taht the reader sees what you did.
good, then I was right in my first post.
so then I will pose to the people that denied what I said:
they are the same damn thing.
goto is one of the best choices available for error handling, expecially in non-GC’d languages where you must deallocate memory if an error condition occurs (so it isn’t as pertainent in languages like Java)
Use of fallthrough to create an easy way to roll back out of a complex function without leaking memory when an error occurs is, in my opinion, good programming practice.
Dijkstra would have the same type of code handled with deeper and deeper nesting. Compare the following:
var0 = allocator();
if(success_condition_one) {
var1 = allocator();
if(success_condition_two) {
var2 = allocator();
if(success_condition_three) {
var3 = allocator();
if(success_condition_four)
return success;
deallocate(var3);
}
deallocate(var2);
}
deallocate(var1);
}
deallocate(var0);
return error;
Deeply nested, ugly, and not very readable. Compare that to this:
var0 = allocator();
if(!success_condition_one)
goto err0;
var1 = allocator();
if(!success_condition_two)
goto err1;
var2 = allocator();
if(!success_condition_three)
goto err2;
var3 = allocator();
if(!success_condition_four)
goto err4;
return success;
err4:
deallocate(var3);
err3:
deallocate(var2);
err2:
deallocate(var1);
err1:
deallocate(var0);
return error;
This doesn’t apply only to dynamic memory, it can apply to any condition in which a function is altering state but an error condition requires the function return the altered state back to its original form before returning, otherwise the object/system is left in an inconsistent state.
There is, of course, another even uglier alternative, and that is to duplicate the error handling code for each branch condition in the latter. The problem then becomes as state changes within a function grow deeper, keeping all of these error handlers consistent becomes much more prone to human error.
I believe the use of goto in these sorts of situations provides the most elegant, readable, and easy to maintain method of error handling.
I keep hearing about how horrible C++ is because it lets you do too much. Maybe you don’t like goto, or reinterpret_cast, or operator overloading, or whatever.
Here’s an idea: don’t use those features! I never do, and C++ hasn’t complained once. If you’re worried that your employees are going to use those features, that’s what code reviews are for. Dock them some pay or something
I think both of those examples are ugly, actually. Try the “Resource Aquisition Is Initialization” meme. Failures should throw exceptions. In C++, destructors are called upon throwing. The destructors should do the cleanup.
The trick is that if and when all the operations succeed, you tell the objects not to destroy themselves when the function exits.
VarCleaner vc0(new Var);
VarCleaner vc1(new Var);
VarCleaner vc2(new Var);
VarCleaner vc3(new Var);
vc0.success();
vc1.success();
vc2.success();
vc3.success();
Much nicer, eh?
OMG that looks terrible
But if you’re using C, I suppose that’s what you’re stuck with. But if you’re using C++ or Java, that’s a very clear case for exceptions.
try {
var0 = allocator();
var1 = allocator();
var2 = allocator();
var3 = allocator();
} catch(exception e) {
//exception handling here
//deallocate whatever was allocated.
}
Sure, you could use a boolean flag, but would it be as clear and concise as the labelled break/goto? I have tried numerous ways of breaking out of such loops, and I’ve found gotos/labelled breaks the most clear and concise. Even Bruce Eckel (author of Thinking in C++ and Thinking in Java)agrees on this point, and advocates the use of goto/break in such a manner. It doesn’t create spaghetti code, and you’re not jumping to random places in a program.
The problem with your approach is that the exception handling is potentially ambiguous. I mean, you might be able to tell which variables were inititialized by setting them to 0 beforehand (in C++) and do the right cleanups based on that, but what if the operations were not just simple initializations?
There are many cases where you need to know just how far the process got before it failed. In that manner, Bascule’s approach actually surpasses yours, as pretty as yours may be
How about this instead?
for (int c=0;c<3;c++)
{
var[c]= condition(c);
if (var[c]==0)
return error;
}
return success;
(instead of)
var0 = allocator();
if(success_condition_one) {
var1 = allocator();
if(success_condition_two) {
var2 = allocator();
if(success_condition_three) {
var3 = allocator();
if(success_condition_four)
return success;
deallocate(var3);
}
deallocate(var2);
}
deallocate(var1);
}
deallocate(var0);
return error;
I was assuming that you’d initialise all your variables to NULL, and in the exception handler, you’d deallocate whatever variable was non-null. You’d just call delete, and let the destructor do what ever cleanup is necessary. That way, you’d isolate all the error handling into a separate block of code. It would be both pretty and functional, which is the important thing
Do you have any links to the method you posted? I’m interested in reading up on it. Another reason I like Java. It’s GC’d, variables are set to null (or 0) at declaration, and there’s the finally clause.
for (int c=0;c<3;c++)
{
var[c]= condition(c);
if (var[c]==0)
return error;
}
return success;
That code isn’t going to deallocate whatever was allocated before the failure occured. It’ll just report an error, leaving a memory leak.
would that not be a job more suited to the calling function?
–failed to understand the C# security mechanism. It’s much more powerful and integrated that offered by Java.
Much more? can you tell how more? You only can tell one thing is powerful or not by your purpose.remember, one person’s meal will be another person’s poison.
–ms saw everything that java did wrong and fixed it.
Everything? I think MS is far not the God, and you have no right to name it the name. FIXED–what a great word! Are you blind that can not see so many SPs and flaws come out from MS? Do not tell me you do not know.
–java on windows is old and decrepit and no one wants to run java applications.
Who else think Java on window is OLD? No one?
I think you can never be a good CEO or marketing people. Remember, you can not ask a apple give you a taste of pear—you should at first ask yourself what you really want and what you are doing—that is a good method to tell a person is a fool or not.
But if your goal is just making FUD, maybe you are doing the right things—Most of the folk is always stupid, they need other guys’ brains and eyes.
–for political reasons, I choose Java.
Yeah, also for the freedom! But you know democracy is always low-effective than monocrat–so let us be patient.
Without guns, you still can find many other weapons.
Given machine guns, you can use it as a hammer.
In my opinion, keep it, and use it with enough reason—we need more choice, right?
Sorry, I know I didn’t explain myself very well. I remember seeing an article about it recently…lemme see if I can find it.
In the meantime, here’s a (hopefully) better example.
struct VarCleaner
{
VarCleaner(Var* v) : var(v), ok(false) {}
~VarCleaner() { if(!ok) delete var; }
void success() { ok = true; }
Var* var;
bool ok;
};
VarCleaner vc0(new Var);
VarCleaner vc1(new Var);
vc0.success();
vc1.success();
Admittedly, that’s almost sort of an obfuscated version of what you did…heh. The advantage of having a seperate object comes in when you’re doing things that are more permanent than creating and destroying objects.
For instance, what if you were doing 3 database updates, where failing on any of them would leave the system inconsistent? You can’t undo all the operations in the “catch” clause because you need to know which, if any, were successful. You’d probably also agree that having a bool for every operation is ugly, and having multiple embedded try/catch blocks is even worse.
The trick is to templatize the Cleaner class to accept any undo function and run that upon destruction (unless success() is called), instead of passing it an object to delete upon destruction. Then you can do something like this:
database_operation_1();
Cleaner one(&function_to_undo_operation_1);
database_operation_2();
Cleaner two(&function_to_undo_operation_2);
database_operation_3();
// last op doesn’t need a cleaner
one.success();
two.success();
I think there’s a class out there called ScopeGuard that does something like that. Google should turn something up.
When I used gotos for a finite state machine, it worked out nicely. Using a loop, with a bunch of if- or case-statements inside was ugly in comparison.
How about this instead?
for (int c=0;c<3;c++)
{
var[c]= condition(c);
if (var[c]==0)
return error;
}
Uhh, that was supposed to be an abstract example of mixing branches with state changes that need to be undone in the event of an error.
Here’s some real C code of mine which uses this methodology:
article->poster = (char *)xmalloc(len + 1);
if(read(fd, article->poster, len) < 1)
goto err0;
article->poster[len] = ‘’;
if(r_16v(fd, &len) < 0)
goto err0;
article->title = (char *)xmalloc(len + 1);
if(read(fd, article->title, len) < 1)
goto err1;
article->title[len] = ‘’;
if(r_16v(fd, &len) < 0)
goto err1;
article->body = (char *)xmalloc(len + 1);
if(read(fd, article->body, len) < 1)
goto err2;
article->body[len] = ‘’;
return 0;
err2:
xfree(article->body);
err1:
xfree(article->title);
err0:
xfree(article->poster);
return -1;
I don’t see that as particularly ugly. I think code such as this is a rather bad example of when to use exceptions from the low level perspective. It will allocate memory for what could ordinarily be done with branches and jumps. The proposed OOP solution stated here is instantiating objects for the mere purpose of consistency checking, and will allocate more memory in the event of an exception.
However, if you prefer to write code that uses memory it doesn’t have to when it doesn’t have to in exchange for your code “looking better” to you, then go right ahead.
The above snippet is perfectly readable, in my opinion, and uses memory only where necessary, for dynamic data storage.
I think the biggest difference between Java and C# isn’t really syntax but concept and culture behind it.
When you sign up for Java, you’re really saying yes to the community. Even though Sun has not loosened the control over the language itself, they don’t control the implementation. Another words, Sun publishes the specification on the language, classes, and virtual machine and anyone can create implement based on those specifications. The implementation that Sun distribute is a reference implementation but not the only implementation. This allows anyone or any company to create their own implementation and sell them or distribute them as they wish.
With C# and largely with .NET it’s drastically different culture. What Microsoft is asking you to buy into isn’t a set of standards but rather they are selling their own implementation of the language, the platform, their set of development tools, and their operating system. You are essentially saying yes to whole suite of things not just a language. Microsoft doesn’t leave room for anyone else to create their own implentation. It is tightly controlled and Microsoft wants to be the only supplier of the .NET implementation.
The business model and culture surrounding Java and C# are very different and I think that is very important to consider when you are committing to one of them.
Some of the uses of goto that I’m seeing here are for breaking out of embedded loops (Wee Jin Goh). Java has loop “labels” that allow you to specify which loop you want to break out of.
loop1: for (int i=0; i < n; i++)
{
for (int y=0; y < m; y++)
{
…
if (errorOccurred)
{
break loop1;
}
}
}
// “break loop1” takes you here
I personally find this solution very elegant (I wish C++ and C# had it). It eliminates the need for goto in the vast majority of situations while still enforcing consistent program structure.
Also, those saying “if you don’t like a feature don’t use it” ignore the fact that most professional software development is performed by teams. Just because I choose not to use a feature in the code I write doesn’t mean that I won’t have to maintain code that uses it.
Bascule – I’d only use your allocate/deallocate solution in code where speed is absolutely critical. Otherwise, I’d use exceptions.
HereSince00 – this would have to be a pretty small state machine to fit easily into one method…
“…instantiating objects for the mere purpose of consistency checking…uses memory it doesn’t have to…”
The example class I posted uses all inline methods, and besides the pointer that we needed anyway, the only additional memory is the bool. In many implementations, a bool is 1 byte. And it’s created on the stack, not dynamically allocated.
If you’d prefer to have 2x the code size and several conditional statements and jumps just to save a byte of temporary stack space, go right ahead.
By the way, I don’t know what you mean when you say it “will allocate more memory in the event of an exception”. Could you explain that?
And Roy, I believe I specifically mentioned code reviews to avoid having to maintain bad code (or pay bad coders for that matter). It’s quite possible to write difficult-to-maintain code in any language. IMO, code reviews are essential for any project developed by a team. It’s not at all unheard of for a project manager to completely ban the use of a language feature.
Some java sycophant makes a comment on a message board and it winds up on OS News?
Anyway, I’ll summarize the guys problem with c# as “java dumbed down c++ just the right amount and now MS is giving too much choice back to the programmer”
Maybe he should just recommend VB to all programmers since he seems to think that programmers are too dumb to make intelligent decisions on their own.
Obviously this guy has been reading the jerk-fest going on various java message boards and is incapable of accepting the fixes that MS made to some of the Java brain damage. As someone else pointed out, why the hell would you leave out unsigneds and enums. I’ll tell you why – brain damage.
The real issue that java sycophants are bitter about is that Java is dead on the client-side and they just can’t accept it. Oh well, maybe if Sun hadn’t made such bad decisions on the gui side of the things, things would have turned out different.
By the way, for you people using mono, Visual Slickedit now supports code completion of c# on Unix platforms.
That’s what I believe: with the right logic and mindset, we can write the same program (in terms of functionality) by using any language. This, of course, has an exception, if the language itself is TOO limiting. We can’t expect people are able to write Oracle by using BASIC! (I mean BASIC, not VB).
Seriously though, I think the whole issue of using goto or not is hugely varied by the purpose and environment of programming. Back in school, when I was taking the Operating System class, I had an assignment of writing a UNIX shell. I found that, for the particular assignment, using goto to parse the pipe I/O is much easier when we need to do it inside a loop. So I used goto for what it’s purposed to do: jumped around the code. More precisely, I jumped back to the beginning of the for loop if a pipe was correctly constructed! That, of course, was very dangerous, and my classmates were all shocked as I did that. But it really helped me coding that assignment.
Now I’m working in a big company using C++. The above approach does not work anymore. First, of course, is we almost have no chance to use goto in MFC codes. Second, and the most important one, though, is a painful problem for real working environment: the code written by one person will be maintained by others. Frankly, “readability” varies from one to one. Something readable to one person may not be the same readable to others. Thus, the company has to establish a “coding standard”, which defines a base common set of what is readable to everybody in the programming department. Simply to say, geeky codes are not encouraged or even allowed in the department. I always used ? : in my school assignments, but I have to change this habit and use if/else in the company. Sure, if/else looks more cumbersome, but it ensures that at least everybody understands what this piece of code is doing. I used to code like
return ( error->Error() ? false : true );
See the problem? It has to be reversed to return/proceed correctly (anyone remember the famous “if(!strcmp(str1, str2))” delimma?). Of course we can say (!(error->Error())), but then in an environment mixed with MFC, ANSI C, and .Net environment (even worse, if RPG is there!), then this may not be consistant. (MFC uses 0 as FALSE, but some programmer used to C may use -1, and if you put a ! on it, the result may be undefined, depending on the language executing the code. Even worse, if true/false and TRUE/FALSE are mixed to use…) Now my supervisor encourages me to code:
if (error->Error() == false) // (or FALSE in MFC)
{
return true;
}
else
{
return false;
}
A coding standard’s purpose is twofold: to guarantee a consistent “look and feel” of the code, from both the users’ and the programmers’ perspectives; and to make programmers easier to work on codes constructed by other programmers. Sure, if you work on your own, or if you’re a group of people who knows everybody else’ coding style and way of thinking in the very first place, it’ll be fine to use geeky codes (and I agree that it’s fun); but in a real enterprise environment, where the codes need to be maintained all the times (and for a long time), coding in your own style may be said as “selfish”. I’m sure no one likes to maintain 100 kinds of styles of codes from 100 different programmers. Unfortunately, we sometimes really need to maintain codes from 100 different programmers, so the best we can do is to enforce a coding standard; that way, even if you don’t like it, you only hate 1 kind of style, not 100. =)
Talking about goto, it’s not that useful if you’re not doing heavy text parsing (like command-line interface and compiler) or any similar kind of complicated task, especially I do both of the above using ANSI C instead of C++. Now I use C++ a lot more, and by dividing the tasks into proper classes and member functions, things are a lot easier, as long as I always keep an updated version of UML graph and a structure flow chart. For additional features of a particular language, I would say just like my company says, use when necessary, avoid them otherwise.
In order to throw an exception, it requires additional overheads. Remember, exception is actually a regular class, nothing really different from a normal class we write in C++. In the case of an exception occurs, the program actually needs to construct a new class (either a generic one or an exception class you defined), initializes it (remember every class has a default constructor), and starts to throw it down the call stack, hopefully any function in the call stack would catch and handle it (first come first serve). If none of the functions you write in the call stack catches it, then the OS would have to handle it (since that’ll be the bottom of a user program’s call stack: the part of OS which starts the program), and that is what we called a “crash”. In the case of Windows 2000, the OS will have to start logging, display a modal dialog, and wait for the logging finished before it can be closed (or if the user clicks Cancel). Isn’t this little exception consuming much more resources than just a few variables?
Here’s a link on C/C++ User’s Journal that talks about Resource Acquisition is Initialization, the method sajiimori is talking about. http://www.cuj.com/experts/1812/alexandr.htm . A really good read.
Amazing, we’re actually having a good discussion instead of a bunch of idiots having a flame war. I’m actually learning stuff (especially ScopeGuard). Nice.
This is IMHO the most important feature C# has over java. The absense of value-types makes java completely unsuitable for all kinds of numerical computing, 2d and 3d graphics. All this is no problem in C# since it has value types (See the Directx9 c# api for example).
Operator overloading is a very nice feature when combined with value types. It lets you create user-defined data types that behave exactly like the built-in data types. And it is very hard to shoot yourself in the foot with operator overloading.
better mis-features OF C#. its a really good read, and quite quite technical: http://www.geocities.com/csharpfaq/
i am not participating this discussion much since i have posted it, but i must say operator overloading fucks up big project majestically. i had a nightmarish experiences with it. the reason is that the overloaded semantics are largely ambiguous. and using an overloaded operator thinking that it suits the semantics in mind does not create a compile time or run time error, but leads to wrong calculations, and nearly impossible to catch bugs on the big projects. in all the cases, everything that you can do with operator overloading can be done without using it. syntax will be a bit complex. so what?
nuff said. –: )
Last I heard, Microsoft explicitly prohibits any software created with Visual Studio.NET to be distributed under GPL. It’s sorta like furniture company that also sells table saw and says if you build furniture with it and give it away for free they will come after you with army of lawyers. I think Microsoft believes that it’s really “their” table saw and they are just renting it to you so they feel as though they have say in what you can or cannot do with the rented table saw.
Stack- or heap- allocating may be handled by the compiler and the virtual machine, without forcing the developer to think about this kind of optimization. Smalltalk has been doing this since mid-80ies (or even before!). Also, if you are going to write numerical software, or 2d/3d graphics software, why should you use an interpreted language such as Java or C#? Use FORTRAN, C or C++.
@CroanoN
syntax will be a bit complex, so what?
CroanoN, use Smalltalk and the syntax won’t complex anymore
Thanks for posting that link, interesting read.
Ive noticed that on disscussions about some aspect of programing that it is civil and intelegent….I think it it because all the trolls from the other discussions are not smart enough to know what to troll about
@Valkadesh: “why should you use an interpreted language such as Java or C#?”
why not? (by the way, neither Java nor C# is interpreted)
@Roybatty: “Obviously this guy has been reading the jerk-fest going on various java message boards and is incapable of accepting the fixes that MS made to some of the Java brain damage. As someone else pointed out, why the hell would you leave out unsigneds and enums. I’ll tell you why – brain damage. ”
fuck off miguel’s-balls-licker troll. you don’t know fuck about me. stop assuming, get a life. this is not Visual Lick Edit message board. and, by the way, it was quite a fast weekend.
> Last I heard, Microsoft explicitly prohibits
> any software created with Visual Studio.NET
> to be distributed under GPL.
MS prohobits that programms with GPL-like licenses link to VS DLLs. But that’s no problem, because the GPL forbids to link against “proprietary” libraries for longer time.
“Stack- or heap- allocating may be handled by the compiler and the virtual machine, without forcing the developer to think about this kind of optimization. Smalltalk has been doing this since mid-80ies (or even before!).”
The issue is not only about performance. It is also about semantics. For value types, equality means identity. For reference types, this is not nessecarily the case. So even if there was no performance penalty for not having value types, it would make sense to have them.
And value types give *huge* performance benefits even when they are allocated on the heap. Take an array like this:
Complex[] data=new Complex[1000000];
In C#, (assuming Complex is a value type) this is a continuous block of memory of 16 Megabyte size. In java, this is a 4 megabyte block of references and 16 Megabytes of Complex objects spread all over the heap. Can you imagine what this does to data locality and cache consistency? It is an absolute desaster performance-wise.
“Also, if you are going to write numerical software, or 2d/3d graphics software, why should you use an interpreted language such as Java or C#? Use FORTRAN, C or C++.”
Because I like C# and it is very fast (as opposed to java). Both java and c# come with very nice just in time/ahead of time compilers that give very good performance. Take a look at the new mono/mini JIT/AOT-Compiler. For some numerical computations it compares quite favorably to gcc. Really. Try it out.
And why should I use Fortran or C++? I *hate* fortran and I think c++ has a lot of useless features and not enough runtime type information.
I want to have the nice syntax, runtime type information, huge class library and platform independence of Java and C# with (almost) the performance of fortran or c++. And mono does exactly this.
If microsoft and/or mono add generics to c#, it will be the perfect mixture of ease of use and power (at least for a procedural/oo language
Of course if I could make money programming functional languages such as clean, I would probably prefer it over C#.
What I wanted to say is that, if you’re looking for the most performant code, you should use neither C# nor Java, but code the nearest possible to the ‘ bare metal’. In this case, the 10% performance penalty you have when using a JIT-compiled language (such as C# and Java) is a burdance too big to be ignored.
The issue is not only about performance. It is also about semantics. For value types, equality means identity. For reference types, this is not nessecarily the case. So even if there was no performance penalty for not having value types, it would make sense to have them.
And value types give *huge* performance benefits even when they are allocated on the heap. Take an array like this:
Complex[] data=new Complex[1000000];
In C#, (assuming Complex is a value type) this is a continuous block of memory of 16 Megabyte size. In java, this is a 4 megabyte block of references and 16 Megabytes of Complex objects spread all over the heap. Can you imagine what this does to data locality and cache consistency? It is an absolute desaster performance-wise.
I’m not saying that value types aren’t useful – what I’m saying is that the difference between value types and reference types should be trasparent to the user. You could accomplish this simply with a flag in the class bytecode set by the compiler (not the user!) at compile time, signaling the VM that instances of that class may be allocated on the stack. Add to this a shallow equality operator a la C++ (it being a real operator, or an equals() method), and you have all the advantages of the value types without having to bother about them.
In this way, the compiler could also make the VM allocate a continuos block of memory for your Complex array.
Because I like C# and it is very fast (as opposed to java). Both java and c# come with very nice just in time/ahead of time compilers that give very good performance. Take a look at the new mono/mini JIT/AOT-Compiler. For some numerical computations it compares quite favorably to gcc. Really. Try it out.
And why should I use Fortran or C++? I *hate* fortran and I think c++ has a lot of useless features and not enough runtime type information.
Regarding C# versus FORTRAN etc., I’d say that you should choose the best tool for the job, not the tool you like more, even if you hate that best tool. For heavy numerical computations, C# can’t be on par, performance-wise, with FORTRAN or C++. The same holds for graphics software (I’m talking about rendering engines and similar, not things like windows etc.). Also, in this kind of software you shouldn’t need RTTI or other reflective structures.
I want to have the nice syntax, runtime type information, huge class library and platform independence of Java and C# with (almost) the performance of fortran or c++.
As I said to CroanoN, if you want nice syntax, runtime type information, huge class library and platform indipendence, you should give Smalltalk a try
“I’m not saying that value types aren’t useful – what I’m saying is that the difference between value types and reference types should be trasparent to the user.”
I do not see how this can be done. Given the following code
int x=5;
int y=x;
y=6;
depending on wether int is a value type or a reference type, x will have a different value.
“Regarding C# versus FORTRAN etc., I’d say that you should choose the best tool for the job, not the tool you like more, even if you hate that best tool. For heavy numerical computations, C# can’t be on par, performance-wise, with FORTRAN or C++. The same holds for graphics software (I’m talking about rendering engines and similar, not things like windows etc.). Also, in this kind of software you shouldn’t need RTTI or other reflective structures. ”
So? Fortran will never be on par, performance-wise, with assembly language. But performance is not the only thing that matters. If I am ten times as productive in C# as in fortran, and the resulting program runs 10% slower than the fortran version, this is a price I am willing to pay.
Take for example a vector based painting program. It would benefit hugely from RTTI, reflection, interfaces and inheritance, but it still needs value types as an efficient way to store large amounts of vectors.
Or a pixel-based painting program. You will need some way to represent pixels of different formats. Classes are totally out of the question (try to represent a 2048×2048 bitmap image as java.awt.Color objects to see what I mean). And the lack of unsigned data types makes java absolutely unsuitable for this kind of stuff.
Are you suggesting that I should write a painting program in fortran?
Languages like C# and Java that run in a VM do not necessarily have to be slower than their statically compiled conterparts. Why should C or C++ be faster?
The only reason VM languages appear slower is that they are compiled at startup (C#), or compiled later on during execution (Java HotSpot). Once this step is complete, they are normally on par with statically compiled languages. Occasionally, they are faster even, especially now that Java supports SSE/SSE2 optimizations.
Java and C# can be statically compiled too, so there is no reason to assume that C or C++ are faster.
Ive noticed that on disscussions about some aspect of programing that it is civil and intelegent….I think it it because all the trolls from the other discussions are not smart enough to know what to troll about
You obviously haven’t been to boards like Javalobby :-).
But most programmers who want to learn, or who know what they are talking about tend to be more civil than trolls, who don’t have any clue as to what they are talking about.
While I agree that code reviews are ABSOLUTELY essential, I disagree that they solve the problem of poorly structure language features (goto, IMO). In my experience, the less you rely on reviews, the more effective they are. Code reviews that end up getting bogged down in simple syntax discussions are less effective at evaluating the logic of the code. Consistent coding standards help immensely at preventing this in actively developed code, but doesn’t address the problems of dealing with legacy code that was poorly engineered. By keeping things simpler syntax/feature wise, Java provides fewer “gotchas” than C++ for inexperienced developers. I still stand by my belief that gotos hurt maintainability because they impose so few structure constraints. This isn’t a big deal when a single developer writes and maintains a method, but becomes a problem when the code has been touched by 4 or 5 other developers of varying skill levels.
There are some misunderstandings here.
The system I am proposing is something that doesn’t quite exist. Obviously, there would be things which would need to be sorted out. Supposing a reference-based semantic for the assignment, then x’s value would be 6. But storing 6 in x could mean either allocating a new int in the heap and collecting the old value, or just popping 5 and pushing 6 on the stack, depending on whether the compiler has treated the ints as references or as value types. The whole process would be transparent to the user.
So? Fortran will never be on par, performance-wise, with assembly language. But performance is not the only thing that matters. If I am ten times as productive in C# as in fortran, and the resulting program runs 10% slower than the fortran version, this is a price I am willing to pay.
But maybe you can’t afford to lose that 10%… in such a situation, Fortran could be the best match between performance and productivity.
On the other hand, let’s say I am really writing a vector based painting program. Maybe my requirements don’t mandate for an efficient use of memory, so why should I bother using value types? I can happily stick with classes, and no one would be harmed
What I’m saying is that there is no ‘one size fits all’ language, but you have to choose the best language that allows to meet your requirements.
And definitively you shouldn’t write a vector based painting program in fortran <g>
There are some misunderstandings here.
“The system I am proposing is something that doesn’t quite exist. Obviously, there would be things which would need to be sorted out. Supposing a reference-based semantic for the assignment, then x’s value would be 6. But storing 6 in x could mean either allocating a new int in the heap and collecting the old value, or just popping 5 and pushing 6 on the stack, depending on whether the compiler has treated the ints as references or as value types. The whole process would be transparent to the user.”
So everything behaves like a reference, but the compiler can “emulate” the reference semantics using the stack or large arrays for performance reasons.
That would be very interesting, but so far despite all efforts such a thing does not exist for java, even though there is a huge demand. As long as such a feature does not exist, I am happy to use the value types provided by C#.
“But maybe you can’t afford to lose that 10%… in such a situation, Fortran could be the best match between performance and productivity.”
In most cases it is not a big deal to lose 10%, so going from fortran to C# is worth it. But when going from fortran to java you lose a factor of 5 or more, so it is definitely not worth it.
“On the other hand, let’s say I am really writing a vector based painting program. Maybe my requirements don’t mandate for an efficient use of memory, so why should I bother using value types? I can happily stick with classes, and no one would be harmed :-)”
Have you ever seen a good painting or drawing program written in java? In fact there are no popular client applications written in java. And IMHO the main reason is the lack of user-defined value types.
“What I’m saying is that there is no ‘one size fits all’ language, but you have to choose the best language that allows to meet your requirements.”
I agree. But C# comes a lot closer to a ‘one size fits all’ language than java does, and the .NET runtime comes reasonably close to a ‘one size fits all’ runtime. It is even able to handle functional languages efficiency.
By the way: Very interesting and polite discussion so far…
An interesting side note: There is no difference whatsoever between value semantics and reference semantics as long as variables are immutable. So functional programming languages are inherently able to optimize reference/value semantics tradeoffs without user interaction. One of the many huge advantage of functional programming.
Goto in .Net doesn’t work like previous languages. You can only use goto in switch statements where you want to quickly change switch statements on the fly.
Basically this article was done by somebody that has no idea about either language.
I’m happy that we agree on the ‘right tool for the job’ side. It’s been a very interesting discussion for me too.
So everything behaves like a reference, but the compiler can “emulate” the reference semantics using the stack or large arrays for performance reasons.
That would be very interesting, but so far despite all efforts such a thing does not exist for java, even though there is a huge demand.
Yeah… sometimes I feel that Sun is too much conservative to try and risk breaking the current paradigm with something really revolutionary. (/me sighs).
Have you ever seen a good painting or drawing program written in java? In fact there are no popular client applications written in java. And IMHO the main reason is the lack of user-defined value types.
I have to disagree here When Java was young, there were worse shortcomings, like no JIT compiling or a ridiculously low-powered widget toolkit. After that, no one thought that client applications could be written in Java.
But C# comes a lot closer to a ‘one size fits all’ language than java does, and the .NET runtime comes reasonably close to a ‘one size fits all’ runtime. It is even able to handle functional languages efficiency
Is it? I thought that .Net is a fine runtime for languages which are isomorphic to C#, and while other languages may run on the CLR, their performance is awful. Have you got any pointers on that?
An interesting side note: There is no difference whatsoever between value semantics and reference semantics as long as variables are immutable. So functional programming languages are inherently able to optimize reference/value semantics tradeoffs without user interaction. One of the many huge advantage of functional programming.
Yes, but this also stands in a pure OO language like Smalltalk, were the VM can determine at runtime whether a variable is immutable or not. I think the problem is that languages like Java or C# offer a twofold memory model: stack based (for primitive types in Java, for primitive and value based types in C#) and heap based (for objects).
“Is it? I thought that .Net is a fine runtime for languages which are isomorphic to C#, and while other languages may run on the CLR, their performance is awful. Have you got any pointers on that?”
There are plenty of very serious projects that target the .NET runtime, so I will just pick a few:
Standard ML is a functional language, so it is certainly not isomorphic to C#. Yet it runs quite fast on the .NET framework:
<http://www.cl.cam.ac.uk/Research/TSG/SMLNET/>
Eiffel is an object oriented language that has some interesting features such as pre- and postconditions and multiple inheritance. While multiple inheritance is not directly supported by the MSIL bytecode, it is reasonably easy to emulate using composition and interfaces. Hence Eiffel for .NET:
<http://www.eiffel.com/downloads/>
As much as I dislike microsoft business practices, one must concede that the .net framework and especially the lower level part is much better designed than the java VM.
I was a little irked at the statement “Java: All the greatness of C++ without the hassle.” Java and C++ are really not comparable to each other. C++ is a far more powerful language that C++. For a certain class of programs, this is actually a feature, not a liability. There is pretty much only one way to do any given thing in Java: the OOP way. In C++, there are easily a dozen and a half. The other day, I was doing some code to access ELF binaries. I was stuck writing a whole bunch of accessor function definitions, then a whole bunch of implementations. It was the matter of a simple template to reduce the job of implementing all those accessors to 1/4 the code. Features like operator overloading and templates allowed the Phoenix and BLL projects to implement almost transparent lambdas as a C++ library. In any given situation, half of C++’s features are not applicable. Operator overloading, for example, should only be used when the underlying types are numeric in nature (like matricies or complex numbers). But when you are working with numeric types, operater overloading allows for much cleaner code than all the Java equals() and lessThan() junk.
Interesting, I didn’t know that about C#. Since the use of goto is so restricted, I think it is fine in C#. In C++, I still feel goto should be restricted to highly optimized code.
Rayiner, operator overloading is NOT only used in C++ for numeric types. STL, for instance, uses operator overloading for its iterator syntax. Several fairly common C++ patterns, such as functors (which use the () operator), use operator overloading. BTW, I like the concept of generics, but feel that templates are poorly implemented in C++ (though part of this is due to my experience with crappy compilers).
I love a lot about the Java language. I feel the syntax is extrememly well thought out. As a platform it feels somewhat limited by the constraints that Sun has placed upon it. I am interested in C# (I hope Microsoft doesn’t kill Mono). Who knows, maybe the competition will improve both languages/platforms.
There are a lot of things I love about C++. However, I do feel that C++ leaves too much up to the developer by default. For instance, the compiler shouldn’t allow you to override a non-virtual function. Single parameter constructors should be explicit by default. These are just a couple of the things that make me feel C++ is too “messy”.
Well said on both counts. You named two of the most annoying features of C++ for me.
Java has a few, too. The biggest by far is that you have to have a “try” around every method call that could possibly throw. One of the purposes of exceptions is to get rid of the clutter that results when you have to constantly check for errors. More than half of the time, I just want the exception to percolate up to a higher context anyway, so the try/catch block is completely redundant in those cases.
….that of course enabling some “features” operator overloading brings some advantages. but thats not the problem. the problem is their misuse. saying opeator overloading should only be used in numerical applications in this way, or goto should only be used in this and this cases, or casting should be done in this and that ways is not a good thing, since, you cannot force people to do it. they basically lead to hard to determine bugs and spagetti code. there are millions of examples for them. unchecked exceptions in C#, for instance, is purely evil. (check the link that i provided before in this forum somewhere for why.)
c#’s and java’s performances are similar. one is good in some type of algorithms, the other is better on others. the performance can’t be the reason for selection. hw is fast enough anyway. if the problem base is really really resource hungry, lower level languages such as c, c++ are used anyways.
the .net has only one language MSIL, and all the other .net languages are different syntactical sugars of it, such as c#. the problem is not being isomorphical to c# but to be isomorphical to MSIL. can you show me 100 percent fortran.net? i don’t think so, since it is not possible. many .net languages are crippled versions of original languages to fit into .net vm architecture. they are being marketed as “aha! you see! a new .net language” by ms marketing machine. i agree that .NET’s vm architecture is more generic in the sense that some languages can be implemented more easily over it than Java’s vm, but that is not a big deal really. it has still its own limitations anyway. for instance, there are many languages over jvm too, including Eiffel.
c# really does not bring very important and valuable additions to java on the language level, and certainly does not bring a new paradigm. some of its features are nice, but they are, together with many more that are not related with c# will be encorporated into Java 1.5 anyways. check jcp site for the upcoming features. some of c#s features, although they make programming easy in terms of syntax, lead to hard to determine bugs. the regression level is high really.
in short, why should i use c# when there is java already working on all the platforms, optimized for years, and embraced by the industry anyway? it already become a standard. on how many platforms mono is working? how safe it is? what can i do with c# and not java? how many projects is there with c# on sourceforge for instance? half of the open source projects are already java projects. i’m not even touching industry success of c#. –; )
Eiffel is strongly based on multiple inheritance, while Eiffel.Net had to drop it (AFAIK) for a single inheritance model, just to fit into the CLR. Managed C++ can’t use multiple inheritance too.
The risk is that these languages would be just syntax variations of C# (modulo some syntactical sugar like pre- and post-conditions).
“Eiffel is strongly based on multiple inheritance, while Eiffel.Net had to drop it (AFAIK) for a single inheritance model, just to fit into the CLR. Managed C++ can’t use multiple inheritance too.
The risk is that these languages would be just syntax variations of C# (modulo some syntactical sugar like pre- and post-conditions).”
Eiffel for .NET *does* support multiple inheritance and even generics. I think it is done by a combination of object composition and interface inheritance. The nessecary glue code is automatically created by the compiler.
See this link:
<http://docs.eiffel.com/technologies/dotnet/eiffel_dotnet_language/3…
The limitation is that when you want to use your eiffel libraries in other languages such as C# and VB.NET, you can not use multiple inheritance. But that is not a big deal.
@CroanoN:
“c#’s and java’s performances are similar. one is good in some type of algorithms, the other is better on others. the performance can’t be the reason for selection. hw is fast enough anyway.”
That is wrong. There are many cases where C# outperforms java by a factor of 5 or more, but no cases I know of where the opposite is the case. In the rare cases where java performs better than C#, it is by a few percent and not by a factor of 5. If you can find a case where java outperforms c# by more than a factor of 2, please post the source code. I would be really interested. Honestly.
Hardware will never be fast enough, because when hardware gets faster you want to do more with it. People who have to use JBuilder always complain about its performance even on an Athlon system with 256MB.
“the .net has only one language MSIL, and all the other .net languages are different syntactical sugars of it, such as c#. the problem is not being isomorphical to c# but to be isomorphical to MSIL. can you show me 100 percent fortran.net? i don’t think so, since it is not possible.”
I gave an example of a language that is completely different in every aspect to C#, namely standard ML. Are you trying to tell me that C# and SML are “just different syntactical sugars”?????? That is ridiculous.
And it is definitely possible to write a Fortran77 or Fortran90 compatible compiler for MSIL, just like it is possible to write a Fortran77 or Fortran90 compatible compiler for x86, powerpc, alpha or the java vm. MSIL is turing complete, so I can write a compiler to MSIL for every language I can concieve. The difference between Fortran for the Java VM and Fortran for MSIL is that Fortran for MSIL will have decent performance.
by the way, neither Java nor C# is interpreted
Yes they are.
The biggest by far is that you have to have a “try” around every method call that could possibly throw.
Nope, you don’t have to do that. Just make sure your own method also declares that it might throw that exception (or a superclass of the exception), and then no explicit try/catch blocks are necessary.
by the way, neither Java nor C# is interpreted
Yes they are.
Yes, Java was interpreted back in ’97. Since ’98, it’s compiled (via a JIT compiler or HotSpot), and .NET was made to use a JIT right from the start.
> But that’s no problem, because the GPL forbids to
> link against “proprietary” libraries for longer time.
Lie.
http://www.gnu.org/licenses/gpl-faq.html#WritingFSWithNFLibs