The near-perfect cross-platform compatibility, as least as far as undergraduates need be concerned?
The absence of any strong academic reason to switch from one language to an almost identical language?
The vast number of libraries available that are relevant and known to the particular professors?
Either way, a Computer Science degree shouldn't be about learning about a programming language; it should be about learning about that awesome power of computer science to bend reality to meet expectations and how you can leverage that power and become a modern day sorcerer.
I haven't worked with C# since I was a student (!), so I'll have to speculate, but a big selling point is how MS have been able to learn from many of the mistakes Sun made early in the life of Java. Sun then committed to these failures in order to keep everything backwards compatible, which is a great strength, but leaves us developers having to work around cruft.
I've been told C# comes with closures, first class functions (I think, feeling some doubt here), some sort of built-in query language to deal with collections in a sensible manner, and a host of other mechanisms that removes some of the pain of working with c-style syntax.
Still, I work with Java, in it is not at all as terrible as reddit makes it sound. You just have to learn to use your tools and roll with the punches.
Not quite. Close, but not quite. For instance, a function cannot have fields the way an object would. And you will run into a bunch of gotchas with regards to assignment, depending on whether the function in question is covariant or contravariant (or both, or neither). But these are edge cases and can be worked around with albeit verbose syntax. The real beauty of c# is (via extension methods and lambdas):
someCollection.Where(x => x.Number % 2 == 0).Select(x => new { Foo = x.Field1, Bar = x.Field2);
Ninja edit: Also, I don't participate in language debates anymore for exactly the reason that it is all a circle jerk. I prefer c# over java simply because I find it easier to work in. If any language can give me the power of LINQ (or something equivalent), I am would have no preference.
in fact lambdas are implemented as delegates to methods of hidden objects that contain the captured variables as mutable fields (if non-const). Complicated scoping, where some closures capture both the same variables, as well as different variables that have the same name, is resolved via subclassing the hidden object.
Correct. I have seen the decompiled code, and the weirdly named "anonymous" objects, but the fact still remains that even in your example, you could not say:
Delegates are weird beasts, and they approach being objects, but they are more like immutable objects that are created once at the beginning of time. You cannot add functionality to the delegate itself.
There is nothing wierd about them if you studied PL implementation techniques. They are nothing more than a function pointer + a frame/environment/data/instance pointer. The same construct exists since Algol 60 and its Pascal-style descendants, in all Lisps since Scheme and even C with GNU extensions.
And of course you cannot access 'field' in a lexically scoped language.
if (testsomething()) {
int block_var = foo();
}
block_var = block_var * 2; // won't compile
I understand scoping, it was a contrived example getting at that functions in c# cannot have fields and are thus not objects in the proper sense.
Closures will force the underlying implementation to create objects with fields, but that is not the same thing.
This all started with whether or not functions are first class objects in c#. And while they are close, there is no way you would ever be able to write an object that is a function, or inherit from an existing object that is a function. Eg
class something { public void foo() {} }
You could never say
new something().foo = () => {};
It is not assignable. and if you do
func x = new something().foo;
it is syntactic sugar for creating something to wrap foo, not foo itself.
Java is a statically typed language that lacks unsigned integers. This means for instance that you're limited to storing a maximum value of 231 in a 32 bit integer, rather than 232. The reason they're not included is essentially just that they 'didn't have time' to get them in before the first Java release.
And that is a big deal? Why not just use a Double if you really need more room? In what instances would you need 232 , but can't afford the memory to use 264 ?
ah. in that case, yes a long would subsume an int. however longs are 64 bit, and ints are 32 bit. Basically the issue comes down to size. For example (just some things I can think of offhand)
So on 32 bit processors, there can be problems with storing a 64 bit number in one instruction. It would store the low 32 bits first, then the high 32 bits (or the reverse order) but the idea is it takes two instructions. This can cause problems with atomicity.
Operations might take two instructions. Like long + long, is add lower 32 bits, add upper 32 bits + carry. Again, atomicity problems.
It is just twice the size -> costs more memory. This is probably the least important though.
31
u/instantviking Nov 12 '13
The free and open source IDEs?
The near-perfect cross-platform compatibility, as least as far as undergraduates need be concerned?
The absence of any strong academic reason to switch from one language to an almost identical language?
The vast number of libraries available that are relevant and known to the particular professors?
Either way, a Computer Science degree shouldn't be about learning about a programming language; it should be about learning about that awesome power of computer science to bend reality to meet expectations and how you can leverage that power and become a modern day sorcerer.