If you want to compare them, going over the differences would be a lot more illuminating.
Swift is like Kotlin
21–30 of 364 posts
Re: Swift is like Kotlin
#220..<count is a lovely little piece of language design
Re: Swift is like Kotlin
#23Could someone tell me the meaning of _ in this Swift code: func greet(_ name: String,_ day: String) -> String { return "Hello \(name), today is \(day)." } greet("Bob", "Tuesday") In me prior experience usually _ denoted an unused parameter/variable. Also: I find the string interpolation syntax ugly... The syntax choices in Swift are curious, but not the most aesthetical/practical in my opinion.
For example, you can have a function like so:
func greet(with greeting: String, to personName: String) {
print("\(greeting), \(personName)!")
}
In the above code, "with" and "to" are external names, and are only available when calling the function but are not available inside the function itself. So you would call this function like so: greet(with: "Hello", to: "Bob")
Now if you want to exclude the external name to call the functions, you use the "_" syntax. So you're right that it denotes an unused parameter. In this case, it's an unused external parameter name.Re: Swift is like Kotlin
#24But true convergence remains far away...
Re: Swift is like Kotlin
#25Earlier quoted context omitted.
What do you like about it? I was actually thinking the opposite... EDIT: Genuinely curious, this is not meant to troll or start a war. I like the more explicit feeling `count-1`. I'd use either...
it's always confusing, in languages with ranges, whether the range includes the second boundary element or not. it's purely a matter of convention, after all. ruby has a..b and a...b, but even after years of using the language i have to look up which is which. a.. perfect notation - once you know the language handles both cases, a.. as for the "count - 1", it's not too bad because i find "inclusive" more intuitive th…
Re: Swift is like Kotlin
#26Could someone tell me the meaning of _ in this Swift code: func greet(_ name: String,_ day: String) -> String { return "Hello \(name), today is \(day)." } greet("Bob", "Tuesday") In me prior experience usually _ denoted an unused parameter/variable. Also: I find the string interpolation syntax ugly... The syntax choices in Swift are curious, but not the most aesthetical/practical in my opinion.
func sayHi(to personName: String) {
print("Hi \(personName)")
}
sayHi(to: "Bob") // Hi Bob
Similarly, using just one label in the function declaration means that they have the same name externally as well as internally.In this case the example is saying that they don't want any external labels.
edit: damnit, beaten
Re: Swift is like Kotlin
#27Earlier quoted context omitted.
What do you like about it? I was actually thinking the opposite... EDIT: Genuinely curious, this is not meant to troll or start a war. I like the more explicit feeling `count-1`. I'd use either...
How is the inclusive range operator implemented in Kotlin? Something like `for (i in 0..count)` needs to iterate count + 1 times, which may overflow the size of count's type - annoying to implement.
count.forEach {
// do things
}Re: Swift is like Kotlin
#280..<count is a lovely little piece of language design
Range.closed(1,5) == [1,5]
Range.open(1,5) == (1,5)
Range.openClosed(1,5) == (1,5]
Range.closedOpen(1,5) == [1,5)
Range.greaterThan(1) == (1,infinity)
Range.atLeast(1) == [1,infinity)
That class always strikes me as having high power-to-weight. It has methods like encloses(anotherRange), contains(aValue), and others.
https://google.github.io/guava/releases/19.0/api/docs/com/go...
Re: Swift is like Kotlin
#29Minor nit: the sort example needlessly uses two lines for the Swift version.
Re: Swift is like Kotlin
#300..<count is a lovely little piece of language design
I can't tell whether this is sarcasm or not. What does the '<' mean in this case? I'm assuming an exclusive upper bound.