News for hackers. Stuff that matters.
Re:Asynchronous Programming in C# by romanovcode on Tuesday April 30, 2024 @06:25AM (#40209309)
Offtopic but I really really like C#. Such a great and easy language to work with! It's a shame that people do not choose it over Java because of M$-bad rhetoric :(
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.

Re:Asynchronous Programming in C# by bazoom42 on Tuesday April 30, 2024 @06:45AM (#40209486)
I also prefer C# to Java, but there are reasonable arguments for Java. While the language is inferior, the Java ecosystem is superior to .net, and this might be more important.
Re:Asynchronous Programming in C# by aleph_minus_one on Tuesday April 30, 2024 @06:51AM (#40209535)
> the Java ecosystem is superior to .net, and this might be more important.

This depends a lot on what you want to do in your program. Of course, for example, for interacting with other Microsoft technologies, .net has a better ecosystem.

Re:Asynchronous Programming in C# by smaudet on Tuesday April 30, 2024 @09:44AM (#40210907)
I also find binaries (at least on Windows, unsure of nix) are much easier to hook into than what I remember from Java (perhaps it has changed)...

About as easy as Python, at least.

Which, for MS, made a lot of sense, they wanted to hook win32 apis. Java doesnt care, as much...

Re:Asynchronous Programming in C# by neonsunset on Tuesday April 30, 2024 @10:10AM (#40211118)
Unix is trivial too

    unsafe
    {
        [DllImport("libc", EntryPoint = "write")]
        static extern nint Write(nint fd, byte* buf, nint length);

        var text = "Hello, World!"u8;
        fixed (byte* ptr = text)
        {
            Write(1, ptr, text.Length);
        }
    }
Re:Asynchronous Programming in C# by albertopv on Tuesday May 07, 2024 @02:09AM (#40282846)
And for non MS serious enterprise development Java ecosystem is way ahead.
Re:Asynchronous Programming in C# by AbuAssar on Tuesday April 30, 2024 @06:52AM (#40209538)
what about kotlin?
Re:Asynchronous Programming in C# by nkozyra on Tuesday April 30, 2024 @06:40AM (#40209448)
It still has some platform dependency that Mono or .Net Core doesn't fully solve.

It's a very pleasant language to work in, especially compared to Java, but there are so many other really nice C adjacent languages in the field that it's hard to argue for if you're not in that ecosystem.

Re:Asynchronous Programming in C# by virtue3 on Tuesday April 30, 2024 @06:58AM (#40209572)
I think that might have been the case a while ago but they have even dropped .net-core and it's now just .net and cross platform.

It appears to have been the case since .net 5 (2020) (I've also stopped paying attention to MS a bit before then).

"Yes, .NET 5 is cross-platform and can be installed on Linux, Mac, and Windows. It aims to provide a consistent development experience across platforms by unifying different .NET flavors, including .NET Core, .NET Framework, .NET Standard, and Mono. .NET 5 also aligns all frameworks to support a common set of APIs, making it easier to build cross-platform libraries."

Re:Asynchronous Programming in C# by toyg on Tuesday April 30, 2024 @07:03AM (#40209618)
Yeah but the way they've done it, iirc, is by cutting libraries out of Core that really should be in there. I remember looking recently at some pretty basic stuff that broke in 6, simply because for some reason the relevant APIs (which were pretty low-level and not really related to anything driver-specific) were marked as Windows-only and ripped out of Core and Host packages.

So in theory it's all independent but in practice the best bits are still on Windows.

Re:Asynchronous Programming in C# by nkozyra on Tuesday April 30, 2024 @07:35AM (#40209864)
This was my experience trying to rewrite a service about a year ago.
Re:Asynchronous Programming in C# by smaudet on Tuesday April 30, 2024 @09:49AM (#40210936)
It has been amusing watching them try to get cross platform going, I used to hear how they (c#/.net) did such a good job with backwards compatibility, however Java had been doing crazier platforms for longer and their cross platform/backwards compat is in a much better state... although they are much more difficult to use to integrate deeply with a system.
Re:Asynchronous Programming in C# by davidfowl on Thursday May 02, 2024 @02:27AM (#40233278)
What stuff was that?
Re:Asynchronous Programming in C# by neonsunset on Tuesday April 30, 2024 @06:58AM (#40209573)
And C# is the nicest of them (because other options are worse in one aspect or another, especially performance).
Re:Asynchronous Programming in C# by vsnf on Tuesday April 30, 2024 @07:01AM (#40209601)
There are many metrics by which C# is the nicest language, but after 10+ years of doing (and loving) C# development, I find that I prefer Dart as a C#-like language these days.
Re:Asynchronous Programming in C# by alkonaut on Tuesday April 30, 2024 @07:17AM (#40209723)
What dependencies/limitations are that?
Re:Asynchronous Programming in C# by keltex on Tuesday April 30, 2024 @08:06AM (#40210102)
The biggest one I've run into is GDI support (Graphics Device Interface). This covers things like two-dimensional vector graphics, imaging, and typography. So simple things like transforming or drawing images are no longer supported.

There are decent third party open-source libaries like SixLabors/ImageSharp that have stared to fill the gap.

Re:Asynchronous Programming in C# by alkonaut on Tuesday April 30, 2024 @10:24AM (#40211249)
System.Drawing was always just a wrapper for GDI(+), and you CAN use it on Linux via using System.Drawing.Common which is a wrapper for GDI+ (Windows) or something else like libgdi+ on non-windows. It works - but it feels more like a compat hack than anything else. System.Drawing wouldn't look the way it does if it wasn't designed to be a Windows only API around GDI+. ImageSharp was always a good lib but now the license was murdered. Hopefully a true OSS fork will come along. SkiaSharp is also a good alternative, especially if you also need the drawing bits.

Missing a Graphics Library in .NET (5-8) is just half the story. It's of course missing an entire UI library too. But Microsoft, perhaps wisely, chose not to also implement a whole xplat UI library. Avalonia/Uno/etc are already there.

Re:Asynchronous Programming in C# by papichulo2023 on Tuesday April 30, 2024 @06:38AM (#40209433)
I havent use it a lot but my main issue with the language is 3rd party libraries. MS libraries are great but all the rest seem to be enterprise-milking, poor wrappers or sdk for some cloud service.

The other one is that it is not always clear the context on which you can use certain APIs.

Re:Asynchronous Programming in C# by hnthrow289570 on Tuesday April 30, 2024 @08:41AM (#40210403)
>MS libraries are great but all the rest seem to be enterprise-milking, poor wrappers or sdk for some cloud service.

The biggest example are PDF producing/converting libraries, which I have no doubt make millions in licensing.

Re:Asynchronous Programming in C# by highwaylights on Tuesday April 30, 2024 @06:49AM (#40209522)
This to me is the biggest drawback.

The language is truly lovely to work in, moreso than I think it gets credit for unless you've a lot of experience with it. It's just very thoughtfully designed, and MS support their own components really well and for a very long time.

The problem is that NuGet never became npm, gem or pip. The open-source community never really embraced C# (for understandable reasons) and it meant that the void there was filled largely by projects that couldn't get much traction and enterprise component vendors like Telerik.

I'm not in any way knocking companies that make their money selling these components by the way, I just think the message that people looking from the outside are seeing (rightly or wrongly) is that there's a tax payable to third parties on absolutely every level of this stack so why build with it? What's my incentive to start learning it when I can pick up node / React / Next / Python / etc. for free and start working right away with free tools? And that all shows in the ecosystem.

Re:Asynchronous Programming in C# by neonsunset on Tuesday April 30, 2024 @07:06AM (#40209632)
You must be joking if you refer to npm packages or ruby gems as examples of good and healthy (!!!) ecosystems.

OSS adoption is an ongoing process, that doesn't happen overnight. The attitude in this and adjacent comments is a good showcase that even after 8 years, once your average developer has settled in a particular mindset, it becomes a matter of enforcing tribal consensus even when the facts change.

If you also ever actually used .NET and nuget packages (in a post-netframework period), it would be apparent that the statement is simply not true.

Re:Asynchronous Programming in C# by highwaylights on Tuesday April 30, 2024 @08:01AM (#40210060)
Respectfully: I’ve used both quite a bit, and have used .NET since the first release.

If I need a package to perform a task that I think other people surely must have brushed up against in the past then I know it almost certainly exists in npm. That’s just not true for NuGet, as much as it would be better for the ecosystem if it was. This shows in the contributions to each, and the contributions (in terms of volume) are much higher for npm.

Re:Asynchronous Programming in C# by neonsunset on Tuesday April 30, 2024 @09:21AM (#40210700)
Nuget did not exist until around .NET Framework 4.0 (which was 14 years ago).

I specifically noted the post-.NET Framework experience. It is a continuous problem that community demands from the standard library and/or sdk to ship something it has no business shipping (like the sibling comment complaining about System.Drawing, it is truly an 8th OSI layer issue). And when there's an OSS solution, there is a stark difference in comments between developers who understand that OSS projects are projects of collaborative development (meaning that submitting and issue you care about may involve a degree of contribution) and the ones which demand paid level of support for free.

JavaScript is also just generally massive. Surely you're not going to hold it against Rust that Rust projects are less frequently contributed to? C# and .NET are unique language and platform which do overlap with Java and JVM, and other similar class of tools but do solve problems the latter cannot, or solve the ones that they can but in a frequently better way (for example: trying to reach performance ceiling in Java requires way uglier tricks with worse results rather than writing clean byref/pointer based C# code with structs and struct generics).

Re:Asynchronous Programming in C# by Const-me on Tuesday April 30, 2024 @07:56AM (#40210012)
> all the rest seem to be enterprise-milking, poor wrappers or sdk for some cloud service

Here’s 8 third-party libraries I have published on nuget in the last ~7 years: https://www.nuget.org/profiles/ConstMe

Only one of them is an SDK for a cloud service, but it’s unofficial SDK. I have no affiliation to pcloud, I only use the free version, I just carefully implemented the documented TLS/TCP binary protocol to access their cloud.

Re:Asynchronous Programming in C# by papichulo2023 on Tuesday April 30, 2024 @10:50AM (#40211574)
Hey great! Meant no offense. I was talking about what I saw when I tried to start a computervison project in c# like 2 years ago. I am sure there quite a few good libraries.
Re:Asynchronous Programming in C# by Const-me on Tuesday April 30, 2024 @11:38AM (#40212246)
> Meant no offense

None taken.

> computervison project in c#

Yeah, for CV applications nuget.org is indeed not particularly great. Very few people are using C# for these things, people typically choose something else like Python and OpenCV.

BTW, same applies to ML libraries, most folks are using Python/Torch/CUDA stack. For that hobby project https://github.com/Const-me/Cgml/ I had to re-implement the entire tech stack in C#/C++/HLSL.

Re:Asynchronous Programming in C# by bragh on Tuesday April 30, 2024 @07:01AM (#40209595)
C# is very good as a language, have developed in it for 5+ years. The problem is the gap between what MSFT promises to management and actually delivers to developers when it comes to the ecosystem of libraries that you want to use with C#. You really really need to fully read the fine print, think of the omissions in documentation and implement a proof-of-concept that almost implements the full solution to find out the hidden gotchas.

For example, even probably their best product VS Code only got reasonable multiple screens support last year: https://github.com/microsoft/vscode/issues/10121#issuecommen...

And then, on the other end of the spectrum, you have Teams and ecosystem surrounding it. The "fun" of Teams bot integrations and the mess with SDKs and SDK documentation for it — never again.

Re:Asynchronous Programming in C# by noisy_boy on Tuesday April 30, 2024 @07:07AM (#40209646)
I wonder why they didn't allow Visual Studio to be available for Linux - I wanted to learn C# to satisfy my curiosity and probably could get away by just using VSCode but every tutorial assumes availability of Visual Studio and I use Linux exclusively at home.
Re:Asynchronous Programming in C# by older on Tuesday April 30, 2024 @07:50AM (#40209969)
VSCode with C# Dev Kit is way to go.
Re:Asynchronous Programming in C# by fl7305 on Tuesday April 30, 2024 @09:14AM (#40210649)
Thanks, I've used VS/C# a lot. What are the limitations using VSCode? For instance, how well does it support debugging multiple threads, or designing XAML WPF/Avalonia UI code?
Re:Asynchronous Programming in C# by osigurdson on Tuesday April 30, 2024 @08:33AM (#40210347)
> M$-bad rhetoric

If M$ is bad, Oracle is Beelzebub.

Re:Asynchronous Programming in C# by sandreas on Tuesday April 30, 2024 @06:30AM (#40209359)
I also like C# as allrounder language, but I don't think it's about M$-bad rhetoric. In my opinion Java tooling and deployment are still far more enterprise than C# has ever been, especially for huge companies.
Re:Asynchronous Programming in C# by nelup20 on Tuesday April 30, 2024 @08:55AM (#40210522)
As someone who's mostly worked with Java & the JVM, I've thought about switching to C# & .NET/CLR for a while. To me C# & some of the tooling/frameworks seem really nice. What made me curious was the Avalonia framework for desktop GUI development which seems to be much better than JavaFX/Swing.

But, I'm still not entirely convinced Microsoft has changed their ways (not that Oracle is any better...), particularly because of the things mentioned here: https://isdotnetopen.com/

Last time I checked, they reversed their decision regarding the proprietary vscode extension, which is great, but the debugger situation hasn't changed & that makes me question whether it's worth switching.