Is C# better for games?

Started by
25 comments, last by Anarchi 22 years, 2 months ago
Quick fact sheet on the .Net framework: http://msdn.microsoft.com/netframework/prodinfo/frameworkfacts.asp

Intro to C#:
http://msdn.microsoft.com/vstudio/techinfo/articles/upgrade/Csharpintro.asp

Go cruise around the msdn.microsoft.com and www.gotdotnet.com websites for all the info you need on C# and .Net.

Edited by - jbattist on February 18, 2002 9:38:42 AM
Advertisement
quote:Original post by HenryApe


No, because you can perform platform dependent operations in C#, inside unsafe blocks, something that you can not do in Java.

There is nothing inherently platform dependent about what you do in an unsafe block - I think you are yet again confusing P/Invoke and the unsafe keyword. Unsafe blocks only let you perform pointer arithmetic, which should port without a problem in a language which has fixed sizes for all datatypes.

quote:
and ''pure C#'' optimizations, such as turning off the GC and removing bounds-checking.

You cannot use an unsafe block to turn off the GC. The thing you _can_ do is make sure the GC doesnt move an object while operating on it. As for bounds-checking - well, sometimes you can do without that overhead.
quote:
When you come across a JNI interface in Java you can be sure it means that platform dependent code is being used.

Any use of P/Invoke, COM Interop or unsafe blocks means that the assembly will not be trusted, and can only be run in a trusted environment.

I maintain the point that the word ''unsafe''(plus the fact that the docs generally advice against using it) makes it pretty clear that this is something you should only use after giving it some serious thought.
I''ve seen a lot of C# code, and unsafe blocks are used very seldomly.
If you are interested in more accurate details about unsafe blocks in C#, I suggest you check out these two articles by Eric Gunnerson: http://msdn.microsoft.com/library/en-us/dncscol/html/csharp10182001.asp and http://msdn.microsoft.com/library/en-us/dncscol/html/csharp11152001.asp



quote:
Yes, you do have to have a wrapper, but again, I do value the clear separation between cross-platform and platform-dependent code. Writing a wrapper did have functional consequences before JDK1.4, but with the mapped memory buffers in the new java.nio packages I think the differences that remain are mainly in the areas of clarity and safety.

I dont think those wrappers add anything to clarity. They are just another layer that has to be written and maintained. C# lets you use existing libraries without having to write a wrapper.

quote:
Most of the features in C# are ok and I really would not mind seeing the foreach keyword in Java,

How about properties, indexers, delegates, attributes, true multidimensional arrays, operator overloading and the ability to create assemblies dynamically?
quote:
but I do think the way C# handles unsafe code and the absence of checked exceptions are serious problems for library developement and code reuse.

Checked exceptions arent universally accepted in the Java community either - Bruce Eckel wrote the article "Does Java need checked exceptions?" - http://www.mindview.net/Etc/Discussions/CheckedExceptions
quote:
One of the big advantages for Java in J2EE development is that Sun has kept the language clean, C# feels more like a hack-job.

Java is cleaner because it has less features and gives you less flexibility?
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
quote:There is nothing inherently platform dependent about what you do in an unsafe block

Exactely, so when you get an unsafe assembly you can not be sure whether the author has just used the unsafe code to speed up his library by removing bounds-checking or whether the code makes calls to the native platform.

quote:How about properties, indexers, delegates, attributes, true multidimensional arrays, operator overloading and the ability to create assemblies dynamically?

Properties, delegates, attributes, foreach are all just different ways to do things that can be done in both languages. It is a matter of personal taste what you prefer and the only thing I miss in Java is foreach, I'm glad that I will not have to learn and look out for the rest of them in other people's code. Operator overloading and indexers have a tendency to destroy clarity so I think Gosling made the right choice when he kept them out of Java.

About assemblys, you can create JAR files dynamicly in Java too, but most times you do not have to since Java's dynamic classloading does not require that you provide an assembly via an URL to load a class.

I have read that true multidimensional arrays can be useful for certain technical applications, but I have never been in a situation where I have needed whatever functionality it is that they provide over Java's nested arrays. I have also not seen them on the Request For Enhancement list for Java so I doubt they are very needed.

quote:Checked exceptions arent universally accepted in the Java community either - Bruce Eckel wrote the article "Does Java need checked exceptions?"

Is any feature universally accepted in any programming language community? I think checked exceptions have greatly helped library building and code reuse in Java, especially since they automaticly show up in auto-generated code documentation. I am sure unchecked exceptions thrown inside C#'s properties will help drive aspirin sales.

quote:Any use of P/Invoke, COM Interop or unsafe blocks means that the assembly will not be trusted, and can only be run in a trusted environment.

I am not sure how much this means since security policies are normally set to trust local assemblys.

quote:Java is cleaner because it has less features and gives you less flexibility?

I think cleanliness IS a feature that is closely related to cooperative development and safety. I value clarity and cleanliness over most features that do not actually provide new functionality but allow programmers to perform the same task in many different, some often confusing, ways. Having too much flexibility is bad in all forms of design, including programming language design. Maybe you do not believe in code conventions either since they hinder flexibility...

Edited by - HenryApe on February 18, 2002 1:56:06 PM
quote:Original post by HenryApe
Exactely, so when you get an unsafe assembly you can not be sure whether the author has just used the unsafe code to speed up his library by removing bounds-checking or whether the code makes calls to the native platform.

You may have a point there, but you are still confusing the keyword ''unsafe'' with the general trust level attributed to an assembly.
quote:
Properties, delegates, attributes, foreach are all just different ways to do things that can be done in both languages.

Of course - but these features invite cleaner looking code, which you have been promoting all along.
However, as far as I know there is no mechanism similar to attributes in Java. You cannot attach arbitrary metadata to classes, methods or method arguments.

quote:
Operator overloading and indexers have a tendency to destroy clarity so I think Gosling made the right choice when he kept them out of Java.

These things destroy clarity too:
  Complex c1 = new Complex( 4, 2 );Complex c2 = new Complex( 3, 1 );Complex c3 = (c1.add( c2.times( 4 ) ) ).dividedBy( 5 );  

Operator overloading(an indexer is just a special case of oo) lets you write code in a way that is more natural with regard to the datatypes involved. I _know_ there have been requests to implement oo in Java as well.

quote:
I am not sure how much this means since security policies are normally set to trust local assemblys.

Your point being?

quote:
About assemblys, you can create JAR files dynamicly in Java too, but most times you do not have to since Java''s dynamic classloading does not require that you provide an assembly via an URL to load a class.

I''m not so sure you understood what I meant. .NET has a whole class hierarchy for creating code on the fly - particularly useful for script engines and compilers. This namespace is what the Mono C# compiler uses to generate code.

quote:
Maybe you do not believe in code conventions either since they hinder flexibility...

A code convention is a conscious decision to limit yourself to a subset of the featureset available. It is hardly comparable to being forced by the language designer to accept a limited featureset.





The world holds two classes of men -- intelligent men without religion, and religious men without intelligence. Abu''l-Ala-Al-Ma''arri (973-1057; Syrian poet)
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
quote:Of course - but these features invite cleaner looking code, which you have been promoting all along.

I do not necessarily think they invite cleaner code, they just add to the learning curve of the language by letting programmers solve one problem in multiple ways.

In Java you can just declare an interface instead of using a delegate. The only benefit that I have heard of for using a delegate is that delegates support static methods while Java's interfaces do not. However, one of the top 25 RFEs at JavaSoft is to allow static methods in interfaces so it seems that the problem might be solved cleanly, without adding feature bloat in the form of delegates.

quote:However, as far as I know there is no mechanism similar to attributes in Java. You cannot attach arbitrary metadata to classes, methods or method arguments.

Sure, there is no standardized way to attach such data to Java, but AFAIK attributes are currently only useful to support COM and .NET. If someone comes up with a need to standardize metadata for Java classes, they can just create an interface that returns such metadata, letting classes that want to attach such metadata implement the interface.

quote:Operator overloading(an indexer is just a special case of oo) lets you write code in a way that is more natural with regard to the datatypes involved. I _know_ there have been requests to implement oo in Java as well.

Yes, and I know it was a very conscious design decision to leave operator overloading out, a decision that I support.

quote:I'm not so sure you understood what I meant. .NET has a whole class hierarchy for creating code on the fly - particularly useful for script engines and compilers. This namespace is what the Mono C# compiler uses to generate code.

I guess it would be nice to have that in the standard library, but I know such libraries exist for Java too. I did dynamic code generation, compilation and class loading in Java at the last place I worked, even though I am not sure where they got the library I used. The closest you get to this with the standard library is that Sun is letting you redistribute javac with your applications these days

quote:A code convention is a conscious decision to limit yourself to a subset of the featureset available. It is hardly comparable to being forced by the language designer to accept a limited featureset.

Actually, modern development methodologies such as Extreme Programming do advocate enforcing code conventions too. I think the analogy between clean language design and code conventions is pretty good since both are about esthetical limitations rather than functional ones. They are also similar since you do not need either when working alone but really benefit from both when developing with others and using other people's libraries.

Edited by - HenryApe on February 18, 2002 6:34:53 PM
Extreme Programming?
this sounds like the sport for me (since i suck at skateboarding)!

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
More info at http://www.extremeprogramming.org/. It is actually a very flexible and nice development methodology.

This topic is closed to new replies.

Advertisement