Gosling said that "[C# is] sort of Java with reliability, productivity and security deleted." (from Wikipedia)

  • 10
    He means "I think we should start a flame war discussing which language is best" – Matthew Aug 24 '16 at 22:31
  • @Matthew but what if one indeed is better than another, isn't it important to know ? – R S Aug 24 '16 at 22:32
  • Also, linked from the exact same wikipedia article you referenced: cnet.com/news/why-microsofts-c-isnt – Matthew Aug 24 '16 at 22:32
  • 1
    @Matthew disagree 200%. He means Discuss this ${blog} – gnat Aug 24 '16 at 22:33
  • 5
    @RS Whatever he meant he said it in January 2002. That's before the C# version 1.0 specification was written. If you had any idea how much has changed since you wouldn't be asking this question. – Alternatex Aug 24 '16 at 23:01

C# incorporates "unsafe" capabilities that allow pointer manipulation. C#'s underlying platform, CLR/CLI (.NET bytecode), was intended to be somewhat more language agnostic than Java (and Java's byte-code). .NET supported, for example, what was called Managed C++ (I have the T-shirt!), though that never really caught on. Managed C++ supported managed as well as unmanaged objects.

C#'s unsafe capabilities allow pointer manipulation, and so, reduce reliability and security as they these extensions are not type safe.

However, the unsafe capabilities are extremely useful. For example, you can memory map files and access the file mapped content without constantly copying bits of the mapped file into some other type-safe object (avoiding both the copy and the generation of soon-to-be garbage).

Further, the "unsafe" features are nicely contained. For one, you can declare whether your program wants to allow any unsafe features at all. For another, if you choose to allow them, then you can clearly locate where any unsafe features are being used (via the keyword unsafe)!

(Note: new language Rust also has a similarly well-contained unsafe capability.)

Still, undisciplined use of unsafe can land you in the same territory as C or (true) C++, with crashes much delayed after some buggy code sequence. I think that Gosling was saying that if you allow unsafe code, then the whole program is suspect, maybe even the whole language: and he's not incorrect from a logical point of view.

However, I think that history is showing that "unsafe" capabilities are not the big safety problem it was presumed to be: that unsafe can be avoided, or, judiciously used-to-advantage, just like invoking native code/APIs (which Java and C# both allow).

I'm guessing that the productivity part of the argument comes from the delayed bugs that happen when unsafe is allowed.

| improve this answer | |
  • "For example, you can memory map files . . ." Not the best example, since you can also do that in Java since version 1.4 (2002). – Kevin Krumwiede Aug 25 '16 at 5:04
  • @Kevin, the whole quote is "you can memory map files and access the file mapped content without constantly copying bits of the mapped file into some other type-safe object (avoiding both the copy and the generation of soon-to-be garbage)". Are you saying this fully the case? (Sure we can memory map files in Java, but in C# you can directly access that memory, i.e. no "read" method invocation is required, just pointer access.) – Erik Eidt Aug 25 '16 at 5:07
  • Yes, if I understand what you mean. You can read the raw bytes of a memory mapped file as primitive bytes. More practically, a type-safe object can encapsulate its use of a memory mapped file instead of holding all that data on the Java heap. – Kevin Krumwiede Aug 25 '16 at 5:12
  • @Kevin, using a "read" call to get those bytes into a type-safe object? That's not the same. In C# you don't need to do a "read" call to get the bytes at all as you have direct access if you want to use unsafe, though again, you don't have to use unsafe if you don't want, and can still access memory mapped files by copying data portions into byte arrays or some such (i.e. a "read" call) . – Erik Eidt Aug 25 '16 at 5:12
  • 1
    @Doc, (1) I agree, though he had a point he was trying to make and I try to respect that. And (2) wow, who knew? en.wikipedia.org/wiki/C%2B%2B/CLI Thanks for pointing that out. I did not realize they had made another effort in that direction, and that it was still supported today, and that it is popular! I'm going to wear my Managed C++ t-shirt today! – Erik Eidt Aug 25 '16 at 14:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.