5 ms·
Genuine question: is there any reason to use Swift without iOS/SwiftUI? (Outside of devs who are primarily Swift developers that want to use something they alre
by Vt71fcAqt7 2y ago
Genuine question: is there any reason to use Swift without iOS/SwiftUI? (Outside of devs who are primarily Swift developers that want to use something they already know for a small project or similar.)
- Mandelmus 2y agoIt's a beautiful language that's a joy to write. It's safe and ergonomic, and has an extremely powerful type system. I'd say those are good reasons to use Swift.
- oddevan 2y agoI'm really interested in exploring it for building web app backends because of this. Being able to have a drag-and-drop distribution is even better.
- _mlbt 2y agoI haven't used it yet, but I've heard really good things about Vapor as far as server side Swift goes... https://vapor.codes https://vapor.codes
- OKThatWillDo 2y agoThanks. What is a "protocol server?"
- potatolicious 2y agoNot a super-expert but I've used Vapor on some personal projects. Do you have a link to the mention for "protocol server"? I'm not familiar with the concept but might be able to help.
- Redoubts 2y agoI'm guessing they clicked onto the Built with SwiftNIO link and saw this at https://github.com/apple/swift-nio https://github.com/apple/swift-nio.
- OKThatWillDo 2y agoThat's right. I did a search but this term does not seem to have a trendy or thorough definition.
- _mlbt 2y agoIn this instance they're talking about implementing network protocols, such as HTTP, where one end is the client and the other end of the connection is the server. It's confusing because the Swift language also has the concept of "protocols" which are basically the equivalent of Java and C#'s interfaces if you're familiar with those languages.
- e63f67dd-065b 2y agoThe main reason is that Apple has effectively deprecated Objective-C for ios/macos development going forward. It's not going away for probably another decade+, but all documentation is now in Swift, new APIs are written with Swift in mind, etc. Think of it this way: in 5-10 years, ObjC will be the python2 of Apple development.
- hbn 2y agoThe GP was asking specifically about non-Apple development
- righthand 2y agoNot really no, there are far better languages with better cross platform support.
- josephg 2y agoWhich languages do you think are both better and have better cross platform support?
- boffinAudio 2y agoLua, I would say. Far easier to get it everywhere, and a very nice language, also.
- josephg 2y agoLua is nice, but it’s a bit of a weird comparison for Swift. Swift is compiled and lua is interpreted. Swift is statically typed. Swift uses ref counting to Lua’s runtime GC. And Swift has non nullable types by default, classes, enums, ADTs, match expressions and so on. Lua is nice. But it’s chalk and cheese comparing the languages. I can’t think of many cases where you’re trying to decide between lua and Swift.
- boffinAudio 2y agoIn this case, the question is whether to use Swift for a backend server on a Linux machine, or something else. That's the environment. I'd prefer Lua, simply because its a very proven language for that application. Sure, Swift has sexy features that make it appealing to developers. But the ecosystem for server infrastructure on Lua is formidable.
- Tainnor 2y agoKotlin
- sureglymop 2y ago
- airstrike 2y agoNo language feels more pleasurable to write in. It's incredibly expressive and things are just dead simple 99% of the time It's not perfect, but I hope it continues to flourish because it gets a lot right
- jimbobthrowawy 2y agoHas nobody made a polyfill for swiftUI on other platforms yet? Or is it too tied to apple OS-level APIs? The language itself is pretty nice, last I used it. Even if some of the method (argument?) names in most SDKs are absurdly long.
- robertjpayne 2y agoYou can implement the same syntax for a renderer on other platforms but all of SwiftUI is closed source. So the diffing engine etc… all would need to be re-created from the ground up. SwiftUI, like react uses some language constructs to make it look really fancy but in reality it's really simple nested data structs. The real hard part is what the "DOM" provides for React and likewise what UIKit/iOS is doing with those data structs.
- BodkinsOdds 2y agoThere's a couple: https://github.com/stackotter/swift-cross-ui https://github.com/stackotter/swift-cross-ui (Linux + Windows) https://github.com/TokamakUI/Tokamak https://github.com/TokamakUI/Tokamak (WASM + MacOS + some Ubuntu support) They both had to rewrite the entire backend from scratch, because SwiftUI is very, very closed source. But Tokamak does have an import that just forwards to SwiftUI on Apple platforms.
- wg0 2y agoHaven't written Swift ever but it seems very elegant language. In that spot, only go stands but go although simple but has very ugly corners such as error handling and a weird type system. So yes for me, I might switch to Swift which seems very elegant and readable compared to some other options.
- Tainnor 2y agoI was maintaining a server-side app written in Swift from 2018 to 2020 and we ran into tons of issues at least back then. I haven't looked into all the improvements they did since, but you might want to check. My coworker wrote down some of the major issues we were facing: https://forums.swift.org/t/issues-learned-4-years-with-server-side-swift/35115 https://forums.swift.org/t/issues-learned-4-years-with-serve... Personally, I've been soured enough that I don't ever want to write any server-side code in Swift again. It just seemed that Swift pretended to be open-source and cross-platform and then Apple would just unilaterally push some changes just because they wanted them for iOS (e.g. function builders for SwiftUI) without waiting for community feedback. It's fine to be a dictator for your PL, but not when you're claiming to have "open governance". All the while support for Linux was routinely being neglected. I would rather recommend Kotlin. It's similar enough to Swift and it comes with the advantage of having the whole JVM ecosystem which can probably do most things you'd ever want to do on a server.