this post was submitted on 27 Aug 2023
54 points (92.2% liked)
Programming
17503 readers
8 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
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I was working on the assumption that it would make it harder to learn two at once. Maybe you are right though.
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:
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:
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.data()
function, the function name isdata(using:)
and there are other function names that start withdata()
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..utf16
syntax is also something I haven't seen elsewhere. Theusing
parameter only acceptsString.Encoding.something
and you can shortcut that by only writing the.something
part.For completeness, in python and rust you would do:
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.
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.
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.
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.
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.
I'm trying to work out which one will have better for ML in a couple of years time.
I don’think rust has any specific features that target ML. Swift does, but it's Apple hardware only.
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.
Only old Macs have AMD GPUs.
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.