3 ms·
A few points that may make your life easier: - In later versions of .NET, struct enregistrering is very powerful, it promotes struct's contents to CPU register
by neonsunset 5y ago
A few points that may make your life easier:
- In later versions of .NET, struct enregistrering is very powerful, it promotes struct's contents to CPU registers. You can write high-performance and allocation-free implementations for value objects, monads and wrappers of all kinds without much issues nowadays.
- Guarded devirtualization helps a lot if you heavily rely on interfaces because it allows further inlining and reduces method calls cost.
- Unfortunately LINQ is no match to Rust iterators which get easily vectorized. However, there are low-allocations and simd-ified implementations which might help with your goals. See https://github.com/asc-community/HonkPerf.NET https://github.com/asc-community/HonkPerf.NET
After all, DDD requires special care when describing its domain definitions in code but you really don't have to go OOP route nowadays for the core logic of your applications. Also records and record structs make it very easy to define contracts and state on the go without having to go with tons of boilerplate I keep seeing in a very much DDD-oriented project my team is responsible for.
- zamalek 5y ago> without having to go with tons of boilerplate I keep seeing in a very much DDD-oriented project my team is responsible for. And that's the unavoidable reality. My team are extremely open-minded, but I have no idea how to bring up this subject with them.
- DeathArrow 5y agoI fancy doing the domain modeling in F# since it lends well to that and the business logic in C#. https://fsharpforfunandprofit.com/ddd/ https://fsharpforfunandprofit.com/ddd/
- kevingadd 5y agoDo you have any links to stuff about struct enregistering and guarded devirtualization? I'm familiar with the concepts and have gotten .NET to do the latter intermittently but if there's documentation on how to make them happen reliably that'd be great to see.
- DeathArrow 5y agoStructs will be stored in the registers of the CPU if the compiler thinks there is enough space. As for devirtualization: https://www.infoq.com/news/2017/12/Devirtualization/ https://www.infoq.com/news/2017/12/Devirtualization/ https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-6/ https://devblogs.microsoft.com/dotnet/performance-improvemen... - you have to go to the section where he talks about devirtualization.
- DeathArrow 5y agoIt's not like MS wants to make it easy to use a functional or procedural paradigm. I tried to bind an IConfiguration section to a record but I couldn't since in condensed form a record lacks a default constructor. So I had to write a class like record and add Init to each property to make them immutable.
- zigzag312 5y agoI think you can add default constructor manually. Something like this: public record Foo(int X, int Y) { public Foo():this(0,0) { } } Or make all parameters optional public record Foo(int X = 0, int Y = 0);
- DeathArrow 5y agoTried with public Record Foo(int x = default, int y = default); and it still complained about missing a constructor. I didn't try to add an constructor like you suggested, it's still shorter than defining all members.