11 ms·
Swift Algorithms
- Kednicma 6y agoWorse nomenclature than any other big language I can think of, including Go and Python. Why should this package be called "algorithms"?
- iainmerrick 6y agoC++ has similar nomenclature - - the std::algorithms library has generic functions for working with collections: https://en.cppreference.com/w/cpp/algorithm https://en.cppreference.com/w/cpp/algorithm Whether C++ is a good model to follow is another question entirely, of course! But at least Swift isn’t being completely idiosyncratic in its naming choices.
- deleted 6y ago[deleted]
- coldtea 6y agoHuh? It sounds like it shouldn't be called anything BUT algorithms. It implements standard generic algorithms for various operations. The kinds you'd be asked about in an algorithmic test, learn in algorithms 101, and so on. Of course technically any part of a program is an algorithm, but usually (like here) we reserve the name for general things like here (from path and graph to partition and search algorithms), not for our "business logic" algorithm.
- summerlight 6y agoThese functions are designed to be highly generic so can be used as building blocks for many other more specific algorithms while it is not specifically tied to other concepts like container or iterator. Do you have any concise alternatives that reflect these properties?
- hntestacc 6y agotest
- happytoexplain 6y ago>a new open-source package of sequence and collection algorithms, along with their related types. This is exactly what algorithms are at the level of almost any language's included libraries. The name seems spot on.
- hntestacc 6y agosome more test
- jerome-jh 6y agoI agree this is a poor use of namespace. Python has that in itertools, Numpy has combinatorics and random sampling in numpy.random. Maybe they just planned to stop here? Or the algorithm namespace is bound to become overcrowded.
- coldtea 6y agoOne issue with Go's lack of generics is exactly that it can't have such a package (and have it be type safe, fast, and work across all relevant types), except with repeated code.
- pmiller2 6y agoSounds to me like a job for a DSL that compiles down to Golang for the final output. That way, the repeated code only exists in the Golang output and not in the code that humans actually write.
- setr 6y agothe solution is... to not use Golang! more specifically, fairly basic operations on a list of data does not seem like it should call for the complexity of a DSL. IMO unless you need to do this quite a bit on random datatypes, copy & paste would probably be the better alternative. Unless you're referring to a DSL that looks exactly like Golang but with generics & monomorphism.... in which case ok I guess
- pjmlp 6y agoWhen that solution is possible, sometimes project requirements make us use tools that we rather not, but have to.
- mhh__ 6y agoIf you do that you have no soul. Why complicate it when you can just have generics that work from the get go
- Cthulhu_ 6y agoBecause generics is a nontrivial problem to solve in languages and compilers; a really great comment that I bookmarked is here: https://news.ycombinator.com/item?id=9622417 https://news.ycombinator.com/item?id=9622417. I read elsewhere (can't find it now) just how much lines of code and language spec is dedicated to generics in Java. Right now, the Go spec + compiler chain are a lot simpler; adding generics would have made things a ton more complicated. Second, by first spending a lot of time perfecting the core language, understanding it, and resolving early issues, they have a much more stable base now to build generics on top of it. As the comment also implies, they take things slow and steady when it comes to Go; it's a language made to run core systems (e.g. at Google) for the next 30-50 years.
- elpakal 6y agoI love this, and best of luck to Nate and the Apple team. I wonder how many of the (awesome) algorithms on Ray Wenderlich's similar repo fit in: https://github.com/raywenderlich/swift-algorithm-club https://github.com/raywenderlich/swift-algorithm-club
- rudedogg 6y agoThis looks great. I'm looking forward to this and swift-numerics maturing. If you haven't seen it, check out the 2018 WWDC session "Embracing Algorithms" (https://developer.apple.com/videos/play/wwdc2018/223/ https://developer.apple.com/videos/play/wwdc2018/223/). It's worth watching, even if you don't work with Swift.
- zapnuk 6y agoI second that. So far every talk by Dave Abrahams has been entertaining and insightful to me.
- Austin_Conlon 6y agoHe was also recently interviewed on a podcast here: https://swiftbysundell.com/podcast/71/ https://swiftbysundell.com/podcast/71/.
- the_dripper 6y agoI'm watching the talk now, the way the speaker describes the things he does seems to me like hes making fun of the Silicon Valley type lifestyle. I think the talk is really great and funny, thank you for sharing !
- Austin_Conlon 6y agoHe's satirizing the rigid and dismissive Gilfoyle type of person (HBO Silicon Valley character) while also exploring what app developers can learn from them.
- the_dripper 6y agoDo you mean Crusty, because in my Opinion with the character he is portraying he is satirizing the typical health "crazed" silicon valley developer, is he not ?
- typon 6y agoIs Swift worth learning if you're not going to be doing Apple development?
- rudedogg 6y agoI've been using Swift for over 5 years now I think.. and I would say no. Outside of the Apple ecosystem the only thing that is really of interest right now is Vapor. It's a nice language though. I worry it's getting too complex, but the new features enable SwiftUI to work so I can't complain too much.
- xenihn 6y agoNo IMO, but Apple (iOS, macOS not so much) development is still an incredibly lucrative niche, and will continue to be so until the United States collapses. It might even still be useful after that.
- austinl 6y agoAs an iOS engineer, I'm a bit biased, but I'd still say it's currently not practical to learn it if you're not doing Apple development. That said, I love the language, and it's a big part of what motivates me to continue being an iOS engineer (I'm not sure I'd still be at if we had kept on with Objective-C). I would love to see server-side Swift take off, but the ecosystem is still fairly new, so any large project would require you to roll your own solutions more often that you would need to in other languages. I was also excited to see https://www.tensorflow.org/swift https://www.tensorflow.org/swift — Swift being used for ML. Swift is working on support for differential programming, which is a cool development in the space. More info here: https://github.com/apple/swift/blob/main/docs/DifferentiableProgramming.md https://github.com/apple/swift/blob/main/docs/Differentiable... Perhaps eventually there will be enough applications outside of the Apple ecosystem to reach a critical mass.
- moksly 6y agoAs a developer in non-tech enterprise, my biggest dream is probably swift being capable of targeting web and android. We don’t have the resources to currently target all three platforms, and we don’t have much hope for google frameworks as they tend to be changed/abandoned faster than we can afford to adopt them, and we can’t really rely on Facebook tech too much because of corporate ethics (I know it don’t make much sense, but it’s non-tech enterprise, this is probably the least weird ethics rule). I mean, it doesn’t really have to be swift, it could be python, .net or kotlin, for all I care, but it’s probably more likely to be swift.
- xixixao 6y agoNice! Similar space to https://github.com/xixixao/jfl https://github.com/xixixao/jfl, might steal a couple (rotation is a good one)
- xenihn 6y agoI'm really, really happy to see this. I know this is going to sound like parody or satire, but I swear I'm being sincere: this is a huge deal for applying to FAANG (and companies that do FAANG interviews) and leetcoding in Swift. It's incredibly painful and off-putting to re-implement stuff you get for free in Python and Java when you're trying to learn everything else at the same time. Some companies give you the option to use whatever you want if you're applying for an iOS position (Google), and some don't (Apple, Facebook). But either way, if you do iOS, odds are you spend 99% of your time at work writing Swift and/or Objective-C, which means you'll have to put in extra effort in learning/re-learning Python or Java. This is especially great for string algorithm problems. Manipulating strings in Swift in an interview is a traumatic experience if you haven't drilled it repeatedly, and you rarely need to do it during Real Work if you have functional backend developers.
- Dhar_mendra 6y agoArticle is very nice
- mikkelam 6y agoI would love to go and use swift at my work (working in robotics). But swift just doesn't feel mature enough for barely anything outside of iOS/macOS. I had a great time using it for that purpose. The community outside of that ecosystem is barely there. I've picked rust instead, it feels like the exact opposite of the single large actor supporting swift, instead it's a huge community effort with lots of use cases already being seen in many spaces. AND rust just got AVR support which I suppose swift could get pretty quickly with llvm as well
- Cthulhu_ 6y agoYeah, back when we first started using it there was a lot of interest in using it to create back-ends as well, but there just wasn't a lot of support for it. For one, it needed to be developed and compiled on a not-Mac environment to be viable, and that has just never been much of a thing. Might be better now, it does just use LLVM in the back-end and IntelliJ has a good editor for it, but still. I think C# had that problem for a long time, but Microsoft did a great job / made a great strategic decision with .NET Core I think.
- dep_b 6y agoStill Mono, Xamarin and Unity preceded that decision.
- nicoburns 6y agoTrue, but even now the C# library ecosystem is lacking compared to e.g. JVM/JavaScript/Python ecosystems. And that's definitely because it was historically closed source and mostly (but not entirely) single-platform.
- JamesSwift 6y agoI dont agree with "C# library ecosystem is lacking". The nuget ecosystem is massive, and the paid offerings side is much larger (owing to more of an enterprise audience generally). There arent a lot of well known projects that _run_ on the CLR like there are on the JVM, but the in-language ecosystem is just as robust as those other ecosystems if not more so.
- zapnuk 6y agoLooks great. But I wonder why there are platform requirements for what seems to me like pretty basic functions. In RandomSample.swift: // For log(_:) and exp(_:) #if canImport(Glibc) @_implementationOnly import Glibc #elseif canImport(Darwin) @_implementationOnly import Darwin #endif 1. Why aren't those 'basic' functions already implemented in swift, and part of a math package (or in numerics)? 2. Why release a package that does not support windows now that windows is officially supported?
- stephencanon 6y agoThey _are_ in Numerics (including Windows support). I think Nate is just trying to keep dependencies to a minimum, but feel free to raise an issue.
- pjmlp 6y agoSwift blog also has enough of such examples right on the introduction.
- hntestacc 6y agotest
- bredren 6y agoHow much of this collection had decent open source packages already available? How much more efficient are Apple’s algorithms over what was generally accepted as the best prior open source version? Were these algos already a standard set for Apple engineers internally? It seems like customers win if Swift apps are more efficient and less error prone.
- random3479236 6y agoI don't understand the hype honestly. Every modern high level language should provide these algorithms. I tried Swift and it has some nice features, but i in my opinion it's not suited for system programming, because it has some very religious design desicions. For example: - You can't use a for loop to loop over array elements by reference. - Just look how to work with pointers in swift. There is nothing more to say about it. https://www.raywenderlich.com/7181017-unsafe-swift-using-pointers-and-interacting-with-c https://www.raywenderlich.com/7181017-unsafe-swift-using-poi... A system programming language is a language in which you can write an memory allocator, or a function like dlopen(). While you can possibly do this in Swift, it would be much easier even in C. I don't want to say swift is bad. The design desicions are ok for an application programming language.