3 ms·
C macros did this in 1973 (48 years ago)
by mgaunard 5y ago
C macros did this in 1973 (48 years ago)
- jayd16 5y agoYeah but now we can do it without having to allow macros.
- mgaunard 5y agoWhy would you disallow a powerful and useful language feature? It's better to be practical than dogmatic.
- spaetzleesser 5y agoBut why? What's wrong with macros? I agree that you can do stupid stuff things with macros but before disabling macros I would get rid of reflection first. With reflection you can do way more stupid things than you can do with macros.
- moron4hire 5y agoNah. Macros allow library developers to do really stupid things that can't be improved on. Reflection lets library users get around the regular stupid things library developers do.
- spaetzleesser 5y ago"Reflection lets library users get around the regular stupid things library developers do." Like marking variables as private?
- moron4hire 5y agoYes, especially if that variable is an IDisposable that the library author also forgot to dispose. Like Microsoft's own System.IO.Ports.SerialPort with its underlying data stream.
- spaetzleesser 5y agoWhy do we have things like "private" and "protected" if people can circumvent them?
- moron4hire 5y agoBecause only a Sith deals in absolutes
- stefan_ 5y agoThat's exactly the problem with C macros, they can do everything.
- wruza 5y agoAnother problem with them is they can’t. Personally I’ve never run in a macro problem in C (and I find these abstract complaints overblown and a little parroting, but ymmw), but their power is far from absolute because it’s just a text concatenation method, not a source code or a type editing method. As an example exercise, you may try to implement: { FILE *f = fopen(…); on_leave_scope(if (f) fclose(f)); } Inability to do that, i.e. to get access to the language structure and fix it according to your convenience, combined with non-hygiene, was what led to C++ compilers and other hardcoded madness.
- Someone 5y agoNot exactly that, but certainly in its spirit: https://stackoverflow.com/questions/69336050/how-to-implement-gos-defer-in-c-so-that-it-allows-declaring-vars https://stackoverflow.com/questions/69336050/how-to-implemen... Also, what some all hardcoded madness is what others call consistency across code bases.