Philip Andersen - Personal blog
Philip Andersen - Personal blog

Thoughts, stories and ideas; when Twitter isn't enough.

Share


Twitter


Philip Andersen - Personal blog

First steps into Swift..

I've been looking for a new programming language for some years to fill the gap in my programming spectrum that I left open when I stopped using Java and my list of reasons why has only grown ever since I focused more on Python in recent years, both good and bad.

Philip AndersenPhilip Andersen

In search for a Java replacement

I've been looking for a new programming language for some years to fill the gap in my programming spectrum that I left open when I stopped using Java and my list of reasons why has only grown ever since I focused more on Python in recent years, both good and bad.

What I am or was searching for was a language that is more modern and fast, placed somewhere in the middle-layer of performance, doesn't have to be as fast as C/C++ but way faster than Python in order to may use it for graphical computation in the future.

A while ago I started to learn C# .NET Core for a short period, however I ended up in a series of issues and workarounds because I wasn't using Windows as my primary operating system. Same issue came up when I talked to some Linux developers wanted to work and trying out Microsoft Azure Sphere (OS) which is a Linux system, but as a developer they want you to be on the Windows platform with full Visual Studio. C# do have a lot of neat features I like such as LINQ, cross-platform support in some ways and it does have good performance. But the downsides for me is something that could be fixed in the future if Microsoft really want to push Linux-development. Since then, Microsoft have pushed and opened up more of .NET and made huge improvements for Visual Studio Code on Linux (example the debugger), but it's still not on the level that I feel is required for working with Microsoft eco-system outside of Windows, but if you're on Windows and is comfortable using Visual Studio, C# isn't that bad of an idea to start developing for.

Bottlenecks of Python

As I've spent more time with Python in recent years and it's development,  I've also noticed more of the language's shortcomings. For Python, publishing and distributing software outside of Linux can be a real pain, creating Windows and MacOS executables, and now add code signing on top of it etc. It makes me feel I spend more time trying to deploy something and make sure everything is bundled than actual development time and that is an frustrating part of the process.

Code signing with Xcode

Nowadays, code signing and sandboxing has become more and more important when deploying desktop applications, especially for any kind of AppStore for both Windows and MacOS/iOS. You can do this on Python but it's a bit of a hassle and there's several workarounds. If you're on a Mac, you can use Xcode with PyInstaller to embed your Python application inside a MacOS Cocoa application. It works, but it's yet one extra step in a process that's already too long. (If you want a guide on how you can do it, there's a handy guide over at https://medium.com/python-pandemonium/embedding-a-python-application-in-macos-d866adfcaf94)

Build & Run

This is one of the biggest part I've missed from my time with other languages such as Java compare to Python. As I wrote earlier, the ease of deployment and packaging isn't there on Python natively and the Build and run button makes a huge difference in terms of productivity. With Swift and Xcode you can even run the software on the real device you want instantly and it will build it for you. I could only wish for such a thing with Python which has been an issue for a very long time.

Why Swift?

Desktop applications

One of the things I create is desktop applications with Qt. It's main strength is the look and feel like a native application and is cross-platform supported. Even how close Qt is as a cross-platform library, it's not 100% perfect, especially not now when desktop environments moving more towards having more window-decorations like GTK3 and Cocoa (Example the unified Titlebar+Toolbar) which I really like and nowadays using Qt on MacOS and Linux software makes it look a bit dated even tho it's very functional. If you're on Windows it's just fine because Windows has a huge issue with UI inconsistency and the best thing to do is just to stick with the classic UI widgets that Qt has to offer in Windows. Saying that, if you need good native cross-platform support, I still highly recommend using Qt over anything else.

The downside of eco-systems

If you look at C#, then it's very Microsoft. If you look at Swift, it's very Apple. Both languages can be used outside of their respective systems such as Linux, but that's still isn't very widespread which I think due to there's a lot more handier alternatives to use on Linux such as Python which you can easily tie it to whatever graphical interface you want to use such as Qt, Web, Curses, etc..

Right now I don't see any of the options being a superior solution, but rather adaptive solutions. A lot of startups and companies go with Javascript on the desktop, and even tho that does solve a lot of issues with eco-system and cross-platform support that exist with C#/Swift, it does instead lack features as well performance that's more natively in the other languages. Which with Javascript you can get something up and going very fast, but then as time goes on to make it feel more native, they end up re-creating a lot of OS-level functionality (some cases three times as some components is integrated completely different on Linux/Mac/Windows), and spending a lot of time with UI optimization.

Apple's hardware, the good and the bad part

One of the great things with the hardware Apple use is that you can predict and debug your software in a lot more controlled environments and use simulated hardware that's accurate which also enhances the productivity.

What we have seen recently is that all new Macbook, Macbook Air, Macbook Pro and now also the new iPad Pro only offers USB-C ports, most which has Thunderbolt support. I am predicting Apple will make USB-C a standard on their whole product line. That way it's yet another thing that's hardware predictable. The main missing piece in Apple's puzzle to create a more unified hardware for all their devices the CPU/GPU/APU.  The new hardware in the new iPad Pro has a GPU and ARM CPU that's can easily replace the Macbook and Macbook Air line-up. I predicted that Apple would give us an ARM chip in the 12" Macbook but instead they gave us a poor performance Intel chip. What I guess is that Apple has planned for ARM conversion but facing issues with compatibility with current MacOS software that breaks the X86 software. I do wonder if they will do like with the PowerPC era and provide a transition time, or do it smoothly without the users noticing with a conversion layer running the software, or requiring compatibility code like they did with the Apple watch and 64-bit. I also wouldn't be surprised if their upcoming security chip would feature a conversion layer. They already have put a lot of things to leverage the CPU onto their T2 chip.

The bad part is the same thing, the hardware. When it comes to the high-end workstation there's not much Apple offer other than the iMac that has a Xeon, similar to the old MacPro and the reality is that Xeon isn't that hip anymore. A lot of developers and creative users who use 3D modelling/animation would love if they had a option to use a 32core AMD Threadripper with 128gb ram. The second thing is that when you invest in a high-end workstation, you invest for the upcoming 5-10 years. Do you really want to invest a heck lot of money in a Xeon when the rest of the Mac line up may only run ARM?. It is said Apple will offer us a new proper Mac Pro computer in 2019, and that's just a wait and see game which is very frustrating.

A lot of people who want a high-end MacPro Tower in recent years has gone the Hackintosh-route, and I don't blame them. You can build a Hackintosh that outperforms Apple's own hardware in their own software several times over, such as Final Cut Pro. Even with a couple of more hurdles people want that fast performance because it saves so much time.

Swift is so much nicer than Obj-C

In the past Obj-C has been the main language for Mac and iOS development and it is very dated as well its syntax is very aged by todays standard. Did you know all the NS-prefixes in Obj-C stands for NextStep?.. yeah, that's just one of many indications how old of language it is at this point.

Apple announced Swift in 2014, later in 2015 they open-sourced it. Now a couple of years later, it seems Swift has become a lot more mature and an established language so why not learning it and see if I can make some good use out of it creating Mac and iOS software. If anything, creating support software tools that's better than web applications and if needed. What I'll create with it I actually don't know for now. So far I've made two iOS games within the first weekend of using it as and it's been a more fun than frustrating experience so far.

On the surface Swift looked like a C-language with its curly braces and variable declarations etc. but if you ignore then it suddenly makes things a lot more comparable with how other 'scripting' languages is written. One thing I did notice is that it isn't really focused on Object-oriented programming but rather more Protocol-oriented programming, which is something I'll look into and learn more about and how it works in Swift other than what I've learned so far.

Similarities I noticed with newer Python

Apple said they wanted to make Swift both fast but also easy to learn. So far I've only had my toes in Swift and coming from Python and I think coming from Python has made it a bit easier for me as Swift was inspired by similar languages. But I still think that for complete new developers who haven't code before, it can still face some challenging parts as with connecting all the things and how it all works together. One of the things that stood out for me who have used type hints in Python3 was that Swift did it in a similar way which also contributed to an easier transition for me because I had experience with it.

Conclusion

In the end, Swift is definitely not for everybody and depending on what audience and platform you are targeting, you should pick the one that suits your case better. One of the things that made me want to trying out swift was the new iPad Pro. I've yet to get mine as it's still has status "waiting to be shipped". My goal is to create some web apps and now some iOS apps that I can use for dashboard, server administration/monitoring and productivity. Meanwhile, I gotta learn me some more Swift.

I'm a designer and developer but also a part gamer on my spare time. I started this blog to share more of my thoughts and knowledge in a longer form format compared to Twitter.

View Comments