10 ms·
This is in tune with my own experience using Rust in production: it can stop you from doing certain classes of mistakes, but it won't stop you from doing stupid
by atoav 8y ago
This is in tune with my own experience using Rust in production: it can stop you from doing certain classes of mistakes, but it won't stop you from doing stupid things.
But the idea that I don't have to think about certain classes of problems allows me to give these stupid things more focus, which is surprisingly refreshing.
The predictable nature of Rust was so refreshing for me that I ended up using it even for smaller reusable scripts where I would happily have used Python before but soon got annoyed with obvious errors that would only show up once you run a program.
If you e.g. have a `print foo` in some obscure branch that rarely happens, that print will ruin your day if you use Python 3. If python would be a little like Rust you would get on save (or at least on compile) a hint or error, that the print should look like this: `print(foo)` for Python 3. You can be incredibly careful and rust will still catch things now and then, that would have gone unnoticed into production unless you have immense test coverage.
I like Rust for the experience I had with it. It definitly changed how I approach certain problems in a very good and productive way, even when I don't use it.
- FreeFull 8y agoPython will actually give you an error for `print foo` as soon as it parses the file. But there definitely are other scenarios where you'll only get the error in the middle of execution (such as passing the wrong type of thing as an argument to a function)
- wyldfire 8y agoAgreed but Python lazy-loads & parses files as packages are imported. By convention these are all at file scope and at the top of the files, so it's often confined to an initialization phase. But...sometimes developers use clever fallback behavior by catching ImportError. So the scenario described is possible to escape simple tests, I suppose.
- marmaduke 8y agoDoesn’t the print raise a SyntaxError not ImportError?
- wyldfire 8y agoYes, sorry if that was confusing -- perhaps I shouldn't have brought up ImportError. The point was that uncovering SyntaxError could possibly be as challenging as other feature tests. try: import collections except ImportError: # fallback impl of collections: import something_that_uses_print_statement
- js2 8y agoA linter would catch that.
- asdkhadsj 8y agoAgree completely. For a bit of my own story, a year+ ago I had the option to write a project in Rust and evaluated it vs Go. Long story short, I tried rust, and it was a massive headache and I failed. We used Go (as I had been for ~4 years). Fast forward to ~2 months ago, a work project dictated tight control over memory which, while possible in Go, had me looking at alternatives. I decided to give Rust another try. This time it wasn't just an evaluation, it was needed to work so I bought and Rust book and spent some after hours time learning/etc. This time, Rust has been an absolute joy. I have no understanding why last time was so painful, and this time it's been so amazing. Maybe it was the book[1]? Maybe it was just a 2nd round of learning based on my previous experience? Regardless, it's been great. There's just so many mental overheads like what is concurrent safe, what is non-null, etc that are just great to not think about anymore. On top of that, the formatter and LSP are just great. It highlights in my text editor (Kakoune) what variable caused an error, where it gets moved incorrectly, etc. So much just works, it's great. My only complaint these days is: 1. I find it odd that some things like slice reads can still panic by default. Yes, I can use `foo.get(1)` to avoid panics, but still - it's a bit odd to me. 2. I'm anxiously awaiting async/await. It's quite difficult to be patient. [1]: Programming Rust: Fast, Safe Systems Development
- steveklabnik 8y agoIt’s probably a combination of both things, but “I tried rust, struggled, quit, came back months or years later and now I have no idea why I thought it was so hard” is certainly a recurring pattern we’ve seen. Glad it’s working for you now!
- insulfrable 8y agoBecause people underestimate the amount of effort needed to learn a new language at first?
- steveklabnik 8y agoI'm not sure it's that simple. I've never heard anyone say this about Go, for example.
- johnisgood 8y ago> before but soon got annoyed with obvious errors that would only show up once you run a program. From what I gather you are comparing static vs dynamic typing, and I agree. I do not use Python because I prefer a subset of errors caught at compile-time. However, it is silly to make it sound like that this is somehow limited to Rust. You could just as well have used Go or OCaml and feel "refreshed" because obvious errors would have been caught at compile-time. > The predictable nature of Rust Again, given the context, it is static vs dynamic typing. This is not something limited to Rust. In case you were not talking about static typing and its pros, could you please tell me what kind of official formal proof tools exist for Rust that makes it predictable?
- c3534l 8y agoI assumed borrowing and lifetimes were part of his experience as well.
- atoav 8y agoSure, and I find both not very hard as a concept. The hard thing is not understanding the concepts but learning what this implies for your coding style, especially when you come from a garbage collected language like Python. Both concept can at times give you hard to solve tasks, but it usually is because the problem you are trying to solve is hard and you cannot just naively hack away without thinking long and hard about it. Other than that I learned liking the borrow checker and lifetimes because you will get a incredible narrow scope of which variables can matter when — which makes debugging much easier
- jhrmnn 8y agoAnd with something like Mypy, you can get most of the benefits of static typing even in Python, if you want to. But Rust has so much more to offer, such as memory ownership.
- atoav 8y agoI didn’t know mypy, but I am going to check it out, thanks!
- dtech 8y ago> If you e.g. have a `print foo` in some obscure branch that rarely happens, that print will ruin your day if you use Python 3 You can use any compiled language for that though, and even some uncompiled ones (PHP will refuse to run the file)
- londt8 8y agoI recommend using mypy for python, type safe python has came a long way. The type annotation syntax has been in the language spec for years
- GrumpyNl 8y agoEvery software allows you to do stupid things. Its your job to avoid them.
- Twirrim 8y agoUse a linter. Most IDEs will do it for you natively, and even if you're dealing with a terminal based editor like vim, it's really easy to get the output of pylint, flake8 etc. running in it. It's extremely rare I ever get a syntax error make it through to code review, let alone build/deploy.
- baroffoos 8y agoLinters catch the easy cases but when the problem spans multiple files they have no clue what is going on.
- ShinTakuya 8y agoThe mypy type linter performs type checking across files, in many cases even without explicit annotations.