4 ms·
What makes code “Swifty”?
- effnorwood 7y ago*Schwifty
- nsxwolf 7y agoShow me what you’ve got!
- deleted 7y ago[deleted]
- deleted 7y ago[deleted]
- setpatchaddress 7y agoThe title here is misleading. Most of this applies to Objective-C. There's nothing wrong with the article as far as programming advice goes, but it has nothing to do with Swift idioms. > So, to make our code more “Swifty” from a performance point of view, sometimes all that we have to do [is literally the same thing we would do in Objective-C] Is anyone writing consistently good, up-to-date Swift documentation for experienced programmers? Some of the early books haven't been updated since the earliest Swift versions. SwiftUI is very poorly documented by Apple and much of the third-party SwiftUI docs are for the obsolete WWDC version.
- saagarjha 7y ago> Most of this applies to Objective-C. Objective-C’s type system is much poorer than Swift’s, and it lacks a number of expressive operations. The “before” examples are generally how a lot of people would actually write code in Objective-C.
- refulgentis 7y agoWhich ones? I wrote ObjC for 7 years, Swift for 3. I only looked at the first two examples, they both were generic programming advice, nothing to do with the language
- saagarjha 7y agoThe first three. Objective-C doesn't have enums with associated values and it's common to store things in heterogeneous collections or stringly-keyed collections. Creating protocols for generic constraints is also rare–informal protocols (respondsToSelector, anyone?) are instead quite prevalent. And Objective-C's "collection" APIs are much less powerful than Swift's: I might use a regex replacement instead of four calls to replacingOccurrences(of:with:), but it's the same principle.
- deleted 7y ago[deleted]
- metalgearsolid 7y agoTo answer your question: objc.io
- oflannabhra 7y agoI’ll tack on a couple sources to this: http://pointfree.co http://pointfree.co - high quality content, emphasizing functional programming. https://oleb.net/blog/ https://oleb.net/blog/ - blog of Ole Begemann, co author of Advanced Swift (good resource itself) https://appventure.me https://appventure.me - Benedikt Terhechte’s topical guides to Swift features https://andybargh.com/blog/ https://andybargh.com/blog/ Andy Bargh’s topical articles
- plorkyeran 7y agoThe first example utilizes a feature of Swift's type system which obj-c does not have (enums with associated values) to write code which is better than could be done in obj-c. This seems like a perfectly good example of improving code by making it more "Swifty", as one of the distinguishing features of Swift is that it has a more powerful type system than most mainstream languages. The second example is strange. It's improving the code by making it call the correct method from the standard library rather than the wrong one. I guess that's not bad advice, but I have no idea what it has to do with Swift in particular. The third one is a missed opportunity. Swift has some unusual ideas around how things should be named (partially inherited from Smalltalk via obj-c, but also partially new), but instead of talking about that it's just generic "give things useful names" advice that has little to do with Swift.
- iddan 7y agoOh how wonderful will it be to program front end and backend web apps with Swift, I just can’t wait
- jamil7 7y agoI'm hoping apple starts to take the cross platform story more seriously. It sounds like it's a big topic for the release of 6. I find it to be a really pleasant and productive language to work in.
- MR4D 7y agoI’d love to see Sundell go and optimize the code on the Computer Language Shootout so we could see its potential in a swifty way.
- bsaul 7y agothere's always been something i wondered about swift : how does it compare to other PL in terms of performance ? The initial promise was to have it be comparable to other compiled languages ( java , c++, whatever), but i've yet to find a real benchmark. Or rather, the ones i've seen made it look more on the range of interpreted/dynamic languages ( ruby / python or node), at least for server side projects. Which came as a surprise to me. Has any real work been work on that issue somewhere ?
- pjmlp 7y agoRather slow currently, thanks ARC. https://github.com/ixy-languages/ixy-languages https://github.com/ixy-languages/ixy-languages
- skohan 7y agoThis is not a good representative benchmark for Swift. It uses lots of reference counted objects within tight loops, which is a worst-case for Swift. It's also not idiomatic Swift - classes are used in many places where they should not be. Also, it's a benchmark which needs special hardware to be run, so it's not easy to try to reproduce or improve on this result.
- pjmlp 7y agoThe same conditions apply to all languages.
- Sohcahtoa82 7y agoIdiomatic Swift code is called "Swifty". Idiomatic Python code is called "Pythonic". Idiomatic Java code is called "terrible".
- skohan 7y agoPerformance is not really a USP of Swift. It's certainly possible to write high-performance Swift code (with the help of a lot of profiling) but if your main concern is performance, you would be much better served reaching for Rust or C/C++. IMO the most important things about Swift code is that it has nice safety features, and it is easy to write clear, self-documenting code.