#define or const string*-Collection of common programming errors
I know this question has been asked several times, but mine is slightly different. Before closing this as duplicate, please read it fully. There are many posts on stack overflow that says, “Personally, I hate MACROS, Don’t use that shit”. I’ve read all those and my case is different. I’m trying to define URLs used in a software (iOS app) using #define macros.
I agree that using const strings is a better practice than #define macros. But in an increasingly REST based API world that accepts query parameters as a part of URL, how can you still use const strings to represent a URL that changes?
Instead of http://api.myblog.com/posts?entryid=%@ a API Server that following REST principles would have http://api.blog.com/posts/entries/[entryid]
In the former type, URL is http://api.myblog.com/posts for all entries and they don’t change. A const string was possible.
In the latter type, URL changes with every entry and I use a Macro that expands to a full URL like this.
#define GET_ENTRY_URL(__MY_ENTRY_ID__) [NSString stringWithFormat:@"http://api.myblog.com/posts/entries/%@", __MY_ENTRY_ID__];
Are there any design flaws in my method? Would like to know your inputs.
Thanks.