Python has a phrase used to describe code written using Python idioms (for-in loops vs for loops, etc.). We say that such a code is Pythonic.
Is there a similar term for the new Swift language for Apple? Swiftonic? Swiftic?
Are we just stuck with idiomatic fast code (description, not term)?
Just to give you an idea of ββwhat I'm talking about, here is an example. Both blocks of code find the index of the letter in the string:
Non-swiftic (?) Code [bad] :
func findIndexOf(char : String) -> Int? {
for var i = 0; i < countElements(self); ++i {
var ch = String(Array(self)[i])
if String(ch) == char {
return i
}
}
return nil
}
Swiftic (?) Code [good] :
func findIndexOf(char : String) -> Int? {
for (index, ch) in enumerate(self) {
if String(ch) == char {
return index
}
}
return nil
}
source
share