by Xeoncross · 4y ago · 0 comments
NSString *myString = @"Hello";
NSString *second = [myString stringByAppendingString:@" World"];
[1]: https://stackoverflow.com/questions/510269/shortcuts-in-obje...Is both elegant and very powerful as it is has the perfect balance between a static and a dynamic language.
Swift on the other had is a language where wonks decided to throw every silly feature they thought off to the point that is becoming more complex than even Scala.
I wished Swift was just a modernized Objective-C with a normal non bracket syntax and some extra facilities that it was missing.
It is such a wasted opportunity
What features in particular do you think represent unjustified complexity?
Swift is not my favorite, but I wouldn’t consider it to be a “kitchen-sink” language, and it’s certainly less complicated than Scala.
https://blog.metaobject.com/2019/12/the-4-stages-of-objectiv...
NSString* result = [NSString stringWithFormat:@"%@ %@", @"Hello", @"World"];Compare with
"Hello " + "world"
or if you hate operator overloading "{} {}".format("hello", "world")
f"{foo} {bar}"It's hard to control once you want anything more interesting than + and it's not localizable. Complaining that a function call's name is too long doesn't matter at all.
ObjC itself is not responsible, it's NeXT and Apple's fault for perpetuating that abominable naming convention for much too long.
As for localisation, only a tiny fraction of strings in a software program are user visible. I don't think we should be designing language syntax around that edge case.
Also, I've never heard of any serious iOS/macOS dev complaining about this.
ObjC is very simple (often confused with archaic), but also wildly complex. Once you wrap your head around the ObjC way of doing things, everything makes sense, is very consistent, and you could develop very effectively.
NSString *foo = [@"foo" stringByAppendingString:@"bar"];
It's not that bad. "foo" + "bar"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.
const char *s = "foo" "bar"; id foo = [@"foo" cat:@"bar"];
I have a category method added to NSString: - (id)cat:(id)arg { return [self stringByAppendingString:arg]; }And, don’t forget to release your alloc’d objects (or use an auto release memory pool). There was no automatic memory management then!