4 ms·
I guess this doesn’t quite qualify as Greenspun’s tenth rule, but what a gross thing to have to do to make up for a language’s lack of macros.
by thom 5y ago
I guess this doesn’t quite qualify as Greenspun’s tenth rule, but what a gross thing to have to do to make up for a language’s lack of macros.
- Ciantic 5y agoI don't know do you follow C# these days, but they have source generators now. [1] Only rule is that it can't modify existing code, but add more. This way they won't break the intellisense etc. But you probably want hygienic macros? https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/so...
- jayd16 5y agoWhats so gross about an attribute to get a string populated?
- thom 5y agoIt’s like buying a 3D printer and finding out it can only print out the name of the files you give it. Sure it’s doing something, and if that’s the thing you want then great, but you can’t help but look enviously at your friend’s 3D printer that does whatever they ask it to.
- spaetzleesser 5y agoI really don't understand the dislike of macros. They would be super handy for things like WPF's INotifyPropertyChanged or for a lot of logging and parameter checking. Instead you have to do all kinds of weird tricks with refelection that are way more complex. They are adding all this stuff in small pieces instead of having a comprehensible solution.
- slaymaker1907 5y agoI think the C macro system (and other similar macro systems) really ruined macros for a lot of people. A lot of the complaints about macros go away if you track scope carefully for generated code either by enforcing hygiene or by a more complex namespace system such as with syntax-case in Racket/Scheme.
- gefhfff 5y agoYep, this. Once, I wanted to try Rust (while been heavily invested in C++ and a bit in C), and after just a bit digging into it, I discovered how present macros are in Rust (e.g. printing). This really turned me off such that I aborted learning Rust. (Gladly I took a deeper look later :) )
- Analemma_ 5y agoIt is very unfortunate that C taught multiple generations of programmers that macros are a deadly trap waiting to blow up at runtime if you don’t bend yourself to insane coding idiosyncrasies. Macros are awesome and problems with them can be caught at compile-time, same as real code! But only if you have a macro system that isn’t worse than the problem it’s trying to solve.
- fivea 5y ago> It is very unfortunate that C taught multiple generations of programmers that macros are a deadly trap waiting to blow up at runtime if you don’t bend yourself to insane coding idiosyncrasies. I don't think that's a fair or reasonable take. If anything, generations of programmers learned from experience that instruction systems that are orthogonal to the language and blindly manipulate text strings while ignoring semantics and context and even basic types that is readily available, such as the C preprocessor or M4, leads to a subpar developer experience, code that is far harder to reason about, and causes bugs that are hard to troubleshoot. Given the choice, implementing features into the language that can be evaluated by static checks is far cleaner and easier to understand and maintain.