Live data from Hacker News

Comptime – C# meta-programming with compile-time code generation and evaluation

github.com

21–30 of 71 posts

Re: Comptime – C# meta-programming with compile-time code generation and evaluation

#22
post #7
post #5

Earlier quoted context omitted.

It's a lot less ergonomic but there are source generators in C# : https://devblogs.microsoft.com/dotnet/introducing-c-source-g... That said, for more complex results, you'd typically load a serialization on start. I can see the value in this tool, but there must be a fairly limited niche which is too expensive to just have as static and run on start-up and cache, but not so large you'd prefer to just serialize, store…

Not terribly niche. All config that isn’t environment-specific and is used in inner loops or at startup. It’s even got a test for serialised values so can be used to speed your case up: https://github.com/sebastienros/comptime/blob/main/test/Comp... But you need to be sure you won’t want to change without compiling.

Well it also needs to be something that you need to generate/calculate, otherwise you would just write by hand the code that comptime outputs.

Re: Comptime – C# meta-programming with compile-time code generation and evaluation

#24
I started using C# recently for a hobby project writing a game engine on top of Monogame, and I have been very surprised at how nice of a language C# is to use.

It has a clean syntax, decent package management, and basically every language feature I regularly reach for except algebraic data types, which are probably coming eventually.

I think the association of .NET to Microsoft tarnished my expectations.

Re: Comptime – C# meta-programming with compile-time code generation and evaluation

#27
post #14

C# meta programming game is strong. Source generators are :chefs_kiss:

I love (and heavily use) source generators, but the development experience is godawful. Working with the raw Roslyn types is painful at best and this is compounded by them having to be written against .NET Standard, severely limiting the use of newer .NET functionality. Eventually I want to write a good baseline library to use for my source generators -- simplifying finding definitions with attributes, mapping types…

I feel the exact same way. They can be insanely powerful, but the syntax is insanely off-putting.

And the documentation is still pretty sparse.

> Eventually I want to write a good baseline library to use for my source generators -- simplifying finding definitions with attributes, mapping types to System.Type, adding some basic pattern matching for structures -- but haven't found a way to do it that's general enough while being very useful.

I'd use it in a heartbeat. The new ForAttributeWithMetadataName function has been a big help, but everything else feels like a totally different language to me.

Re: Comptime – C# meta-programming with compile-time code generation and evaluation

#28
post #5
post #2

This seems like the kind of feature that should be built into MSBuild.

It's a lot less ergonomic but there are source generators in C# : https://devblogs.microsoft.com/dotnet/introducing-c-source-g... That said, for more complex results, you'd typically load a serialization on start. I can see the value in this tool, but there must be a fairly limited niche which is too expensive to just have as static and run on start-up and cache, but not so large you'd prefer to just serialize, store…

I use source generators pretty extensively but don't really understand how this is different (or what it's solving that source generators can't).

I'm pretty new in the source generation area and only do enterprise dev, so I'm sure I'm missing something or just don't have the use cases.

Post reply on HN