let bar = foo.stringByReplacingOccurrencesOfString(" ", withString: "", options: .LiteralSearch, range: nil)
Compare to any other language, say Python:
bar = foo.replace(" ", "")
let bar = foo.stringByReplacingOccurrencesOfString(" ", withString: "", options: .LiteralSearch, range: nil)
Compare to any other language, say Python:
bar = foo.replace(" ", "")
I certainly agree it's potentially more readable at first. I'm not yet convinced, without actual data, that anyone, given a month or so experience with a given and common API wouldn't be more productive with shorter names up to a point. I would be good to get that data. Maybe I'd be better off with
a = Math.numberFromAddtionOf2Numbers(c, d)
e = Math.numberFromDivisionOf2Numbers(numerator: b, denominator, c);
vs a = c + b;
e = b / c;
which is best s = str.stringByReplacingOccurrencesOfString(" ", withString: "", options: .LiteralSearch, range: nil)
s = str.replace(" ", "");
s = str.r(" ", ""); s = str.replacing(" ", with: " ")
which seems to go along well with the "sorted" and "appending" mentioned in the new API design guidelines:https://swift.org/documentation/api-design-guidelines/#be-gr...
This is a bit more verbose if you need to chain a lot of replacements... but chances are you shouldn't be doing that in the first place! Instead there should be a version that takes a dictionary, like
str.replacing(["<": "<", "&": "&"])
This is better because most of the time you don't actually want characters produced by earlier replacements to match later ones, and it can be faster for large strings.There's a steeper learning curve sure. But brevity has value.
Is grep a stupid ass name that makes no sense to the layman? Of course! Can even moderately complicated regular expressions actually be read by anyone after the fact? Hell no. And yet it's a fantastic tool.
If there were a dynamic toggle between verbose and brief newbies would start with verbose. I bet most users would eventually switch to brief. Not all, but most.
So it's just as short, from a typing perspective. With a lot of free bonus clarity.
I lived through the bad years when Apple's dev tools were half-baked and made you almost pine for the first dot-com bubble when you were writing Java (but in IDEA IntelliJ, which made it almost worth it).
But today Xcode is state-of-the-art, at least in terms of autocomplete, and it makes a big difference.
Regexes have facilities for case insensitive replace, as in most languages.
Maybe I've been programming in Python too long, but str.replace is intuitive to me (unlike, say PHP's str_replace). I'm guessing you don't program in Python much, judging by your question of string copying.
Can you really defend that as an identifier in any sane API? It's utterly abhorrent to my eyes, in the same way typical Microsoft bastardized Hungarian looks. Actually - it's worse.
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mo...