[HN Gopher] Swift on the Server (2020) ___________________________________________________________________ Swift on the Server (2020) Author : gozzoo Score : 74 points Date : 2021-04-25 18:22 UTC (4 hours ago) (HTM) web link (theswiftdev.com) (TXT) w3m dump (theswiftdev.com) | AndrewZM wrote: | I just finished implementing a small service that talks to the | stamps.com API and I have to say that its been really easy to | implement. Deployment via Docker is really easy, for small | services Vapor is just great. The Vapor Discord community is | absolutely fenomenal. | rnantes wrote: | If you look on the Swift GitHub page you will see tremendous | effort going into async/await. It will change the game for server | side swift later this year. | k_bx wrote: | I don't know how Swift works, but from my Haskell experience, | if your language needs async/await --- it's already failing. | Everything is async in Haskell, so you don't need to think | about it, and cannot accidentally make a mistake by blocking | your async thread by calling sync code from it. | nextaccountic wrote: | > Everything is async in Haskell, so you don't need to think | about it, | | Then why does https://hackage.haskell.org/package/async | exist? | eecc wrote: | I think what he means is that everything in Haskell is | "async" because the language runtime is lazy and types can | encode parallelism: monads and functors fro sequential, | blocking code, while applicatives for independent code. | | Not sure if it's actually correct though. | elpakal wrote: | this! lack of proper async support has been a big deterrent for | me when considering Swift on my server or even Docker/CLI | project. I worried that things like SwiftNIO/Vapor would change | significantly when async landed and would require a lot of | upkeep... I look forward to async landing. | sentinel wrote: | I've used Swift as the backend language for a side-project | website around 2018-2019. I may be out of date, but I wouldn't | recommend it. My main reasons: | | 1. The server-side frameworks are nascent and still changing - | you will really be on the cutting edge if you use them, so be | ready to deal with bugs and to change your project structure when | the devs drop support for the old framework version. | | 2. Related to the above - not having a community around the | frameworks means you'll have to figure a lot of stuff yourself - | DB connection not working and throwing a weird error? You might | not find that answer in SO. | | 3. It's a compiled language - so once you deploy, it can take up | to 5+ minutes until the code is live; Swift (in iOS at least) | doesn't have a good story around build times, so you're at the | mercy of improvements in Swift development, probably coming from | Apple (unless you get in the weeds and start setting up your own | build chain) | | 4. Deployment - when I was working on the project, Heroku was the | only platform that offered a stack for Swift, which they have | since deprecated. I didn't feel like expending the effort to | update to the new stack, and will probably re-write the backend. | It's been a minute since last I worked with Swift, so maybe more | platforms now offer (quick) Swift deployment. | | It's a beautiful language and it has a lot of things going for | it, but as far as server-side, I recommend sticking with boring | technologies: RoR, Django, Node (which is what I'm using | currently). | gjs278 wrote: | this is a list of all the shittiest backend languages in one | post | pixel_tracing wrote: | A lot has changed and Vapor Swift community is alive and has | made significant improvements. The Swift build pack for Heroku | works fine. I've deployed a cluster of Swift services in | Kubernetes. No issues so far for side projects. | sentinel wrote: | Glad to hear about the improvements! Swift is a great | language, I hope to someday get back to using it. | singularity2001 wrote: | It's such a shame Swift has such abysmal support outside Apple, | because it is a thousand times more beautiful and pleasing than | Rust (while offering _some_ of the safeguard mechanisms). | oscargrouch wrote: | For me there's a sweet spot that is meant for languages like | Java, C# and now Swift. For me at least Swift is the natural | successor of this family of language for a bunch of reasons. | | I would'nt create a program in C++ or Rust if i can do it in | Swift, because its much more pleasant, productive and safer | (while i love the level of control and speed C++ and Rust gives | you). | | I would just go for C++ or Rust if the domain i'm solving | require this. Even because for some problem domains there are | very few languages you can use. And i'm glad that now we have | more options on this space like Rust and Zig. | | But for business kind of languages, applications with common | business logic, for me at least there's nothing better than | Swift. | | Script languages can be even better at ergonomics and | productivity, but they tend to have a price that its only | perceived later in regards to efficiency and the lack of a | proper type system. | | On the server side unfortunately, Swift is too late to the | party and Go is already eating the Java cake. But i see a | tremendous potential in Swift for user facing applications. | The_rationalist wrote: | The sweet spot you're looking for is Kotlin. | liuliu wrote: | Both are in the same sweet spot. But both are big languages | with a lot of features and requires a lot of support. | Luckily, so far, they are supported by big companies | (JetBrain is no Apple, but has a good track record of | supporting this kind of things). | | More interesting things are Elixir and Julia, which | arguably are in the similar sweet spot (Elixir may be | closer to that than Julia). | neilv wrote: | Swift on the server might make sense for an Apple-only full-stack | developer, who wants to remain Apple-only, who is happy with the | Swift development experience on the frontend, and who is willing | to bet their backend on Apple's developer support. | | (I'd use Rust, Flask, Node, Go, Scheme, or a variety of other | platforms/approaches first.) | cutler wrote: | This guy is in denial. Swift has been dropped by IBM and by | Google for Tensorflow and Apple doesn't appear to be doing much | to promote Swift outside of iOS and MacOS. | elpakal wrote: | to be fair, Swift for Tensorflow was dropped (Feb 21) way after | this article was written (Aug 20) | https://github.com/tensorflow/swift | slver wrote: | What does Swift have to do with Tensorflow. It's like comparing | apples and oranges. | programmarchy wrote: | There was a port in the works at one point. | agsnu wrote: | After leaving Apple, Chris Lattner (designer of Swift) ended | up at Google for a while and there was an attempt to make | Swift a first class language for Tensorflow. An interesting | podcast on the topic from 2019: | https://www.swiftbysundell.com/podcast/58/ | | Since then he has moved on to SiFive and S4TF has been | shutdown. See HN discussion | https://news.ycombinator.com/item?id=26117453 | qaq wrote: | He is still very active in Swift community though. The | level of accessibility of key Swift contributors I can only | compare to Elixir. | GoOnThenDoTell wrote: | Does Apple use Swift (on Linux) for their own backend services? | slver wrote: | They use a lot of Java and Scala. But I'm sure it's inevitable | some teams are dogfooding Swift on the server as well. Swift is | a very nice language. | danappelxx wrote: | Depends on the team, it's a big company. There are definitely | swift services internally. | yakkityyak wrote: | Not really. It's mostly Java and Go. | djxfade wrote: | Doesn't the iTunes and App Store backend still run on | WebOjbects? | alblue wrote: | Yes, but while web objects was a first class thing in the | objective c world back in 1995 the direction swung due Java | from about 1997 onwards -- I doubt there's any non-Java WOA | any more. For example, it was developed when 32 bit PowerPC | was a thing and I don't think it ever made it to 64 bit | Intel. | Longhanks wrote: | How can you tell? | alblue wrote: | I worked there, and yes, most of the server side stuff is | in Java and Go. | qaq wrote: | Do you need both or would just Go do :) ? Hate Java | alblue wrote: | If you were starting from scratch, you probably would | start with a different system. However web objects was | their web framework at the time which was ported from | objective c to java decades ago and shifting legacy from | any technology to another is practically impossible | especially if that technology is a cost rather than a | product. | bartvk wrote: | Disappointing but perhaps not surprising. Your experience | is reasonably recent? | saagarjha wrote: | Either you ask someone who worked there, or you can trawl | job postings. | qbasic_forever wrote: | How's GRPC support for Swift? That to me is more of a tell if | anyone is using it for internal infrastructure and services in | big companies. | spideymans wrote: | I love Swift. It's my favourite language for application | development. It's terrible that it's effectively restricted to | Apple platforms. | mark_l_watson wrote: | Nice, thanks for writing that up! | | Swift is a great all purpose language. Before Google dropped the | Swift TensorFlow project, I had started writing a "Swift AI" | book. I bailed on the book, and instead have a live-book GitHub | repo with code and README files for the various non-TensorFlow | projects (which I tossed out to /dev/null). The live book is at | https://github.com/mark-watson/Swift-AI-live-book-and-code | liuliu wrote: | Do you want to take a look at https://github.com/liuliu/s4nnc/ | ? Nothing to serious though. | qalmakka wrote: | It's 2021 and Swift is still nowhere to be found in the | repositories of any of the Linux distributions I usually use. | It's a big PITA to install, with nothing comparable to `rustup` | or even truly universal prepackaged binaries - the official | website only offers plain .tar.gzs for either Ubuntu LTS or | CentOS, or source code. It's nowhere to be found on FreeBSD | either, but there's a .exe for Windows. | | Until they expect a novice to download and unpack random archives | and set up environments without any kind of support they really | can't expect to get any kind of growth on Linux. There's | definitely no shortage of new, interesting languages, and too | often Swift's support for non-Apple platforms feels more like an | afterthought than anything. | harikb wrote: | +1. For non-apple usage, I would want to see lot more GitHub | repos with open source support for Swift. Right now even | Kotlin/Rust and others beat Swift in that respect. | | I really like the language, but I don't know what is holding it | back. I wish it solved concurrency without async/await keywords | - that would have been a killer feature to compete with Go | saghm wrote: | > I really like the language, but I don't know what is | holding it back | | From my limited outsider perspective, it seems like Apple's | unwillingness to go out of their way to support Linux is | what's holding it back. There seem to be a large number of | people interested in using Swift on the server, but without | first-party support, Swift on Linux will always be playing | catch up, as new features will always land on MacOS first and | often not be designed with any regard to how they'll work on | Linux. | pjmlp wrote: | Just like Objective-C, it is a language for Apple platforms and | that is about it. | | Try to use GNUStep to see how much an Apple language has | managed to thrive outside of the ecosystem. | Apocryphon wrote: | Objective-C at least has Oolite as a cross-platform killer | app to show off. | raydev wrote: | Did Apple ever support GNUStep or make an attempt for ObjC to | work on Linux in this millenium? | | Because they do have people focused on maintaining Swift | support for Linux. So it's a bit different. | slezyr wrote: | I'm not sure that you can call this "thrive" | | https://en.wikipedia.org/wiki/Category:Software_that_uses_GN. | .. | codetrotter wrote: | That's what they are saying, it's not thriving. | _-david-_ wrote: | I am not sure which distros you use, but Swift is available in | Fedora and EPEL (CentOS/RHEL) 8. The package name is swift- | lang. | eecc wrote: | To be fair, the instructions on | https://swift.org/download/#using-downloads are fairly | straightforward and copy-pastable. | | Indeed the prominence given to pgp signature verification is a | breath of fresh air compared to the current wave of pipe-shell | intros: it's not gatekeeping to ask a would-be programmer to | exercise some reading skills and internalize the idea of | signature verification. | | :) | xbar wrote: | I had similar troubles trying to find the Swift ecosystem. The | author's opening statement that Swift is everywhere rang | hollow, even if it might be technically not strictly false when | viewed from a certain angle under the right lighting | conditions. | | So, I'm playing with Rust. | skohan wrote: | Same. I love programming in Swift, but deploying it is a | PITA. I got tired of waiting around for the cross-platform | story to improve, so I moved on to Rust. It's refreshing to | use tools which feel like they're made by someone who | actually wants you to use them. | heavyset_go wrote: | Swift had a chance 6-7 years ago when it first came out to | capture mindshare on platforms other than iOS and macOS, but | that chance was squandered. There's absolutely no reason | someone would choose Swift over even .NET Core on other | platforms these days. Thankfully, other languages have excelled | during that timeframe. | whatatita wrote: | I would hapily give it a try with a `brew install swift` but | any involved install process is off putting. | NobodyNada wrote: | Homebrew requires the Xcode command-line tools, which | includes the Swift toolchain. If you have `brew`, you already | have Swift. | iddan wrote: | Brew exists for Linux too | jolux wrote: | It does, but I'm not quite sure why you'd use it instead | of apt or dnf or pacman... | [deleted] | alrs wrote: | if you're running brew on Linux, throw in the towel, it's | over. | H_L wrote: | Swift is absolutely an afterthought on non-Apple platforms. | | Apple doesn't even provide ARM slices for the official Swift | Docker images (https://hub.docker.com/_/swift?tab=tags) which | makes server-side development on their own cutting-edge M1 | (ARM) machines basically impossible. | tracer4201 wrote: | I was looking for a language to dive deeper into, and I was going | to pick between Swift or Rust. I ended up going with Rust. Why? I | wanted something to replace C++ that I can write once and re use | on Android or iOS. Also, I found lots of interesting projects | where other people were using Rust. I don't just jump the | bandwagon, but I just didn't see that much excitement for Swift | or really understand it's future as a general purpose language | outside of Apple development. | | And I love Objective C, but again, I only ever saw it being used | for Mac and iOS. | jonplackett wrote: | I love Swift. Especially the newer versions (swift 1 and 2 were | so awful I gave up on it completely but 3+ are great). | | But... I wouldn't personally use it for anything other than | iOS/Mac development because it's always so hard to find examples | / tutorials / help on stackoverflow for less-used languages and I | imagine that's what will be in store for me if I go this way. | cvwright wrote: | This is unfortunately true. I just wrote a very simple little | web service in Vapor. | | Vapor itself is fantastic, but for documentation and examples, | you're pretty much limited to (1) the Vapor docs (2) the Vapor | API docs buried on GitHub and (3) the source code. Fortunately | the source itself is pretty well organized and easy to follow. | jonplackett wrote: | How did you find it? Was it worth the extra effort VS using | some other language? | cvwright wrote: | Overall I found it pretty nice. | | It's hard for me to compare to other languages in this | space, like Go or Rust, because I have basically no | experience with them beyond the very most basic | introductory toy projects. My choices came down to Python | (with Flask or aiohttp) or Swift with Vapor. | | There were a couple of weeks where I wished I had just gone | with Flask and been done with it. | | But beyond the short term, now that I have it working, I'm | glad I went with Swift. One big plus is that I can reuse a | bunch of Swift Codable types between my iOS app and the web | app. Another is that I feel like I have a better | performance/concurrency story than I'd get with Flask. | | Edit to add: I don't think getting started with Vapor was | any harder than with aiohttp. And for me, it was a lot | easier than learning a whole new language like Rust. | [deleted] ___________________________________________________________________ (page generated 2021-04-25 23:00 UTC)