Earlier quoted context omitted.
1..5 syntax has been deprecated for about 2 years, now you have 1...5 which is inclusive and 1..<5 which excludes the last element.
does it work with expressions? foo()...bar()? I can count on no fingers the amount of times I've hardcoded the length of a loop in production code.
Swift is like Kotlin
251–260 of 364 posts
Re: Swift is like Kotlin
#252Does anyone else think the Kotlin syntax for array literals is super ugly: val shoppingList = arrayOf("catfish", "water", "tulips", "blue paint") What is wrong with square bracket syntax? (rant over). EDIT: I suppose it's consistent with other syntax e.g. listOf() etc.
I agree, it leaves a bad taste in the mouth. It's even worse than old PHP's array(). I'll pick short forms all the time: lists with (), dictionaries/hashes with {}.
Re: Swift is like Kotlin
#253Earlier quoted context omitted.
Would you work in a programming language called Hitler? Any multinational company needs to do their research before deciding on a name.
Equating a programming language named after a Russian island to Hitler is a real stretch, unless you think that everything Russian is like Hitler. It's just an island and a language named after it.
Re: Swift is like Kotlin
#254Earlier quoted context omitted.
Whereas it's completely reasonable to object against naming something after an insect?
Yes, it is pretty normal to have phobia of e.g. insects. If you have phobia of Russia on the other hand, you might want to get checked.
Re: Swift is like Kotlin
#255Does anyone else think the Kotlin syntax for array literals is super ugly: val shoppingList = arrayOf("catfish", "water", "tulips", "blue paint") What is wrong with square bracket syntax? (rant over). EDIT: I suppose it's consistent with other syntax e.g. listOf() etc.
Re: Swift is like Kotlin
#256Earlier quoted context omitted.
> # using \ is looking for troubles Are you referring to escaping and other special sequences (e.g. unicode codes)? Though it is odd-looking I actually find it rather smart that they decided to reuse an existing mechanism for that: aside from delimiters the only magical character in a string is \ rather than have e.g. both \ and $. > # the useless () My beef is more with 1..5 being inclusive and there apparently bein…
1..5 syntax has been deprecated for about 2 years, now you have 1...5 which is inclusive and 1..<5 which excludes the last element.
Re: Swift is like Kotlin
#257Earlier quoted context omitted.
> Does anyone else think the Kotlin syntax for array literals is super ugly: Well yeah, except it's really that Kotlin does not have array literals at all, arrayOf is just a variable-arity function.
I guess they think they are cool for being able to provide this feature through a library function rather than a language construct, but someone should tell them they really need to add some syntactic sugar that transparently invokes arrayOf while looking nicer.
For example:
let x = [1, 2, 3] // produces Array
let y: MyType = [1, 2, 3] // produces MyType
f([1, 2, 3]) // produces whatever type f() takesRe: Swift is like Kotlin
#258Earlier quoted context omitted.
> [Kotlin Native] features automatic reference counting with a cycle collector on top, but what the final memory management solution(s) will look like is unknown at this point. https://blog.jetbrains.com/kotlin/2017/04/kotlinnative-tech-...
So it's not ARC (in the Swift sense), it's just RC + cycle breaker.
Re: Swift is like Kotlin
#259Earlier quoted context omitted.
> # using \ is looking for troubles Are you referring to escaping and other special sequences (e.g. unicode codes)? Though it is odd-looking I actually find it rather smart that they decided to reuse an existing mechanism for that: aside from delimiters the only magical character in a string is \ rather than have e.g. both \ and $. > # the useless () My beef is more with 1..5 being inclusive and there apparently bein…
About \, yes it's the possible clash with a real quote. More an inconvenience to the reader that a source of bugs, but also that. About ranges, Ruby has both .. and ... and after 12 years I don't remember which is what. Maybe an inclusive one is enough and 1..(n-1) About syntax in general, it should be easy for developers no matter how hard it is for the compiler/interpreter to parse it. I don't like to have to type…
Clash with a real quote? As in you paste random text from wherever and it turns out evaluated? You've got the exact same issue in Kotlin.
> About ranges, Ruby has both .. and ... and after 12 years I don't remember which is what. Maybe an inclusive one is enough and 1..(n-1)
That's why I like that Swift uses "a..> Maybe an inclusive one is enough and 1..(n-1)
I have never missed inclusive ranges in languages with only exclusive ranges (e.g. Python), the opposite would not be true.
> About syntax in general, it should be easy for developers no matter how hard it is for the compiler/interpreter to parse it
That way lie Perl and C++ and undecidable syntaxes, I'm very much opposed to that.
> I don't like to have to type useless characters.
I don't see what's useless about saying what you're asking for. You define a struct your use a struct block, you define a protocol you use a a protocol block, you define an extension you use an extension block. It's readable and regular.
> But I don't understand your "has to be repeated for every addition" so maybe I'm missing something important here.
If you're adding more than one item in Kotlin you have to repeat the receiver e.g.
val Double.km = (thing)
val Double.miles = (thing)
val Double…
in Swift you just wrap it all in an extension block: extension Double {
val km = (thing)
val miles = (thing)
val ...
}Re: Swift is like Kotlin
#260I like swift's conditionals without brackets, OTOH the syntax for string interpolation is ugly
Ugh, I know it's something that literally every programmer on earth can and often does bikeshed, but Swift just got string interpolation syntax wrong . Parentheses are something that are often part of the interpolated expression... they shouldn't be part of the interpolation syntax itself.
"blah blah \(f(g(42)))"
Seems fine to me.