Live data from Hacker News

Swift is like Kotlin

nilhcem.com

1–10 of 364 posts

Re: Swift is like Kotlin

#3
post #2

0..<count is a lovely little piece of language design

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...

Re: Swift is like Kotlin

#4
post #3
post #2

0..<count is a lovely little piece of language design

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 confused me as well. "0.. is less than count"?

Re: Swift is like Kotlin

#5
post #3
post #2

0..<count is a lovely little piece of language design

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...

When I see "0..n" I wonder whether the range is inclusive or exclusive of n.

When I see "0..<n" I know the range is exclusive of n.

Re: Swift is like Kotlin

#7
Could 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.

Re: Swift is like Kotlin

#8
post #3
post #2

0..<count is a lovely little piece of language design

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.

Re: Swift is like Kotlin

#9
post #3

Earlier 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 confused me as well. "0.. is less than count"?

".." has a meaning – why are you leaving it out of the translation?

Re: Swift is like Kotlin

#10
post #5
post #3

Earlier 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...

When I see "0..n" I wonder whether the range is inclusive or exclusive of n. When I see "0..<n" I know the range is exclusive of n.

Yes, but the corresponding design decision would be "0..=n". Swift's "0...n" is a bit less obvious.

Also, exclusivity is almost always what you want, so "0..n" should just default to exclusivity and "0...n" could be inclusive.

Post reply on HN