3 ms·
Looking at the screencast I was surprised to see this macro syntax being allowed (passing an asterisk here means all properties get synced): NSRailsSync(*)
by stephth 14y ago
Looking at the screencast I was surprised to see this macro syntax being allowed (passing an asterisk here means all properties get synced):
NSRailsSync(*)
Here's what's happening. Ingenious stuff.
//adding a # before va_args will simply make its contents a cstring
#define _MAKE_STR(...) NSRStringFromCString(#__VA_ARGS__)
//define NSRailsSync to create a method called NSRailsSync, which returns the entire param list
#define NSRailsSync(...) \
+ (NSString*) NSRailsSync { return _MAKE_STR(__VA_ARGS__); }
- falling 14y agoClever. “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” Seeing the recent evolutions, I thought Rails people learned that magic in code leads to debugging unhappiness.
- stephth 14y agoI think that quote is about complex code. We tend to look at macros as dangerous, but this is a pretty clean usage of macros, it's basically a function that turns the arguments into a string. Simple and easy to debug. Don't you think? Edit: Discussion about that quote: http://stackoverflow.com/questions/1103299/help-me-understand-this-brian-kernighan-quote http://stackoverflow.com/questions/1103299/help-me-understan...
- falling 14y agoIt’s a simple macro that makes you write code that looks like a syntax error, and I don’t like that (http://www.codinghorror.com/blog/2006/05/code-smells.html http://www.codinghorror.com/blog/2006/05/code-smells.html). Especially since without the macro you’d just need to write two characters more or, even better, a clearly named constant, like kNSRAllProperties.