45

On Learning Rust and Go: Migrating Away from Python

 5 years ago
source link: https://www.tuicool.com/articles/hit/YJ3IFnz
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

I first started using Python in 1993. It's been my main programming language since about 2000. I've written a ton of code in Python, both for work and in my free time. For several years now, I've been growing dissatisfied with it. Partly it's because I'd like more help from my programming tools, such as static type checking, better handling of abstractions and code modules, and in general aiding me in writing larger, more complex software. Partly it's because I'm writing more challenging software, and trying to get more out of the hardware I have available. Partly it's because I'm not getting the feeling that the Python community is going in a direction I want to follow. Instead I get the feeling that the Python community is happy to cut corners and compromise on things that I'm not willing to. Which is fine, if it makes their lives better, but leaves me wanting something else.

I wrote Obnam, my backup application, in Python, over a period of about fourteen years, until I retired it a year ago. During Obnam's life, Python 3 happened. Python 3 is actually a good thing, I think, but the transition was painful, and Obnam never made it. Obnam had other issues, which made it less fun to work on; Python 3 wasn't what killed it.

Obnam and other large programs I've written in Python gave me the strong feeling that it's a nice language up to a certain size and complexity of program. Obnam is about 15000 lines of Python code. That turned out to be too much for me in Python: too often there were bugs that a static, strong type system would have caught. I could perhaps have been more diligent in how I used Python, and more careful in how I structured my code, but that's my point: a language like Python requires so much self-discipline that at some point it gets too much.

So over the last few months I've been learning Rust and Go, on and off, in short gaps of free time between other duties. Both have static type systems that can be argued to be strong. Both seem to have decent module systems. Both seem to support concurrency well. Either should be a good replacement for Python for non-small software I write. But I expect to be using Rust for any non-work programming and Go only when work needs me to.

Rust is developed by a community, and was started by Mozilla. Go development seems to be de facto controlled by Google, who originated the language. I'd rather bet my non-work future on a language that isn't controlled by a huge corporation, especially one of the main players in today's surveillance economy. I write code in my free time because it's fun, and I release it as free software because that's the ethical thing to do. I feel quite strongly that software freedom is one of the corner stones for the long-term happiness for humanity.

Anyway.

Ignoring ethical concerns, Rust seems like the better language of the two, so far. It has the better type system, the better compiler, the better tooling in general, and seems to me to have learnt better the lessons of programming languages and tools of the past third of a century. Rust exhibits better taste: things are designed the way they are for good reasons. It's not always as convenient or familiar as Go, but it doesn't seem to make compromises for short-term convenience the way Go does.

Note that I've not written any significant code in either language, so I'm just writing based on what I've learnt by reading. My opinions may change in the future, as I get more into both languages.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK