7 ms·
With safe concurrency and typed throws, Swift is starting to look a lot like a friendlier Rust to me. Honestly pretty excited to take a look at it again, though
by dmart 2y ago
With safe concurrency and typed throws, Swift is starting to look a lot like a friendlier Rust to me. Honestly pretty excited to take a look at it again, though I doubt it will become my daily driver due to the smaller package ecosystem. Hopefully cross-platform Foundation is a step towards improving that though.
- steelbrain 2y ago> Swift is starting to look a lot like a friendlier Rust to me. That’s what i thought and rewrote my cli util in swift. Ran great on macOS, tried to build for windows and found out there’s no well maintained, actively developed http server for windows for swift. Dont let these wooing crowds fool you
- asplake 2y agoHa! That seems to answer my next question: what’s its story for web development? Does it have one?
- myko 2y agoVapor works great on Linux and macOS. Haven't tried Windows (pretty much only run Steam there these days)
- alexashka 2y agoYou can't compile for Linux from XCode (defacto IDE for all things Apple) and all web dev runs on linux. If you like having an IDE instead of scrolling multi-page compiler error dumps in your terminal window - this is a complete non-starter. The leading Swift web framework (Vapor) suggests you use Docker to build for Linux. I gave it an honest try - their empty starter 'hello world' web server takes more than a minute to compile. Ok, but surely it'll be faster after I make a one liner change? No - their docker workflow has 0 compiler caching - you'll be waiting more than a minute every time. Complete non-starter. I ended up installing a VM, installing the swift compiler and that only takes 2-3 seconds to re-compile a 1 liner change (in a print statement, in an empty project, lol). Consider me very deeply unimpressed. By comparison - a visual studio code + docker + python/ruby/javascript setup is a well oiled, working machine.
- JoeMattiello 2y agoYou can install other toolkits for Xcode. There’s even an aws toolkit.
- alexashka 2y agoIs it possible to write code in Xcode, press compile and have the debugger show me where an error is when compiling for linux. If yes, please show me the way because I've failed and I've given it an earnest try.
- saagarjha 2y agoYou can use LSP?
- w10-1 2y ago> story for web development Under the hood, Swift-NIO and async Swift is a pretty powerful basis for writing performant servers. Aside from Vapor, there are other small/fast containers like hummingbird. Not mentioned (surprisingly) is Swift support for wasm/wasi, for deploying code directly in the browser. Also, "some say" that macros could revolutionize both static and dynamic generation by moving a good portion of site generation to compile time. I'm not aware of any libraries realizing that promise yet. Finally, Swift concurrent actors have supported distribution for some time, so you can have all-Swift distributed systems, where the client code works with both local and remote servers.
- Larrikin 2y agoDid you look at Kotlin?
- synergy20 2y agoSwift does not use virtual machine and garbage collection, it competes more to c++ and rust and if Apple is serious about pushing it cross platform that's definitely a welcome move, in fact, I can't wait even though I have never programmed in swift. the main point is that, it's memory safe, and seems much easier to code than rust.
- glhaynes 2y agoMemory safe and, with Swift 6, data race safe.
- timeon 2y ago> Swift does not use virtual machine and garbage collection, it competes more to c++ and rust Doesn't it use ARC by default?
- azinman2 2y agoWhich is reference counting, not garbage collection. Ref counts free when count = 0. Garbage collection scans all object pointers and looks for loops / no missing pointers.
- vor_ 2y agoReference counting is a kind of garbage collection.
- mkl 2y agoThat's tracing garbage collection. Reference counting is another type of garbage collection. https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Strategies https://en.wikipedia.org/wiki/Garbage_collection_(computer_s...
- jakey_bakey 2y agoHow hard is it to build an HTTP server? (Yeah, this is a dumb question but I'm asking anyway)
- Eric_WVGG 2y agoDo you mean from first-principles, or letting someone else do the work and use a framework? Apple did the hard work, https://github.com/apple/swift-nio https://github.com/apple/swift-nio. If you just want a big framework to launch an API, that's been around for years: https://vapor.codes https://vapor.codes
- akvadrako 2y agoThat all depends on your requirements. A few hundred lines of code will get you pretty far, but there are about 100 optional features in common use.
- taftster 2y agoSneakily hard, actually. There's different versions of HTTP (of course), so pick your target. But when you hit HTTP/2.0, it's not a simple request/reply model (if HTTP/1.1 can be described as such). The intermixing of various client headers and what they imply to server behavior, handling of the streams and when to open vs. when to close, http/2 multiplexing, etc. Don't forget HTTP/3 which uses the QUIC protocol (UDP based) instead of TCP. Interestingly though, a trivial HTTP server is actually very easy to implement as well. A very crude HTTP/1.0 server (or maybe even a limited scope HTTP/1.1 server) can actually make for a fun afternoon project. Like minimal (or no) concurrency support, all TCP connections closed after the request/response cycle, GET only (or maybe POST only), etc. So it's a mixed bag of what you want and how you define an HTTP server.
- astrange 2y agoI can't think of a good reason to want to implement the complex parts. Write an HTTP service if you must, but make it HTTP/1.0 (or 1.1 for keepalive) and stick it behind nginx to do the newer versions and SSL termination. (I also think all HTTP services should if possible be written in a shared-nothing CGI type language, and not embedded in your random stateful program. This way you can't accidentally leak info across user sessions.)
- neonsunset 2y agoFor fast web servers, you could use .NET, especially if you care about Windows. It gives you good ecosystem and consistent experience across all platforms. Even FreeBSD support has improved considerably as of lately. It is already built on top of what Swift, Java and others call "NIO". In .NET it's just "SocketAsyncEngine" users will never know about unless they look for it :)
- darby_nine 2y agoCurious! In what ways do you do you see swift as friendlier than Rust? I perceived it as functionally equivalent, although Swift had a lot more "magic" involved and it was less clear how things might work memory-wise.
- 9dev 2y agoMore magic (thus less required explicitness) and less involvement with memory management are typically considered as friendly traits in programming languages.
- darby_nine 2y ago> More magic (thus less required explicitness) and less involvement with memory management are typically considered as friendly traits in programming languages. Really depends on the context. I really, really, really hated this instinct in the ruby on rails community when I was still doing that. Magic is nice until it doesn't work the way you expect, which is when it becomes an active liability. I really don't spend much time thinking about memory management in Rust, but I can certainly understand why one might be happy to not have to design around ownership and lifetimes. I really like the explicit nature of it, though, makes it super easy to read and reason about code you've never seen before.
- dagmx 2y agoTo me, Swift has better ergonomics for most people. Ref counting by default makes most programs easier to deal with. Guard let (though recently somewhat introduced in rust) are much more friendly ways to unwrap optionals. Being able to provide parameter defaults and aliases. Easy passing in of callbacks. Easier async. Null chains with the Question mark operator. I really like rust, but it’s much faster to get to a working program in Swift. And with the new CXX interop, I now reach for Swift by default since I have to deal with a lot of C++ libraries.
- darby_nine 2y ago> Easier async. I was on board until this one. Async is a rough spot for rust, but I find the async strategy swift went with absolutely baffling and difficult to reason about.
- porcoda 2y agoI’ve migrated to swift for some nontrivial projects that were formerly C++. Quite happy so far, and didn’t find rust nearly as pleasant when I tried the same thing there. I don’t want explicit memory management very often, so ARC works great for me. Haven’t had any issues with portability either, although I don’t test often on windows so I’m not confident there but Linux and Mac have been great.
- dogprez 2y agoI'm glad you found something you like. I just want to make it clear that the things about Rust that make it "unfriendly" are also the things that make it able to do things other languages can't do, like compile-time memory safety. Depending on what you are making, that might make little difference. I just wanted to make sure you appreciated what Rust can do that other languages can't.
- astrange 2y agoThis is an article about another language that can do that.
- dogprez 2y agoNo, sorry, it's not https://doc.rust-lang.org/1.8.0/book/references-and-borrowing.html https://doc.rust-lang.org/1.8.0/book/references-and-borrowin...
- astrange 2y agoSwift does have borrow checking: https://www.swift.org/blog/swift-5-exclusivity/ https://www.swift.org/blog/swift-5-exclusivity/ Basically the difference is that Swift's is more implicit, happens more at runtime, and it will make some programs work via copy-on-write that Rust would reject. So that's obviously more limiting. It's more flexible when you can allocate memory freely, but it doesn't work if you can't.
- dogprez 2y ago> happens more at runtime Bingo, that's the difference. That's why I said "compile-time memory safety". This is what Rust gives you for your trouble, zero (runtime) cost for memory safety.