4 ms·
Coming from C++, I hate C# for the nice things that they removed, like const, value-based equality operators, non-null references and powerful templates. It to
by pif 2y ago
Coming from C++, I hate C# for the nice things that they removed, like const, value-based equality operators, non-null references and powerful templates.
It took several versions of the language to have readonly and records. Non-null references are just a bunch of compiler warnings rather than a first-class type.
Generics work, but type constraints are a joke. In particular, the ~new()~ constraint shows the disregard MS has always had for object-oriented programming: objects are supposed to be fully constructed; parameterless constructors are to be the exception, not the rule. On a similar note, record struct insist on having a parameterless constructor that cannot be disabled.
Furthermore, the language is mildly-typed (I'd say strongly if it wasn't for non-null references), but the framework is not typed at all! How people could write "public virtual bool Equals(object other)" with a straight face is beyond me!
- alkonaut 2y ago> How people could write "public virtual bool Equals(object other)" Well it was created before generics in .NET one and can't be removed, that's the simple answer. But yeah, making object equality customizable virtually was probably the worst design mistake in C# and .NET. Having to specify the comparer explicitly when creating e.g. a Set collection would have been so much better for quality. The second worst mistake was defaulting CultureInfo to the system culture (i.e. making methods like float.Parse()/ToString() take the system culture into consideration instead of requiring everyone to pass in the required behavior)
- actionfromafar 2y agoThanks, that explains my mixed feelings. C# is very good to me, I feel very productive, but it also feels like "stricter Python" or something, which is not exactly what I expected, after being exposed to C++ for a great while. C++ occupies such a weird mix of formalism and "here's a knife, do something with the knife", but I've found that since a few years back I almost never have a program crash on me in C++. Just logic bugs. I must have found treaded garden paths.
- gpderetta 2y agoAs a C++ programmer, the first time I had to write some complex generic code in C# I was annoyed that a common C++ pattern of macros+templates for registration of factory functions wasn't directly expressible in C#. My recollection is fuzzy, but I hit exactly the inability to constraint new that you mention. Then I found out about the ability to introspect and modify lambda expressions and generate code at startup time, which obviated the need for a template with constrained new, and I was blown away by that power. I was also very pleasantly surprised that C# had very easy to use multiple dispatch. So, C# is an extremely powerful, but you can't always port C++ idioms 1:1. edit: and before you ask, yes, I'm a recovering complexity addict.
- jiggawatts 2y ago> public virtual bool Equals(object other) .NET 1.0 was a direct copy of Java, so these Object methods are inherited from there. It's compatible enough that it's possible to transpile Java Bytecode to run on the .NET runtime and vice-versa.