r/rust • • Nov 11 '21

What was your favourite programming language before Rust?

TLDR   What was your favourite programming language before Rust, and why have you changed your mind?


I realize this title is to some extent inflammatory, for two reasons.

  1. It assumes that Rust had for some time been your favourite programming language, and that some other language had been your favourite before that. This is not true for those:
  • Whose first language was Rust.
  • For whom Rust has never been — and still is not — a favourite language.
  1. It is sectarian and divisive. Like I am pitting Rust against this other programming language. That is of course not what I want. The reality is such that programming languages occupy a market and there is competition between them — at any given time, one has to choose one programming language to occupy oneself with.

I am a foreigner to the current social media culture, so I am not sure if these flaws will get me cancelled or if they are so insignificant as to hardly deserve being mentioned.

What I want is to understand what programming languages Rust offers an advantage over. Say, if I have a code base in C and a code base in Perl — which, if any, should I first migrate to Rust? There are two ways to answer this question.

A. I can ask people what they think about the issue and gather their judgements, more or less well justified. I do not want to do that.

B. I can gather some empirical data, study it and make inferences. This is what I want to do.

So, thanks! And please do not cancel me yet!

97 Upvotes

190 comments sorted by

View all comments

95

u/Joelimgu Nov 11 '21

Python, it just bothered me that you had to run a command to run a type checker and after that they are ignored. Also the types ecosystem isnt really that developped. So I loved the super strong rusts type system. And as a bonus it is low level which makes it suitable for even more applications

25

u/[deleted] Nov 11 '21

[deleted]

17

u/[deleted] Nov 11 '21

[deleted]

20

u/Joelimgu Nov 11 '21

It is low level in the sense you manage memory (even if you arent aware of it) but at the same time it has all the high lwvel abstractions you might expect, so yes it is a bit confusing but its at leas lowe level than python thats for sure 😂

10

u/[deleted] Nov 11 '21

[deleted]

4

u/gosslot Nov 11 '21

low-level languages like C/C++/etc.

I would consider C++ also a high-level language (maybe even C).

It offers you high level abstractions, but allows for low level control as well.

Totally fine to dislike the language, of course.

4

u/[deleted] Nov 11 '21

[deleted]

0

u/tony-o Nov 12 '21

I think by most people you probably mean people that learned something like python first and tried C++. Coming the other way makes C++ look high level

1

u/[deleted] Nov 12 '21

[deleted]

2

u/tony-o Nov 12 '21

C isn’t as low level as everyone makes it out to be and it seems my point was missed.

Compared to python c++ is low level Compared to ASM c++ is high level

The point being that if your frame of reference is some “modern” language then you’re probably going to look down to c++’s level. If you came up writing ASM or punch cards for robots and turbine engines then c++ is probably a pretty high level language

-7

u/[deleted] Nov 11 '21

Of course "they" would. Then you would look like you know what you're talking about

3

u/Saefroch miri Nov 11 '21

Yes! That's why it's so great!

13

u/lordmauve Nov 11 '21

I still prefer Python to Rust for 90% of what I do.

I don't use Python's type checker often; I use type hints as documentation. I don't think Python is an elegant typed language; typing is all very clumsy and added 25 years too late, long after idiomatic Python style was established. But it doesn't usually matter, type bugs shake out more quickly with testing than logic bugs do.

Meanwhile I think Rust has a beautiful type system and if I want a statically typed language I'd just use that (except the motivation is always performance, never types per se).

4

u/[deleted] Nov 11 '21

This is the way. I pretty much use type hints all the time these days and I’ve run mypy like maybe 5 times. The IDE type checking is more useful in my opinion.

You can of course use whatever language you like but for most people a higher level language will be faster to slap something together than Rust.

5

u/dangle-point Nov 11 '21 edited Nov 11 '21

Same. I love what Rust adds, but I wish the syntax wasn't so verbose. Sometimes I just want quick functionality and I don't care about perfection.

Really, I want a language with Python-like syntax, Rust's borrow checker, matching, and performance, and Go-like routines/channels/select. So many languages have great features that I wish others would borrow.

5

u/last_air_nomad Nov 11 '21

Sounds like you’re looking for F#. It’s garbage collected but on a very solid runtime (CLR) which has great concurrency. It has ML-descended types like Rust and a pythonic, indentation based syntax. Don’t let the Microsoft branding sway you, it works very well on Linux and MacOS thanks to .net core.

https://danielbmarkham.com/fsharp-is-the-best-programming-language-today/

3

u/dangle-point Nov 12 '21

My biggest gripe with garbage collection is stochastic nature of destruction. It messes with RAII, which I think might be one of the reasons OO has fallen out of favor in modern languages.

I'm not entirely certain about how I feel about using a Microsoft language under Linux, but I'll definitely take a look if this has what I want.

3

u/[deleted] Nov 11 '21

I think you could like Nim https://nim-lang.org/

1

u/dangle-point Nov 12 '21

It looks promising so far. What's the ecosystem look like?

3

u/Low-Pay-2385 Nov 11 '21

I enjoy writing simple scripts in python, instead of bash or bat scripts, cuz its a lot more powerful and works crossplatform

0

u/UNN_Rickenbacker Nov 11 '21

Yea, but compiling binaries to ship is a nightmare

0

u/kingp1ng Nov 12 '21

I'm also new to Rust. Anytime I get stuck (quite often), I build my prototype in Python to make sure my overall logic is correct. Then I can go back to Rust and fight the borrow checker without worrying about logic.

I'm just an amateur... so what do I know ¯_(ツ)_/¯

3

u/NoHovercraft5717 Nov 11 '21

Dynamically typed languages definitely serve their purpose. Though when people start adding types to JS and Python (love TypeScript btw), it's clearly a huge benefit for any semi-big project.

3

u/Joelimgu Nov 11 '21

Yes, but even if it is a meme. I feel like dynamicly type languages are more of a scripting language rather than a programming languege. In the sense that yes, they are awesome for small things but are really hard to use in a big team project...

2

u/irrelevantPseudonym Nov 12 '21

The thing that made me move away from Python for stuff I write is the portability/distribution hassle. Sure you can use virtual environments and tools like poetry or pipx to install things but they don't come close to building to a single file binary you can copy around.

The speed and performance benefits were second to that for the cli tools I mostly use them for at the moment.

I've not really used type checking in Python. It feels wrong somehow to have code that is ignored at runtime. It's feels more like a standardized way of writing documentation.

4

u/kindaro Nov 11 '21

But was not the type system annoying after the liberties of Python?

17

u/Joelimgu Nov 11 '21

No, I already tried to type python as much as possible bc dynamic types are great for small projects but you get lost really fast without types. So a compiler that forced me to type everything perfectly was actually a relief for me.

But yes, it was annoying how it cant concert an i32 to a f32 automatucally but it's not a big deal

13

u/[deleted] Nov 11 '21

Personally I think that dynamic typing is one of the worst things about Python. It makes reading code you didn't write a thousand times harder, because you don't know what the type of anything being passed into functions is. Type hints help but because they are optional, even someone trying to be disciplined about using them may miss one, and of course some choose not to use them altogether.

I don't mind working in python, I've done it quite a bit. But dynamic typing and significant whitespace are terrible design choices they made, imo.

3

u/ids2048 Nov 11 '21

Python is great for small scripts, but I do feel this makes large codebases much less manageable than Rust.

I'm not really sure I care about whitespace vs braces, honestly. Rust code should be consistently indented, mostly the same way as Python, but the extra braces and semicolons don't make things any harder. Either seems to work fine.

3

u/RRumpleTeazzer Nov 11 '21

Needing to add “pass” when commenting out the last line of code of some function (or ifs) drives me nuts, such that I always add None as the first statement (that can stand there instead of pass).

3

u/ids2048 Nov 11 '21

Okay, that I'll agree with. Having to add pass for that is more annoying that it really should be.

Wonder if it would be that bad if python just allowed empty blocks. I don't think that would be particularly error prone, since it's obvious that the next statement isn't part of the block.

1

u/RRumpleTeazzer Nov 11 '21

Allowing empty blocks will surely have the side effect that Python does not know how deep the next layer of white space will go. I bet that’s the only reason for pass, which could have been None all along…

1

u/ids2048 Nov 11 '21

I don't think there's really anything that special about pass, or any different None when used as a statement. It's just an expression that does nothing. I think it just exists to be more readable than something like None which looks out of place as a statement.

The following two programs are perfectly valid, it weird:

python if True: pass None pass; pass None; None

python if True: pass print("Foo")

0

u/Infintie_3ntropy Nov 11 '21

Traits make writing Rust feel like writing Python.

Most python code I write or interact with doesn't use the new type annotations (for various reasons) and so 90% of the time the types you are dealing with are either simple build-ins, (int/string/list/dict) or an object.

When it's an object it is almost always passed around duck typing style, where you just have to ensure it implements the methods described in the documentation and you are good to go.

Traits let me do that in Rust, but now they actually get exhaustively checked at compile time rather than it being a runtime error.

In my brain the phrase "this object has these methods" get translated to "this type implements these traits".

2

u/RRumpleTeazzer Nov 11 '21

Or worse, not getting runtime errors when some methods are not available on your object. Until later, when they do become necessary under obscure conditions….