6 ms·
I think one of Swift's advantages is its progressive disclosure. It can be written without using any of its more advanced features, making it approachable witho
by kitsunesoba 6y ago
I think one of Swift's advantages is its progressive disclosure. It can be written without using any of its more advanced features, making it approachable without limiting possibilities for more advanced users.
- usmannk 6y agoI agree. I referenced this (perhaps a bit too implicitly) in a sibling comment. Swift's complexity is there but only when you need it.
- cylon13 6y agoCan 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.
- mhh__ 6y agoIsn't that true of almost all programming languages? Or do you mean cleanly? I think D has to be this idea (or disease depending on who you ask i.e. Go is based on the idea of only keeping the simple bits) taken to the extreme - you can quite happily write Java in D but also implement a Java in D all the way down to the metal (merrily metaprogramming all the way down)
- youareostriches 6y ago>It can be written without using any of its more advanced features... So can Perl.
- Andrew_nenakhov 6y agoI perled a bit in early 00s, and I never used any of those so-called advanced features, because it made the code totally unreadable.
- renox 6y agoIt can sure but I remember having to spend 2hours(with a reference manual open) rewriting two lines of Perl script that a sub wrote (after a colleague told me that he couldn't understand the script) into two lines that a Perl beginner could understand..
- cutler 6y agoI've never understood this notion that a professional codebase should be dumbed down to the level of the beginner. In most professions the neophyte must jump though hoops to reach mastery yet in programming we seem to have turned this idea on its head. Whatever happened to mastering your tools? A seasoned Perl veteran should be able to play a damned good round of golf.
- _jal 6y agoIt is an appeal to the artistry inherent in making the difficult as simple as possible. Or the internalization of the managerial imperative for cheap labor, take your pick.
- coldtea 6y ago>Whatever happened to mastering your tools? Companies prefer a churn of cheaper juniors happened.
- SiVal 6y agoWe have too many different, interacting parts in most software systems these days to demand devs have pro-level expertise in every part they might have to deal with. If you can simplify the code (without significant harm to functionality) so that only 10% of your potential devs wouldn't understand it very well instead of only 10% would understand it well, you have just increased the value of the code.
- rpastuszak 6y agoAll of this sounds great but it doesn’t mean that the code written in it will maintain the same level of simplicity/approachability. Go has the advantage of enforcing it. Writing code is easier than reading it. Don’t get me wrong, I love swift but I think that for what you’re talking about constraints are necessary because we naturally shift towards more complex ways of expression.
- anoncareer0212 6y agoExactly, I was in love @ Swift 2, but as the language evolved to cover corner cases and enable things like SwiftUI, it became nigh-unreadable, there's simply too many 'dialects'. Dart is the closest I've found to optimizing the surface area of a language while maintaining flexibility like ObjC.
- a1369209993 6y ago> It can be written without using any of its more advanced features If anything, that's bad, because it invites projects to adopt a impoverished subset of the language that avoids those features, in which case they might as well not exist because you aren't allowed to use them.
- sangnoir 6y agoThis describes Perl - one could get very clever with it. As a recovering Perl programmer - that is a scary thing for a language to be, especially for large code-bases worked on by people with different skill levels as the code quickly becomes inconsistent, with mixed paradigms.
- simonh 6y agoI once came across a production bash script that contained sections in Korn syntax, others in C Shell syntax and yet others in bourne shell syntax. Lovely!