Skip to content
loading...

re: Are C macros awesome? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: C macros are kind of like dynamic typing, aren't they Perhaps, rather it is about templates in C++ I starting wondering, are macros a really aw...
 

I've definitely seen macros used to create unreadable code. But don't they provide a lot of power when used well? For example, I don't think there's any way to do what I did in Go. You can use reflection and interface{} maybe, but I'm pretty it would come out to much longer and less readable. Maybe it wouldn't be needed in a language with generics, but I wonder if there aren't some really useful things other static languages coul gain.

I can see how dynamic languages like Python and Javascript wouldn't gain anything from macros. I guess I don't know very many static languages, just Go and C.

Perhaps, rather it is about templates in C++

Man, I always miss so much in these discussions from not knowing C++ :P But everyone seems to think it's horrible, so I'm averse to learning it.

 

For example, I don't think there's any way to do what I did in Go.

Well, it is hard to judge without specific example :)

But both C and Go are intentionally limited in some ways. So of course for them macros feel useful. However Go designers preferred to go limited but not use macros (of course one can add some macros preprocessor before Go compiler anyway).

Languages which compile to bytecode like Java and C# take middle place between scripting and compiling to native code. So usually there is no sense in macros.

I remember Scala (Java-based language) was going to introduce macros. Many people were alarmed. Probably this idea have died in peace - I don't know.

Man, I always miss so much in these discussions from not knowing C++ :P But everyone seems to think it's horrible, so I'm averse to learning it.

I won't say it's horrible, but it become so overcomplicated over years, so many (like me) prefer Java, Go or something like this.

Nevertheless it makes sense to get acquainted with C++ at "non-professional" level to know better what magics are implemented in it nowadays :)

Concluding it's good to have macros in C. But it is also good we don't have them in many other languages :) just my humble opinion, of course.

code of conduct - report abuse