Picking Up A Second Language: Swift To Python

Why Python and what it’s been like

Phil Andrews
4 min readJun 30, 2016

Swift was a great way to get things started. I had never written a single line of code. A complete programming beginner, it took 13 months to design, self-teach, code, recode, and then launch my first full application. I’m incredibly proud of it, it’s a novel game that people play every day. Aside from keeping it up-to-date and rolling out new features, mission complete.

Credit: Stefan Pohl

There’s this thing now though. Once I became engrained with thinking in code, all the possibilities of what I can do with the skill became glaringly apparent. That being the case, the issues with only knowing Swift were also becoming glaringly apparent. As much as I like the Apple ecosystem, I can only reach 50% of mobile users and less than 4% of desktop users by writing Swift code.

The next software I wanted to write was desktop software. These are programs I’m primarily building for myself but there are plenty of other people who could benefit from them. If I write them in Swift, I can only reach 4% of users. If I write them in Python I can reach virtually everyone.

Why Python?
  • I can reach a much larger user base.
  • There are tools that are available in Python that might never be available in Swift. For me that library was Tensorflow.
  • There are a ton of stable frameworks available.
  • I can write Python for desktop, web, or even mobile. Not that I would write it for mobile. I probably wouldn’t but the option is there.
  • Every question you will ask has almost certainly been answered on StackOverflow already. Python tags on SO: ~596k. Swift tags on SO: ~100k
How long will it take?
  • A lot less time than it did for the first language. You’ll be able to write a basic piece of software in just a few days.
How does the syntax compare?
  • It’s very similar. Dot notation, function parameters, much of the code you write will look the same.
  • White space is how Python keeps everything in order. You won’t be using brackets to open and close functions or classes. Which means, at first, everything will look haphazard.
What have been the biggest challenges?
  • The command line. I’m not uncomfortable with the command line but Python requires some proficiency. The learning curve with it can be frustrating but it’s no different than anything else. The more you do it the easier it becomes.
  • The Python docs are not as friendly and it doesn’t come with it’s own high-powered IDE like Xcode. Most languages don’t.
  • Getting set up and used to a new IDE. PyCharm was my choice. I managed to port over most of my syntax color settings and key bindings from Xcode. This is an ongoing process.
  • If you’ve become too reliant on storyboards for UI, a new language will be that much more difficult. Storyboards can be great but I recommend doing all UI sans a few exceptionally basic things in code. It’s how the programming world does it. Check out this for working without storyboards and this for layout alignment in code.
  • The autocompletion and prediction in Xcode is incredible compared to what you’ll find in other IDE’s. I did not realize how much I rely on it until I began shopping around for others. I’m typing a lot more than I was with Swift.
Have I paused to question whether it was a good decision?
  • Yes. But for only one reason so far. The GUI capabilities are far from what you’re used to in the world of OSX and iOS. The frameworks are not as robust as you would otherwise get in AppKit or UIKit. You can still get a great GUI but it’s going to take a little something extra to give it that slick polish.
What were the other possible choices I considered for a language?
  • Java. That’s really it. There are tons of things you can do with C++ or any of the other lower level languages but the learning curve would be much steeper so I didn’t wander down that path.

The tradeoff is time. What is the opportunity cost of learning a new language verse building in what you already know?

So far the switch has been humming right along. Aside from the normal “Why won’t this work?!” moments this project is coming together piece by piece.

If you’re sitting on one language or one ecosystem that you’re comfortable with, don’t feel intimidated to learn another. It’s going to be much easier the second time around.

--

--