this post was submitted on 27 Aug 2023
54 points (92.2% liked)

Programming

17325 readers
75 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

I’ve been programming for decades, though usually for myself, not as a profession. My current go-to language is Python, but I’m thinking of learning either Swift (I’m currently on the Apple ecosystem), or Rust. Which one do you think will be the best in terms of machine learning support in a couple of years and how easy is it to build MacOS/ iOS apps on Rust?

top 50 comments
sorted by: hot top controversial new old
[–] mrkite 30 points 1 year ago (2 children)

Rust is the only language I know of that is actively being used at the kernel level all the way through to the web app level. Compare that with Swift which is not only mostly tied to a single ecosystem, but even the "cross platform" stuff like libdispatch is littered with code like:

if #available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)

[–] [email protected] 5 points 1 year ago* (last edited 1 year ago)

Note libdispatch runs on older versions of Apple Platforms than those version numbers. The backwards compatible code paths aren't just for other operating systems - that's how it works on older Apple platforms too.

[–] [email protected] 29 points 1 year ago* (last edited 1 year ago) (9 children)

Swift has little to no use outside the apple ecosystem, and even if you are currently using Apple, you have to consider your targets as well. Writing in Swift means your code will only be usable by other Apple users, which is canonically a rather small fraction of technology users. Rust on the other hand is multiplatform and super low level, there's very few other languages out there that can match the potential of applications of rust code. Thus you will, in time, be introduced to many other technologies as well, like AI/ML, low level programming, web, integrations between languages, IoT, those are only a few of all the possibilities. On the other hand, even if Swift has a much more mature ecosystem, it's still only good for creating UIs in all things Apple, which is pretty telling; Apple is not willing to put in the time and effort to open it's language to other fields, because it sees no value in them being the ones providing the tooling for other purposes. They pretty much only want people to code web apps for them, and Swift delivers just fine for that. So if your current purpose is making Apple UIs, you could learn Swift, but be warned that either you'll either be doing that your whole life or will eventually be forced to change languages again.

Then again, most languages nowadays aren't that different from each other. I can code in a truckload of languages, not because I actually spent time making something coherent and complete with each one of them, but because I know some underlying concepts that all programming languages follow, like OOP, or functional programming, and whatever those entail. If you learn those you will not be afraid to switch languages on a whim, because you'll know you can get familiar with any of them within a day.

[–] [email protected] 15 points 1 year ago (2 children)

Just a nit: swift is opensource and there is a swift ecosystem outside of apple UI things. Here's a swift http server that you can totally run on linux.

[–] [email protected] 11 points 1 year ago (4 children)

Don't get me wrong, Swift is OSS and there are things you can do with it apart from front-end dev, but there are usually better options out there for those other things. For example if I want an HTTP server, I'd choose JS, Kotlin, Rust, etc.

load more comments (4 replies)
[–] [email protected] 8 points 1 year ago

Swift only treats Apple OSes as first class citizens - even though technically you can use it on other platforms it's a painful and limited experience.

load more comments (8 replies)
[–] [email protected] 12 points 1 year ago (1 children)

I think rust is good for learning some low level concepts, especially coming from python.

I don’t think Python is going anywhere in the ML space though.

[–] [email protected] 1 points 1 year ago (1 children)

Agree. I'm kinda looking for marketable skills though and I feel Python may be becoming saturated.

[–] [email protected] 4 points 1 year ago (1 children)

A programming language itself isn’t a marketable skill!

Learn the underlying concepts of programming and how computers work and you’ll be able to move from language/framework to pretty much any language/framework easily.

[–] Von_Broheim 2 points 1 year ago (1 children)

Language absolutely is a marketable skill because most companies are looking to hire someone who can start working day one not someone they'll have to train for weeks or even months in a new language that heavily relies on some specific framework.

[–] [email protected] 3 points 1 year ago

I have to disagree. I’ve been conducting interviews for a fairly large software shop (~2000 engineers) for about 3 years now and, unless I’m doing an intern or very entry level interview, I don’t care what language they use (both personally and from a company interviewer policy), as long as they can show me they understand the principles behind the interview question (usually the design of a small file system or web app)

Most devs with a good understanding of underlying principles will be able to start working on meaningful tasks in a number of days.

It’s the candidates who spent their time deep diving into a specific tool or framework (like leaving a rails/react boot camp or something) that have the hardest time adjusting to new tools.

Plus when your language/framework falls out of favor, you’re left without much recourse.

[–] [email protected] 11 points 1 year ago (2 children)

Other than having first class support on Apple's hardware Swift dosen't have much going for it. There is no killer feature in Swift, it dosen't widespread features and it only has a small niche. If you want to develop for mainly Apple devices I would say go for it as that is the niche it was designed for. Although I see from your post you want to do ML, Python for the high level stuff + C++ for the low level stuff is probably your best pick for that. May I ask what type of ML are you going for? Are you mainly using libraries like Tensorflow, Pytorch etc... or are you into the nitty gritty of building these things yourself and writing the required code for the matrix math and training algorithms.

[–] philm 3 points 1 year ago

Swift is a nice language though.

But I'm obviously on team Rust^^ for various reasons (one being that you can do the whole stack in Rust (not that it's necessarily the best choice for each level, but it really composes well and with a little bit of trait-magic abstraction in the higher levels it works quite well IME)

For ML, python yes, certainly for high-level stuff at least currently. I wouldn't be so sure in the future about the lower stack though, Rust seems to gain momentum there as well (potentially replacing use-cases where currently python is dominant too).

[–] [email protected] 2 points 1 year ago (2 children)

I think ML is probably going to require a lot of people in the future and I'm looking to build a digital nomad skill set for the future that pays well. While I've done a postgrad subject on ML and have a STEM degree, but I'm inclined to use existing libraries as that's just easier.

[–] [email protected] 2 points 1 year ago

There's a recent Rust ML framework called "burn". So maybe there's also a future for ML in Rust for you.

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

If you want to train your neural nets you can maybe check out: https://github.com/rust-ml/linfa https://github.com/param087/swiftML (Rust seems to have more active support in terms of libraries)

If you want to integrate ML into an IOS/MacOs app: https://developer.apple.com/documentation/coreml

For userland apps Swift would be better and for training or just being generally being more useful in the future go for Rust.

At the end of the day just choose the language that is more enjoyable for you.

[–] [email protected] 1 points 1 year ago

Sensational answer! Thank you.

[–] [email protected] 9 points 1 year ago (1 children)

I think Python is still unmatched when it comes to ML, and nothing can beat Swift in terms of Apple ecosystem support. Why not learn both, though? I find Swift a bit harder to reason with than rust, but both have merit (and both have interesting use cases). Just see what uses you will find for them as you progress.

[–] [email protected] 3 points 1 year ago (2 children)

I was working on the assumption that it would make it harder to learn two at once. Maybe you are right though.

[–] [email protected] 5 points 1 year ago* (last edited 1 year ago) (1 children)

Honestly - now that you know one language learning any new language is a pretty simple task. For example - here's a hello world in the three languages:

# Python
print("Hello, World!")

// Swift
print("Hello, World!")

// Rust
fn main() {
    println!("Hello, World!");
}

As you can see, the differences between Swift and Python are pretty minimal* and while rust adds a whole bunch of extra busywork (you need a function, you need an explanation point, you need a semicolon...) it's generally the same thing.

(*) While that comparison of Python/Swift only differs in the comments, Swift is generally a much more complex language than Python, so you will need to learn a bunch of new concepts. For example if you needed to manually specify the output string encoding you'd write the Swift hello world like this:

let string = "Hello, World!"
if let data = string.data(using: .utf16) {
    print(data)
}

There are some common Swift language patterns there that are rare in other languages:

  • if let will gracefully handle any errors that occur in the encoding step (there can't be any errors when you're using utf16 encoding, but if another encoding format was specified it might fail if, for example, you gave it an emoji.
  • Swift allows you to interleave part of your function names in between the function arguments. That's not a data() function, the function name is data(using:) and there are other function names that start with data() but accept totally different arguments, for example you might give it a URL and it would download the contents of the URL as the contents of the data.
  • the .utf16 syntax is also something I haven't seen elsewhere. The using parameter only accepts String.Encoding.something and you can shortcut that by only writing the .something part.

For completeness, in python and rust you would do:

# python
string = "Hello, World!"
utf16_data = string.encode("utf-16")
print(utf16_data)

# rust
fn main() {
    let string = "Hello, World!";
    let utf16_data: Vec< u16 > = string.encode_utf16().collect();
    println!("{:?}", utf16_data);
}

That's actually pretty good comparison of the three languages and an example of why I like Swift.

The syntax in Rust is absurdly complicated for such a simple task. And while the Python code is very simple, it doesn't handle potential encoding errors as gracefully as Swift, and it also uses a string to specify the encoding, which opens up potential mistakes if you make a simple typo an also you'll have to do a Google search to check - is it "utf-16" or "utf16"? With Swift the correct encoding string will auto-complete and it will fail to compile if you make a mistake.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (2 children)

Python actually isn't my first language, just my current choice. I've programmed in Basic, Pascal, Fortran, PL-SQL, Prolog and C at various times in the past. My question was more about which is likely to scale over time to be the more popular ML language.

Python also sucks for MacOS gui apps, so I was contemplating building MacOS/iOs apps for myself as a side quest.

[–] [email protected] 3 points 1 year ago

Purely from the standpoint of making GUI apps in macOS/iOS, Swift is almost certainly the best choice. All of Apple’s UI frameworks are written in Swift (technically often Objective-C, but with Swift in mind), and designed to be used from Swift. It’s kind of possible to do this in C++ using Objective-C++, but nearly all of the UI code is going to be Objective-C anyways (Objective-C is the language that used to be the default on Apple platforms, but was replaced by Swift). It’s also certainly possible to use libraries for other languages that wrap this functionality, but these often can be missing features and/or be harder to work with. Additionally when looking for help, you’re likely to find much more support out there for the native frameworks since that’s what most people are using.

[–] [email protected] 1 points 1 year ago

OK - well at the end of the day the right approach is to have a problem you're trying to achieve and pick the best language for that (wether you know the language or not).

If it's MacOS/iOS apps, then definitely don't choose Rust. But reconsider that choice for your next project.

Also, with modern large language models, it's even easier to work with an unfamiliar language. And honestly it wasn't ever all that difficult.

[–] [email protected] 3 points 1 year ago (1 children)

The tricky part isn’t the syntax, it's the domain knowledge. Well, actually it's syntax, too. Swift has a whole lot of things that aren’t like anything else with sprinkles of Objective-C. Rust turns the common patterns upside down because they make borrow checker sad. But, in the end, what makes you a good engineer is knowing how to apply the tool to solve the problem and that goes well beyond syntax.

Programming languages are like different kinds of saws: all of them are made to cut things, but there are nuances. Some are replaceable, others can be used for one specific thing. Knowing how to operate a hacksaw gives you some idea how a chainsaw would work even though they are fundamentally different. But tinkle it this way: what are you trying to do? Answering that will tell you which saw you need to use.

[–] [email protected] 1 points 1 year ago (1 children)

I'm trying to work out which one will have better for ML in a couple of years time.

[–] [email protected] 3 points 1 year ago (1 children)

I don’think rust has any specific features that target ML. Swift does, but it's Apple hardware only.

[–] [email protected] 2 points 1 year ago (2 children)

One of the things that I'm struggling with on Python is the very poor support for AMD GPU's, which are in Macs. I'm sure Swift will do a better job of using the hardware capabilities better.

[–] [email protected] 2 points 1 year ago

Only old Macs have AMD GPUs.

[–] [email protected] 1 points 1 year ago

If you’re looking for the best utilization of your hardware, I wouldn’t be surprised if Apple’s ML frameworks were best. Since Apple has a small set of hardware, they can write software that takes advantage of it better. Consider looking into Core ML which is by Apple and for Swift. Of course this will only work for Apple hardware, but if this is just for personal interest/hobby then that doesn’t really matter.

[–] [email protected] 8 points 1 year ago (1 children)

If you're trying to prepare for a couple of years in advance, it might be worth spending a day playing with each language just to see which one feels best to you. Both languages should be able to do anything you want but some things will probably be more difficult in one or the other. I've never used swift, but I know rust can have a rather steep learning curve. That may be deterrent enough for some people, but that's up to you to decide if that struggle is worth it.

[–] [email protected] 3 points 1 year ago (1 children)

Thanks, this makes some sense. I've started a few tutorials for Swift, and I added the Rust plugin/module to Visual Studio Code, but neither felt intuitive to me.

load more comments (1 replies)
[–] [email protected] 4 points 1 year ago

If you don't have a Mac I don't think you can get the MacOS SDK.

So in that case I'd recommend Rust. I still think most of Rust's tools/frameworks need more time in the oven but Rust is massive and has tools being built for everything. If you want Mobile I'd recommend you take a look at Dioxus or Tauri. There are probably others as well but I don't know them it's been a while since I've looked.

[–] [email protected] 3 points 1 year ago (1 children)
[–] [email protected] 3 points 1 year ago

Lol, Turbo Pascal was the first OO language I learned, back before there was any such thing as an Internet.. Showing my age now.

[–] [email protected] 3 points 1 year ago (1 children)

@Bluetreefrog
I, like you, code for myself not others and not professionally. Take a dive into Xcode and Swift if you're in the Apple world. It is just stupid easy to throw together an app or tool in no time at all.

[–] [email protected] 1 points 1 year ago

Have you played with the Swift ML frameworks at all?

[–] ericjmorey 2 points 1 year ago (1 children)
[–] [email protected] 1 points 1 year ago (2 children)

I have thought about Julia.

load more comments (2 replies)
[–] [email protected] 1 points 1 year ago (1 children)

Something to consider as well is learning both. Swift is certainly the best choice for making macOS/iOS GUIs. Other languages are probably better than Swift for your ML needs (could be rust, Python, etc.). However it’s totally possible to have an app using multiple languages. You could have the UI portion be in Swift, but the ML portions be in another language.

At my company we have a Mac app with the GUI written in Swift, shared logic with our Windows app written in C++, and some libraries written in Rust. So it’s certainly possible.

One caveat is that some languages don’t work with each other very well. Swift and Python do work well together iirc, so doing UI code in Swift and ML code in Python may not be a bad idea.

If you want to just stick to Swift, Apple does have some ML frameworks for Swift that you can use. I don’t do any work with ML, so I have no idea if these frameworks are any good, or have good resources for learning.

If you want to just stick with whatever language you use for ML, there are GUI libraries in nearly every language. These certainly won’t be as robust or as nice to work with as the native frameworks in Swift, but they could probably get the job done. I do know that a major issue with GUIs in Python is the difficulty in multi threading, which is a must for any app that performs long tasks without the UI freezing.

load more comments (1 replies)
load more comments
view more: next ›