HN2new | past | comments | ask | show | jobs | submitlogin

  NSString *foo = [@"foo" stringByAppendingString:@"bar"];
It's not that bad.


I must be missing something here.

  "foo" + "bar"


While this syntax is indeed popular in several languages it's deeply weird, it's like how English uses apostrophe S to do two very different things at the end of words.

The Add operation has a whole bunch of properties and this not only isn't most of them, it's arguably not any of them, the main argument for + as a string concatenate operator is "Well, people seem to like it". Which, I guess I/O streams doesn't even have that going for it, but it's a pretty terrible rationale.

Look, just grow string interpolate and write f"{foo}{bar}" or whatever as much as you like don't abuse unrelated operators.


Whatever you feel about operator overloading, it's way better than the Objective-C version, even the version floated by the defenders. String interpolation is even better, sure, but the + alternative isn't that bad. As you noted, natural language does the same kind of overloading and we seem to cope with it just fine.


It's more like compile-time concatening of literals like in C when doing

  const char *s = "foo" "bar";


I use:

  id foo = [@"foo" cat:@"bar"];
I have a category method added to NSString:

  - (id)cat:(id)arg { return [self stringByAppendingString:arg]; }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: