News for hackers. Stuff that matters.
Re:Asynchronous Programming in C# by pif on Tuesday April 30, 2024 @07:05AM (#40209630)
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!

Re:Asynchronous Programming in C# by gpderetta on Tuesday April 30, 2024 @07:51AM (#40209977)
As 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.

Re:Asynchronous Programming in C# by xandrius on Tuesday April 30, 2024 @08:06AM (#40210106)
Your edit seems to show your awareness but it's a plus for languages not to let developers do literally anything they want.
Re:Asynchronous Programming in C# by gpderetta on Tuesday April 30, 2024 @11:14AM (#40211912)
You are not wrong, but programmers, uh, find a way.
Re:Asynchronous Programming in C# by alkonaut on Tuesday April 30, 2024 @07:17AM (#40209718)
> 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)

Re:Asynchronous Programming in C# by actionfromafar on Tuesday April 30, 2024 @07:24AM (#40209784)
Thanks, 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.
Re:Asynchronous Programming in C# by jiggawatts on Tuesday April 30, 2024 @07:55AM (#40210005)
> 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.