News for hackers. Stuff that matters.
Re:What is .NET, and why should you choose it? by prmph on Tuesday February 14, 2023 @01:28PM (#34793744)
I tried C# recently again, after having migrated to use JS/TS and Node.Js as my main stack for years.

What put me off was how cumbersome it seemed to be. Maybe I’ve just been spoiled by JS/TS, but where are the following features (which I believe to be quite basic)? - Union types - Object literals - Functions as first class citizens

I get that C# is supposed to be a purely OO language, but in this day, the most useful languages are multi-paradigm.

People like to dish on JS/TS but IMHO one reason why they became so popular is overlooked. There’s just something so direct and unceremonious about programming in JS, and with TS you get strong expressiveness as well.

Until and unless the .NET languages have that it will be hard to pull me away.

Re:What is .NET, and why should you choose it? by IneffablePigeon on Tuesday February 14, 2023 @01:45PM (#34794011)
Union types are a gap, although records and switch expressions will get you much closer than was previously possible.

Object literals are a thing, they’re called anonymous types. You just new them up. And functions can be passed around as first class objects, with some minor type boilerplate in a few places.

There are a few places where you have to adjust to different naming conventions and types are obviously stricter but my experience is that for the most part modern c# has all the things I like about TS/JS.

Re:What is .NET, and why should you choose it? by runevault on Tuesday February 14, 2023 @05:41PM (#34797268)
It is worth mentioning the c# team is taking a serious look at Union types finally. Considering the runtime already has a version in f# I'm curious how it goes on the c# side of the house (I know semantics are different between the two languages so can't necessarily be 1:1)
Re:What is .NET, and why should you choose it? by delta_p_delta_x on Tuesday February 14, 2023 @01:59PM (#34794218)
> Union types

Yes, these are missing in C#.

> Object literals

You could use records[1], or anonymous types[2].

> Functions as first class citizens

There's delegates[3] and lambda expressions[4]. Is there anything that's missing here that you need?

You can use lambda expressions almost exactly like you might in JS/TS, even omitting the type:

  var squared = x => x * x; 
And if you want even more functional, you could always use F#.

[1]: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

[2]: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...

[3]: https://learn.microsoft.com/en-us/dotnet/api/system?view=net...

[4]: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

Re:What is .NET, and why should you choose it? by prmph on Tuesday February 14, 2023 @02:53PM (#34794989)
> You could use records[1], or anonymous types[2].

Not quite with directness of JS.

> There's delegates[3] and lambda expressions[4].

Again you can get something equivalent, but not without some ceremony. It’s not as frictionless as with JS.

Re:What is .NET, and why should you choose it? by delta_p_delta_x on Tuesday February 14, 2023 @09:53PM (#34799426)
> It’s not as frictionless as with JS.

I'm not sure how much less friction you want than directly declaring lambdas, or LINQ, or any of the newer functional constructs.

Like I said, if you want more functional, there's F#, which is a dialect of ML.

Re:What is .NET, and why should you choose it? by kaba0 on Wednesday February 15, 2023 @08:09AM (#34803307)
I think your problem is just structural vs nominal typing, in that you can’t get away from the former.