4 ms·
> Swift is widely marketed as a functional language If that's true, those sources reporting that are wrong. Apple itself refers to it instead as a "protocol-or
by hellofunk 11y ago
> Swift is widely marketed as a functional language
If that's true, those sources reporting that are wrong. Apple itself refers to it instead as a "protocol-oriented language" when it's not just saying "object-oriented".
Swift is definitely not a functional language in the way that it usually means, and Apple knows this, and any legit survey of languages wouldn't clump it together with much more functional languages. For example, this guy[0] knows what he is talking about.
> Where Swift shines it is in the integratiion with the underlying Objective C frameworks on the Mac.
>Swift is a good replacement for contexts in which Objective-C would be used.
Except when you try to do anything with OpenGL or a C-based API, like Core Audio. Swift is really lagging for "power programming" with these low-level APIs. It's great for beginners who use all the high-level frameworks (though "great" is a subjective term I don't really agree with for Swift), but a lot of people who really need to get stuff done on Apple's platform are not going whole-hog Swift.
>If you’re coming form Erlang/Haskell world you’ll think Swift is verbose and a bit of a mess but if you’re coming from Objective-C you’ll think “Swift is concise and elegant”
I got to be honest, I still find I prefer Objective-C, because, it's essentially C. I can use my C structs and interfaces with zero problem. But in Swift, all C primitives are translated into Swift-only stuff, even integers!
And don't get me started with trying to use a C++ library with Swift, something that's smooth with Objective-C. Which is ironic since Swift itself is written in C++.
[0] http://robnapier.net/swift-is-not-functional http://robnapier.net/swift-is-not-functional
- melling 11y agoIn your provided reference, the first sentence Rob writes: "Ever since Swift came out, I keep seeing weird comments that Swift is a functional programming language" Swift is often promoted as being "functional": http://www.raywenderlich.com/114456/introduction-functional-programming-swift http://www.raywenderlich.com/114456/introduction-functional-... In fact, I've tagged many articles as functional in my Swift resources: http://www.h4labs.com/dev/ios/swift.html?q=functional&age=10000 http://www.h4labs.com/dev/ios/swift.html?q=functional&age=10... Want to buy a book on functional programming in Swift? https://www.objc.io/books/functional-swift/ https://www.objc.io/books/functional-swift/
- hellofunk 11y agoNote that the objc.io book is more about building functional idioms from scratch so you can use swift in a functional way, rather than actually leveraging a strong functional core of the language. The fact remains that Swift is just not a functional language and attempts to categorize it as such are unrealistic.
- seivan 11y agoOn a WWDC video named something along the lines of "Value types in Swift" they explained that Apple is trying to get try middle ground between protocol oriented and functional. Same thing with mutability and immutability. They aren't pure anything because both ways have their purposes.
- s73v3r 11y agoPeople say a lot of things. Doesn't make them right.
- pg_is_a_butt 11y agoi agree... you're wrong.
- robbyking 11y agoSwift is a multi-paradigm language. In that Ray Wenderlich article you linked, he writes "This tutorial focuses on just one of these methodologies, FP (Functional Programming)"
- mikeash 11y agoWhat is a "Swift-only" integer? Swift integers are just integers. They interoperate with C just fine. Interacting with C APIs in Swift is pretty much as convenient as using them from C or Objective-C. Which is to say, it's kind of inconvenient compared to using a good Swift API, but you don't gain a benefit from using C or Objective-C instead. The major exceptions to this are the inability to take a pointer to something before it's initialized (for example to use a local variable for an out-parameter) and the inability to declare arrays on the stack. The former just requires some "= 0" or similar, and the latter can be worked around without much difficulty using a Swift Array or just using malloc and free, at the expense of a bit of performance. There is also a problem where Swift translates fixed-length arrays to tuples (because Swift has no concept of fixed-length arrays) which can be inconvenient, but this rarely comes up. Maybe you're just not familiar with the facilities Swift provides for interacting with C APIs and are doing things in a more difficult way than is necessary. It's absolutely true for C++ interfaces, of course, but Swift doesn't even try and never advertises C++ interop. For that, you have no choice but to use C++ or Objective-C++. But for plain C APIs, Swift does a great job.
- hellofunk 11y agoWhat about stuff like this, these weird castings that pop up in Swift that you don't worry about in Objective-C when dealing with C APIs: glBindBuffer(GLenum(GL_ARRAY_BUFFER), bufferIds[1]) glBufferData(GLenum(GL_ARRAY_BUFFER), sizeof(Float) * tcSize, tc, GLenum(GL_STATIC_DRAW)) That just looks silly to me.
- potatolicious 11y agoSwift enums are considerably different from C/Obj-C enums so the cast is unavoidable. Specifically unlike C enums, Swift enums can be backed by non-integer types like Strings. For numeric types that have a clear equivalence in C-land, Swift is seamless.
- comex 11y agoActually, GLenum is not a C enum in the first place; it's just an integer typedef.
- deleted 11y ago[deleted]
- nstj 11y agoI actually find working with C in Swift to be far more pleasant than using C directly. The blog post by our friends at Apple on the subject -https://developer.apple.com/swift/blog/?id=6 https://developer.apple.com/swift/blog/?id=6 - gives a pretty good background.