Hacker News new | ask | show | jobs
by Ygg2 598 days ago
Hack or not, it's been working relatively well for the past decade.

But even, if you account for that, the records in Java do most of what Lombok used to do - make class externally immutable, add default `toString`, `equals` and `hashCode` implementations, allow read-only access to fields.

> what source generators can do in C#

Having had the displeasure of developing source generators in C# (in Rider), what they do is make code impossible to debug while working on it. On top of relying on an ancient version of netstandard.

I cannot emphasize enough how eldritch working on them is. While developing, whatever change you write isn't reflected when you inspect codegen code, and caching can keep old code beyond even post re-compilation unless you restart the build server, or something.

So whenever you try to debug your codegen libs, you toss a coin:

- heads it shows correct code

- tails it's showing previously iteration of code gen code, but the new code is in, so the debugger will at some point get confused

- medusae it's showing previous iteration of code gen code, but new code hasn't been propagated, and you need to do some arcane rituals to make it work.

Hell, even as a user of codegen libs, updating codegen libs caused miscompilation because it was still caching the previous codegen version.

1 comments

> relying on an ancient version of netstandard

They require 2.0, which is the only version that is actually useful, since it supports .NET Framework 4.x.v

You do realize netstandard 2.0 is 7 years old right? That it misses a ton of functionality compared to current dotnet. Stuff like MaybeNull annotation .
It misses a ton of functionality compared to the current .NET (Core), but it does not miss much compared to .NET Framework 4.8. The reason why source generators require it is because they may be run by Visual Studio, which is built on top of the classic .NET Framework. .NET Standard 2.0 is a good trade-off IMO if you need to support both the classic Framework and the modern .NET.
It missed ton of functionality compared to C# in 2022 (when I last used it). It's about as old as Java 8.
If setting <LangVersion> to 12 and maybe doing `dotnet add package PolySharp` was too challenging then the source generators API is probably not for you. It's not a language issue :)