5 ms·
At some point you gotta ask yourself: Why am I still writing Python then, if I want to write Rust? If I want Rust's safety, why not write Rust then, with battle
by zelphirkalt 3y ago
At some point you gotta ask yourself: Why am I still writing Python then, if I want to write Rust? If I want Rust's safety, why not write Rust then, with battle proven tools and better type system from the start?
Often the answer to this question unfortunately is not a technological merit, but knowledge of a team and willingness to learn. You might want to write actual Rust code and there can be any number of benefits, but if your team does not want to learn Rust, you got a problem and cannot move on.
Here it becomes visible, how important it is to learn multiple programming languages. It makes teams flexible and allows choosing technologically better solutions, instead of having to shoehorn things into that one language the team knows. Programming languages matter. Each has its strong areas and flaws. Some languages allow you to change the language itself, to extend what you can do with them comfortably and safely.
All this is assuming of course, that you will have suitable replacements for any libraries you need. Such replacements can including writing some code oneself, using the language's facilities.
For example, if the language is powerful enough or includes the right batteries for it, you can easily write a little parser for a file format yourself using a grammar that is available in some standard. But keep maintainance in mind. If the file format is still developing, you might not want to do this.
Something that in one language might be an external dependency, a library, can in another language be a concise self-written code, that one can look at and quickly understand.
- eska 3y agoIn my case I write Python like this because the colleagues who are using my software are hardcore engineers but only intermediate or beginner programmers. Well-designed APIs with IDE support and safe patterns protect them from a lot of potential mistakes they didn’t know they could make. I won’t be able to ask them to learn Rust out of time constraints.
- orthoxerox 3y ago> At some point you gotta ask yourself: Why am I still writing Python then, if I want to write Rust? If I want Rust's safety, why not write Rust then, with battle proven tools and better type system from the start? Garbage collection
- zelphirkalt 3y agoTo what end? I think avoiding manual memory management is great, but I never had issues in Rust either, since I don't manage memory manually there either. I think that is kind of a point of Rust, as it avoids that whole class of bugs common in C programs. But to what end do you want garbage collection (GC)? Just for having GC? Or a more specific purpose, that is difficult to attain with Rust's model? For example: I usually want tail call optimization in languages I use. But not for it in itself, but for being able to write functions nicely, not having to worry about recursion depth, expressing things more declaratively, avoiding mutation (at least of an explicitly managed stack or any loop variable) and probably other things that don't come to mind right now.
- jeremyjh 3y agoGC is nice because you don’t have to constantly think about ownership and lifetimes.
- earthling8118 3y agoThe amount of time spent worrying about this is vastly overestimated. You don't really have to worry about lifetimes in your common day to day coding unless you're doing some seriously performant or low level stuff. At which point you probably don't want a GC anyway.
- jeremyjh 3y agoI’ve written a fair bit of Rust but it was ~5 years ago. I understand some ergonomics have improved but I think this somewhat depends on the type of application you are developing.
- orthoxerox 3y agoJust for having GC. When I'm writing Python, I am fine with not saving every CPU cycle and every byte of RAM, but having types saves my productivity.
- 3y ago
- d0mine 3y agoBecause Python enables faster iterations. By the time you manage to produce a Rust program that even compiles, you can do several edits with tests in Python.
- wtetzner 3y agoThat's only until you've grokked Rust. I find iterating in Rust to be faster than Python.
- ReflectedImage 3y agoIterating in Python is always faster than iterating in Rust. If you do indeed find what you are saying then you simply speaking aren't able to write Python code.
- wtetzner 3y agoNo, because to iterate in Python, you have run the program and get it into the right state. For many things in Rust, I can just use `cargo check`.
- ReflectedImage 3y agoFrom that statement, I'm not convinced you know Python nor Rust. I'm going to suggest you read the following: https://docs.pytest.org/en/7.3.x/ https://docs.pytest.org/en/7.3.x/ https://doc.rust-lang.org/rust-by-example/testing/unit_testing.html https://doc.rust-lang.org/rust-by-example/testing/unit_testi...
- wtetzner 3y agoAre you saying the only quick way to iterate is unit testing? My point is that there's a whole class of things that require unit testing in Python that are just automatically caught in Rust. If you don't know Rust well, it's going to be slow going. If you've internalized the way it works, it can be very fast to iterate. Especially when you learn to start structuring types in such a way that bad states aren't even representable. You can often make it impossible to construct inputs that would require debugging in Python. > From that statement, I'm not convinced you know Python nor Rust. Thanks for the personal attack. I use both Rust and Python regularly at work, and write tests for both. Working on the Rust code base is pretty much always faster, because so many things are caught in advance. Yes, unit tests are still needed, but not for as many things. Learning to use the type system to your advantage, instead of treating it as an obstacle, can really speed things up.
- dehrmann 3y agoIf you're scaling Python to the point where you need everything fully-typed, your next stop shouldn't be Rust, it should be something like Java or C#. You just don't need Rust's memory semantics, and the GC will be good enough.
- __MatrixMan__ 3y agoYou're absolutely right that: > Often the answer to this question unfortunately is not a technological merit, but knowledge of a team and willingness to learn. And for the software engineer, this is also true: > [it is] important ... to learn multiple programming languages But I don't think the majority of python users are software engineers. They're data analysts, they're scientists, they're students. They'll never face a choice between Python and Rust, let's just be happy they chose Python over Matlab or Excel. And with that in mind, writing Rust-shaped python so we can interoperate with our less-softwarey-brethren--while not the nirvana that we crave--is not a bad compromise.
- digdugdirk 3y ago100% this. As one of those people graduating from "Maker of Excel-abominations", I absolutely love that python can shape itself to my learning curve, while being useful the whole way through. Articles like this expose people like me to concepts of typing that I never would get otherwise, and by practicing the concepts in python I might eventually be able to make the leap.
- ReflectedImage 3y agoPlease don't. This is about people trying to use the wrong typing system "static typing" in a language that already has a better typing system "dynamic typing". This is about bad programmers who have come from Java and want all other programming languages to look like Java.
- steve_gh 3y agoNot better. Different. Languages make different choices to suit different domains, and with perfectly good reasons. Don't complain, embrace the richness and diversity of programming languages. And choose the right one for each task.
- ReflectedImage 3y agoIt's better in the context of a programming language designed to use it.