News for hackers. Stuff that matters.
Re:Minimal APIs at a glance in .NET 6 by ddek on Monday September 13, 2021 @06:06AM (#28509550)
So I guess we've had 'JavaScript but like C#', in the form of TypeScript; so I suppose now we get 'C# like JavaScript'? I must admit, I find this amusing.

I suppose this raises two questions: "Why use C# like this in place of express or koa on node, which idiomatically similar?", and "Why use C# like this instead of C# like that (the way all other AspNetCore apps do it)?"

Re:Minimal APIs at a glance in .NET 6 by nodejs_rulez_1 on Monday September 13, 2021 @06:48AM (#28509842)
They neither broke the type system to make it weaker nor did they stick a browser engine where it doesn't belong.
Re:Minimal APIs at a glance in .NET 6 by jeswin on Monday September 13, 2021 @07:00AM (#28509925)
1. The web server component could be fronting a middle-tier written in C#. There are numerous advantages to doing this in .Net over Node.

2. Performance.

3. Native AOT is coming in 6.0. Meaning, you get a native platform specific app which can run without the framework - like golang. But with GC, so not like C/C++/Rust.

Re:Minimal APIs at a glance in .NET 6 by stevefan1999 on Tuesday September 14, 2021 @05:31AM (#28522243)
I don't get it why people always hated (tracing) GC. Unless you are working on a hard real time systems such as DSP or audio synthesizer, having some kind of GC is always the boon.

Not only you can run code faster in some case (by suspending GC in some critical code and just do plain allocate and resume GC at a later time, and this is also how you make it more real-time compatible), it can also help curb fundamental security issues such as dangling pointers and use-after-free.

GC is also not the blame to the bloated size of your app, Nim [1], for example, is a language with GC/runtime while being lightweight. Another honorable mention would be Haxe [2] for gamedev, where it can generate much more compelling C++ code that the binary size is just slightly bigger to what you normally do with C++ while having much less lines needed to code. And it has a tracing GC.

So I do think GC-enabled language can be like C/C++/Rust. Even if there is a binary and performance difference, it won't be huge. But the way it makes your program safer by a huge margin and your programmer less mentally pain, makes having GC a huge difference.

By the way, even smart pointers/move semantics and ownership are one kind of GC (by leveraging linear/affine logic to ensure resources will not drop out of its controllable/life phase commonly called lifetime), so most of the time what I refer to GC is more specifically tracing GC where mark-and-sweep algorithms that usually need to stop-the-world is indeed a fundamental problem in GC design especially for multi-core platform which is going more and more popular nowadays.

[1]: https://nim-lang.org [2]: https://haxe.org

Re:Minimal APIs at a glance in .NET 6 by cb321 on Wednesday September 15, 2021 @03:41PM (#28543456)
There is definitely a terminology problem. "Automatic memory management" is a more precise term than "garbage collection". It refers to the more user visible trait, and pairs better with the antonym of "manual memory management" which is much more commonly seen. I would encourage people to use "AMM" as a term even if in their coding they do not use it. :-) "AMM" also begs the right questions such as "automatic -- in what sense, exactly?" It also tracks with the primordial C "auto" for stack variables (the automatically managed part of C - yes I am aware modern C++ repurposed it). It might even make some discussions have less talking past each other. This kind of oceanliner ship is hard to turn, though.

There are a few high profile prog.langs and environments like Java/Go/old Lisp stop-the-world/etc. style where (some) people struggle with "GC". These struggles often give AMM itself a bad reputation - while C stack variables (often coupled with what people call "value types" today) are often the way to be very, very fast (yes, because of mostly CPU-private stacks..even so).

Nim is very fast and has many choices in AMM from none to Boehm-Wiser to its own tracing variant to a new extremely low overhead ARC and ORC that have more Rust-ike aspects (but copying in some cases to be safe which is just about 10x easier to use in deviousmeters). With a TinyC/tcc backend Nim yields near Interpreter/REPL-like edit/compile/test cycles. It's really a joy to write code in most of the time. People should look into Nim more.

Re:Minimal APIs at a glance in .NET 6 by GordonS on Monday September 13, 2021 @11:03AM (#28512366)
I've been using C# since it was released, and I'm a huge fan.

But I can almost guarantee that native AOT doesn't appear with dotnet 6 - they've been promising it for several years, and it's become Microsoft's Duke Nukem Forever,

Re:Minimal APIs at a glance in .NET 6 by merb on Monday September 13, 2021 @02:06PM (#28514680)
yeah and the sad thing without NativeAot there won't be the WebAssembly things which we would like. the way it works now is way too lazy for anything real world. (compiling the runtime to wasm and loading dll files...)
Re:Minimal APIs at a glance in .NET 6 by ripley12 on Monday September 13, 2021 @11:14AM (#28512506)
NativeAOT is supported in more places in .NET 6, there has been a tremendous amount of work to ensure that libraries are trimmer and linker friendly. But I believe ASP.NET’s targeting .NET 7 for that.
Re:Minimal APIs at a glance in .NET 6 by kevingadd on Monday September 13, 2021 @06:29AM (#28509700)
I think the fact that this maintains type safety, IDE integration and other useful traits of modern C# like zero-allocation primitives gives it a leg up over TypeScript/JS in some cases.
Re:Minimal APIs at a glance in .NET 6 by davidfowl on Monday September 13, 2021 @09:19AM (#28511113)
This
Re:Minimal APIs at a glance in .NET 6 by oaiey on Monday September 13, 2021 @02:00PM (#28514575)
Funny, that David ends this discussion.

Thanks!

PS: oh no, now I am ending it :)

Re:Minimal APIs at a glance in .NET 6 by oaiey on Monday September 13, 2021 @07:50AM (#28510296)
It is about attracting new developers to .NET. Boilerplate does not help. So it boils down what the cool kids consider simple: Express + node.js => ASP.NET Core Minimal API.

Evolve or die. When you see the releases in the last 5 years, C#/.NET tries to evolve and stay relevant.

Do we need to like that: No. Is it necessary for .NET: Yes.

Re:Minimal APIs at a glance in .NET 6 by andix on Monday September 13, 2021 @06:49AM (#28509847)
You still get C#/.NET, with it's superior performance and type safety, but just without all the OOP bloat.
Re:Minimal APIs at a glance in .NET 6 by LAC-Tech on Monday September 13, 2021 @08:42AM (#28510756)
Wait, you think this is not OOP?

    var app = WebApplication.Create(args);
 
    app.MapGet("/", () => "Hello World");
 
    app.Run();
You're creating an object and calling methods on it..
Re:Minimal APIs at a glance in .NET 6 by andix on Monday September 13, 2021 @08:49AM (#28510833)
This is more functional. C# is an multi paradigm language.

There is not a big difference between an FP module and an OOP static or single instance class.

Re:Minimal APIs at a glance in .NET 6 by LAC-Tech on Monday September 13, 2021 @08:51AM (#28510867)
I think the word OOP has lost all meaning and just means "crusty old code I hate".
Re:Minimal APIs at a glance in .NET 6 by andix on Monday September 13, 2021 @09:34AM (#28511259)
In the OOP way you create controller classes. In the FP way you pass lambdas/functions.

So yes, it’s not 100% functional. But probably 80%?

Re:Minimal APIs at a glance in .NET 6 by LAC-Tech on Monday September 13, 2021 @05:10PM (#28516917)
You're creating an instance of an app class, calling methods on it, and passing objects in that method (string and lambda are objects).

I just feel like the term OOP can't win here. If it's concise people will just claim it's FP.

Re:Minimal APIs at a glance in .NET 6 by andix on Tuesday September 14, 2021 @05:33AM (#28522262)
Off course there is still OOP involved. Also most FP languages support objects to some extent. Also records and their modules have some similarities to OOP. And even FP can be never completely pure, there always has to be state.

But this approach is just more functional than the one before.

Re:Minimal APIs at a glance in .NET 6 by arethuza on Monday September 13, 2021 @10:36AM (#28512047)
Also MapGet seems to be changing the state of the WebApplication object... which doesn't seem to be very functional?
Re:Minimal APIs at a glance in .NET 6 by flohofwoe on Monday September 13, 2021 @06:26AM (#28509676)
The same can be done in pretty much any other language, it's just a HTTP server wrapper which maps specific URL paths to callback functions which return a HTTP response.

E.g. in Go: https://gobyexample.com/http-servers, or in Python via Flask: https://flask.palletsprojects.com/en/2.0.x/quickstart/#routi...

Re:Minimal APIs at a glance in .NET 6 by stevefan1999 on Monday September 13, 2021 @06:25AM (#28509669)
because you dont want to work with a broken module system?

im talking about you, ESM, for all the headaches you induced me on TypeORM and NestJS. I really miss the proper Java packages and dotnet namespaces design