23 ms·
I know C# people like to think up three new forms of syntax before breakfast, but it feels like these magic comments could have been attributes?
by thom 1y ago
I know C# people like to think up three new forms of syntax before breakfast, but it feels like these magic comments could have been attributes?
- jiggawatts 1y agoThe motivation was almost certainly compatibility UNIX shebang lines for shell scripts: #!/usr/bin/dotnet run Console.WriteLine("Hello from a C# script!"); Which just looks like a crime against nature and right order of things. It's really hard to explain to anyone who wasn't born in a monoculture, but I come from an eastern european country where in my childhood there may have been maybe a few hundred truly foreign people living there at any one time, mostly diplomats and their families. Decades later I visited and saw a chinese immigrant speaking my native tongue. You can't imagine how... disconcerting that is. Not bad, I'm not against it, it's just... weird. This feels exactly like that.
- Kuinox 1y agoThis come from C++ preprocessor directive, and have been here since the first version of C#.
- noworriesnate 1y agoBeing able to use a shebang as a preprocessing directive is really creative. I’m really glad c# isn’t design-by-committee language.
- GoblinSlayer 1y agoWell, shebang is a comment.
- homebrewer 1y agoThose are not comments: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... They've been supported for decades at this point, they're not new. Your suggestion would require more changes to the language than what's actually implemented, afaiu.
- thom 1y agoApologies, I left C# years ago when there were only 5,000 things to keep in your head at any one time.
- Kuinox 1y agoC# always supported preprocessor directive.
- CharlieDigital 1y agoYup; from v1
- thom 1y agoYes, but I would have thought attributes were the canonical "think you might want to reflect over" rather than this imperative solution. But you're all happy with it and it's not my circus, so enjoy.
- Kuinox 1y agoThis cannot be something you reflect over, because they allow to encode build arguments. They need to be parsed before it's compiled, which is exactly what preprocessors directive allows.