I'm coming from a place without macros (Java/Python/C#/Scala) so perhaps my perspective is distorted but...
Why are macros used in Cocoa? Two that spring to mind are NSLocalizedString
and NSAssert
(and STAssert
). Would it be so hard / unsuitable to make them functions (which could be inlined)? I suppose I find them a little bizarre as an unnecessary throw-back to C (and yes, I am familiar with the pedigree of Obj-C).
Is it just something that was done back in the day or is there a specific reason?
In general it is preferable to avoid macros, but for functionality like that provided by NSAssert()
, you can't.
If you look at the definition, you'll see that it uses __LINE__
, __FILE__
, _cmd
and self
from the context it is used in. If it wasn't a macro, it wouldn't have access to that information.
For NSLocalizedString
however, i see no obvious reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With