7 ms·
Can it be read without knowing about its more advanced features though? Production software is read much more often than it is written.
by cylon13 6y ago
Can it be read without knowing about its more advanced features though? Production software is read much more often than it is written.
- nicoburns 6y agoI've been able to dip into Swift codebases with zero previous experience without too much trouble. I do have Rust experience which helps. But never-the-less everyday Swift seemed pretty readable to me.
- cutler 6y agoSwift has some really clunky "features" such as dual-identifier parameters and escaped opening parens as identifiers for string templates. WTF! As if function/method declarations weren't complex enough in a statically-typed language which supports generics.
- pansa2 6y ago> escaped opening parens as identifiers for string templates Do you mean the use of “\(variable)” for string interpolation? What’s wrong with that?
- cutler 6y agoIt's just downright clunky. What's wrong with ${variable} as in Kotlin and Javascript?
- mantap 6y agoThey had good reasons, it means there's only two substrings that need escaping: the backslash and end string sequence. In hindsight, it's ugly and hard to read. A case of optimising for the wrong thing.
- Someone 6y agoI think that’s more a question of taste/what one is used to. I find that dollar sign a bit heavy, visually, but one could also argue that’s a plus. Using backslash has the advantage that there’s only one ‘special’ character in strings, but of course, also has the problem can escape any character with a backsplash, except for opening parentheses.
- santraginean 6y agoThey’re not dual identifiers; one is an argument label and the other is the parameter name. Maybe it’s because I come from an ObjC background, but this is one of my favorite aspects of the syntax; IMO it makes code way easier to read without having to look up method definitions to figure out what each argument does.
- dmitriid 6y agoFrom State of the Platform this year: https://pbs.twimg.com/media/Ebb51t6XkAIF4YD?format=jpg&name=large https://pbs.twimg.com/media/Ebb51t6XkAIF4YD?format=jpg&name=... Which for is for and would work as for for?
- saagarjha 6y agoOne of Swift's strengths is that most of its features really make sense if you read them, even if you aren't aware they existed. The entire language is optimized around readability. (No, I'm not counting the function builder fiasco.) For example, you may not know that Swift's loops support where clauses: for i in 1..<10 where i % 2 == 0 { print(i) } But you can immediately understand how it works, because it's consistent with the rest of the language and reads well.
- kbenson 6y agoA where clause on a loop is nice, but I think it's likely it will either be abused or be limiting. I've always favored systems that work well together to build something more than the sum of the parts. Perl is an example of that in many cases. for my $i ( 1..(10-1) ) { next if $i % 2 == 0; print $i; } Here Perl's post-conditional syntax (which works only on a statement and not a block so it's more manageable) combines well with "next" (Perl's version of "continue") to very clearly convey intent without a lot of extra boilerplate. An additional clause is often just an additional line. Comments after each can provide additional context as needed. I think this is a more flexible way to accomplish the same thing, and more readable in all but the simplest of cases. And for those simplest of cases, I would use a grep, which is also useful in other parts of the language: for my $i ( grep { not $_ % 2 } 1..(10-1) ) { print $i; } Any syntax learned that works as a special case to only a single structure is either a case of missed opportunity or a case of extra syntax that needs to be learned which shouldn't be, IMO.
- saagarjha 6y agoThat where is not a one-off construct, it's used with switch statements: switch i { case 1...100 where i % 2 == 0: print("\(i) is a small even number") case ..<0: print("\(i) is negative") default: print("I couldn't care less") } Or generic constraints: struct Vector<T> where T: Numeric { // ... } If you so wish, you can always use any of the functional constructs as well, as in for i in (0..<10).filter { $0 % 2 == 0 } { print(i) }
- coldtea 6y agoTotally. It's very easy to read.