I'm learning Rust so I can move away from C#

So, I've been learning Rust recently. It's been a huge breath of fresh air for me. It's basically everything I've ever wanted in a community and programming language.. But wait, C# is pretty cool too... Well, let's take a step into why I find Rust to be so refreshing, despite me loving C#.

Linux as a first class citizen

Rust is supported on Linux as a first class citizen. This is in stark difference to .NET, where Mono seems to be the red headed step child. I love Mono. This website is running Mono. No matter how awesome Mono is though, it can never shake off the fact that .NET and C# is primarily driven by Microsoft, who would be glad if every copy of the source code of Linux was lost.

Xamarin is now the official steward of Mono. They seem to be much more focused on ensuring that their proprietary Mono support on Android and iOS continues to be awesome (which it is). It seems like the only advancement to Mono happens only because it happens to work on every platform.

Rust has financial backing from Mozilla. Mozilla has always struck me as one of those "good" companies. Some people would say this about Google, but I don't think making people into ads without consent is not evil. Mozilla has always been good about open sourcing nearly everything they do. And they do it under permissive licenses! The whole of Rust is under Apache/MIT license. Meanwhile, Microsoft is busy making sure that their licenses say can't be "run on a platform other than the Windows platform;"

Open Design. Open Community.

I joined the #rust IRC channel. I was quite shocked at how active it was. And how much discussion about the direction of the language itself happens on there. Again, this is the exact opposite of .NET and C#. Basically what happens with C# is Microsoft goes behind closed doors, tries to find things that need to be easier, and then when the next version of Visual Studio is due to come out, unleashes these changes on us. If we don't like the changes, that's too bad. Now, honestly, I must say that most of these changes are not necessarily bad. It's more the principal of the matter. It's like if C# was your wife (or husband) and your family had saved up money for three years to get a new car, and then C# went shopping with her ex from high school (Microsoft) and brought home a scooter and a gas guzzling Hummer. It's not that either one aren't useful in some circumstances, but that money (ie, time) could've been better used on something else.

And that's not even to mention the fact that Microsoft decided to send home with C# a mutt dog that shits on everything(ie, WinRT support in .NET). I for one do not like the direction Microsoft is taking .NET. In fact, with WinRT it looks like the Windows division had a secret plan to try to make .NET suck as much as possible. Obviously they want us to all be using C++, because all their advancement happened there.. oh and now C# can interface to C++ code easier... so you can port your existing C# code to C++. It seems like Microsoft is actively trying to prevent me from writing for their platform even. Sometimes I think they'd be happier if all the developers just went away and let them focus on making Word suck more.

Now, this rant has a point. Rust isn't like this. If I don't like a feature, I can talk about it in IRC.. and here is the amazing part, people will actually listen. Sure, the writers of C# and such hang out on Stackoverflow and answer design questions and such, but it's not like Microsoft is asking the community "well, what do you want?".. because if they had, then WPF probably wouldn't be dead in the water. But I digress.

Most of the stuff Microsoft develops that is open source, they don't really accept contributions to either. Recently (last year) they finally started accepting pull requests and doing development openly in ASP.NET MVC though. So, they're starting to move toward the right direction, but I won't be happy until .NET framework is completely open source.

Embrace the magic. Screw the magic.

There are two kinds of developers. The ones that prefer magic, and the ones that don't. I explicitly abhor magic in most cases. This is why I don't use ASP.NET MVC. Magic is the life blood of it!

Now, what do I consider magic?

  1. Strings that somehow get translated to significant method or type names at runtime
  2. Using reflection to call certain hard-coded method names (that aren't part of an interface)
  3. Using attributes to define essential behavior.

I can hear the yells now. "Convention over configuration!" No, fuck your conventions. I want compiler errors, not runtime or logic errors.

Example, here is how to configure a route in ASP.NET MVC:

routes.MapRoute(
  "Default", // Route name
  "{controller}/{action}/{id}", // URL with parameters
  new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

Hmm, let's count the number of ways we could mess this up. Well, we might screw up the super magic names of "Home" or "Index". I think that the anonymous object's fields of controller and action are also significant. I don't know ASP.NET MVC. Personally, with something like intellisense at Microsoft's disposal, I don't understand why they chose such a dynamically typed way of doing this.

Magic isn't as bad in dynamically typed languages at least, because magic doesn't make you lose as much as in a statically typed language. This is why I'm not going to mention something like Ruby. I actually enjoy writing Ruby. When they do magic, I'm not losing the entire benefit of using a compiled and statically typed language. Instead, I'm just losing an easy understanding of how things work.

Rust, on the other hand, is designed from the very start that compiler errors should be given for everything that is probably wrong. They have an enormous focus on compile-time safety. They track your pointers and ensure a null pointer will never happen. Sometimes things are impossible to represent in this safe environment, so they also provide the unsafe keyword. The whole community seems to be chanting "compiler errors, not runtime errors". And for good reason. Compilers are powerful tools! They should verify that code will do what it is suppose to, not just spit out machine code

Just use Visual Studio. Oh, you're on Linux?

C# was never designed to be written outside of Visual Studio. With it's long names, magical code generation (in some projects), and official tool support for only MSBuild, it makes a lot of assumptions. This would be fine if Visual Studio worked on Linux, but it doesn't. The only choice for Linux is Xamarin Studio, or some crufty combination of Makefiles, MSBuild(for interop with Visual Studio), and a bit of insanity. And if you've never had the pleasure of using Xamarin Studio, let me just tell you first hand. IT SUCKS. It can get you through in a pinch, but in general, it sucks really bad. Apparently it doesn't use MSBuild natively, which causes interesting behavior sometimes. The UI doesn't obey themes properly, leading to a very ugly editor in my case. VI-mode is a running joke; and finally, it's #1 feature is that restarting it will fx it when it freezes.

Well, Xamarin is maintaining it, maybe it works better for their official platforms (Windows or Mac OSX).. erhm.. no, it doesn't. It sucks equally as bad there. The strange thing is that when it was MonoDevelop, it didn't suck quite as bad. I mean, the UI was a bit uglier (but did work properly with themes), it didn't support the new stuff like portable class libraries, and it was still pretty bad.. but I actually did not mind using it exclusively. It usually was good enough for me to not constantly be annoyed. Xamarin changing it into XamarinStudio was the worst thing that ever happened to it.

Rust, on the other hand, does not have an ulterior motive to drive the sales of a text editor. It's very easy to type, and very easy to use with many tools. I'm not going to say makefiles are perfect, but at least they work everywhere. Rust seems to follows the C style convention of keep names as short as possibly readable. (but you won't see names like atoi in rust, because the designers aren't Satan). I've been using Kate (due to it's awesome vi-mode) for Rust development. I constantly have to look at references because I'm still learning, but in general you seem to type less than C#. I do miss intellisense, though. It's a very useful feature when you're discovering methods and such of an object.

It's like C, except it's from this decade

Honestly, I've never had a big problem with writing C. I love the simplicity and the pure understanding I can have of the code I write. Also, it's nice to see a Linux-first platform. But I can't stand the cruft of actually trying to get things done in C. Function prototypes, preprocessor includes, no assistance with memory management... ugh. This is what makes Rust so awesome. It's like C, except for with all the cruft fixed, and with a few other awesome things added like closures and green threads. You can even use rust to write an OS kernel with just a bit of added assembly. Try doing that with C#..

Other languages?

To be fair, I did look at other languages. Some of these languages looked cool, but just didn't quite mesh with me like Rust did.

  • Go -- lacks generics and I don't enjoy some of the design decisions
  • Crystal-lang -- I actually looked at this and wanted to use it, but I couldn't get it to work and the community seemed rather lack luster.. and the language/compiler lacks an open source license
  • Something crazy and functional -- I've tried some functional languages.. they're pretty cool, but just not what I wanted right now

My dream of a language almost perfectly coincides with Rust

  • Compiles to native (no runtime)
  • Compiler errors, not runtime errors
  • Strong type system with duck typing
  • Has a strong generic type system
  • Generally embraces my "no magic" life style
  • Linux as a first class citizen
  • Could semi-easily replace C as a systems language

As you can see, Rust fits the bill pretty well. It's not perfect, no language is.. but it's the best I've seen yet

What now?

Well, I'm going to continue learning and using Rust. And I'll continue using C#, because it's what brings home the bacon.. but all of my open source effort will be toward Rust. Rust has a community I believe in and their ideals are something I can agree with. Some people like magic mixed with their static typing, and that's ok. Some people don't care at all about Linux support, and that's ok. I'll be over here though, using Rust, chanting "compiler errors not runtime errors" and using Kate on Arch Linux :)

So far, I'm working on learning Rust by trying to write something like my LucidMVC project, but in Rust, dubbed RustyMVC.

Posted: 10/12/2013 6:12:17 PM

Comments

Joey Ezechiels
I already considered Rust an interesting language, but your blog has convinced me that Rust should be the next language I learn.
10/12/2013 9:41:49 PM
asterite
Hi there from Crystal :-)

We're sorry you couldn't get it to work. What problem did you encounter? We can help you make it work.

About the license: we are still thinking which license to use, that's why we never replied to you. Please understand that the language is still very young, we are very few in the team and we do it in our free time.
10/13/2013 4:42:07 AM
Earlz
@asterite, the problem I encountered was I couldn't get sockets to work, despite everything looking right in the socket's source code. I understand that the language is extremely young, and that's another reason why it's not quite for me. I don't mind bleeding edge, but I need to actually be able to get stuff done as well. 

As for the license, it will prevent anyone in the future from contributing to your project until you get that sorted out. 
10/13/2013 6:30:16 PM
James Dunne
Rust is a first class citizen on Linux but currently a third class citizen on Windows, where I would love to use it for a few projects that otherwise could not be done on Linux due to hardware support issues.
10/14/2013 3:37:50 PM
Earlz
Well, usually it's very hard to have really good support on all 3 platforms. I haven't tried it, but it looks like it should work with a little bit of setup with MingW
10/14/2013 7:24:54 PM
Paolo
I like and agree on most of the things you wrote. I feel the part on MVC routes, though, is a little ungenerous for .NET. As much as I like compile-time guarantees, I don't think any language can provide more compile-time checks to routing than MVC does. 
Routes are trying to map a command that comes directly from users (in the form of a URL) to the piece of code that should be run by the server to build a response to that command. I can't really see a way to do this which does not involve some form of runtime interpretation of a string. 
I don't think rust (which is admittedly not even being built with web frameworks in mind, so we may never know....) would be able to solve this problem in a way that does not involve some sort of runtime "magic"
10/15/2013 3:37:58 PM
Earlz
I think I can see what you're saying. You can have convention, or configuration, not both. If you want to have compile-time checks that your routes will always match up (or else yield 404), you'll have to specify more information about the route than "/{controller}/{action}..." you'll have to specify what controllers are valid in what context and what actions are valid on that controller. 
10/15/2013 4:33:50 PM
Anonymous
@Earlz: Even if you did that, you would still only be able to check for that validity at runtime. 
My point is that a URL is a form of user input, as it comes from the user while your application is running. It's IO. And IO is where every language's static type-checking guarantees break down a little. Even Haskell, which is quite big on types and (I understand) one of the sources of inspiration for rust.
Convention and configuration are an orthogonal problem to compile-time and runtime checks (unless I misunderstand what you mean). 
10/15/2013 4:50:29 PM
MFlamer
I agree with you regarding Rust as an excellent language. I also have found Nimrod to be as good or better for the same reasons. I encourage you to investigate it also. http://nimrod-code.org/
10/17/2013 12:10:02 AM
brianoh
I've just started looking at Rust. I have to ask myself continually "why look at it?". Off-the-cuff: 1 speed. 2 parallelism. 3 (from what I read) safety. 4 curiosity. 5 : it's different but doesn't use "magic".

I'm non-religious about languages, but one thing I do find rather grating with is the use of "let" instead of "var" for variable declaration in Rust.  I know - "what's in a name?", well, a lot, and there has to be a reason for every small design decision - which there probably is, and it is cast in stone now.

It's difficult to compare languages because there are differing reasons for particular use of syntax, and familiarity can have appeal. I do however find Dart's variable declaration syntax extremely non-verbose - "int iVal", "String sVal", however it's a very different language with different design-goals to both Go and Rust. I guess Go and Rust are more comparable. Go (to me) is far more simple to learn than Rust. So, I hope that Rust offers more other than being a bit faster (it appears).
10/23/2013 3:23:32 AM
Earlz
I would say Go and Rust are comparable, but not necessarily for the same subset of audience. Go has garbage collection and Rust, mostly, doesn't. This causes a huge change in the design of the language. I think the cool thing about Rust is how much it can handle without ever actually needing garbage collection. Before looking at it, I wouldn't have thought such a language to be possible without GC. In the future, I can see Rust being ported to embedded platforms as well, where I think it will especially shine. Rust not needing garbage collection means that it can have an extremely thin runtime
10/23/2013 1:58:16 PM
Anonymous
@brianoh, let instead of var is so utterly trivial it's not even worth mentioning. People who talk about points like this as if they matter strike me as people who barely know what they're doing and are probably JavaScript idiots with 6 months of experience.
1/16/2014 2:04:45 AM

Posting comments is currently disabled(probably due to spam)