39 ms·
> Fetishization of Efficient Memory Representation: ... I don't understand what the point is here. Some people care about avoiding heap allocations? They're a t
by s17n 2y ago
> Fetishization of Efficient Memory Representation: ... I don't understand what the point is here. Some people care about avoiding heap allocations? They're a tool just like anything else
The point is that dealing with the Rust borrow checker is a huge pain in the ass and for most Rust applications you would have been better off just using a garbage collected language.
- jkelleyrtp 2y agoI mean, maybe? If you come into Rust thinking you're going to write doubly-linked lists all day and want to structure everything like that, you're going to have a bad time. But then in python you run into stuff like: ``` def func(list = []): list.append(1) ``` and list is actually a singleton. You want to pull your hair out since this is practically impossible to hunt down in a big codebase. Rust is just different, and instead of writing double-pointer code, you just use flat structures, `Copy` keys, and `loop {}` and move on with your life.
- fiedzia 2y ago> this is practically impossible to hunt down in a big codebase use linters, they keep getting smarter
- n_plus_1_acc 2y agorustc is a good smart linter
- junon 2y agoAnd if you're really wanting to be stringent, clippy exists for more subjective or more expensive lints. And it's also very good.
- Izkata 2y agoFYI this site doesn't use ``` for code blocks, it uses indentation (two spaces). https://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc
- mewpmewp2 2y agoA bit off topic, but how do people usually write code here or on Reddit, I always find it to be really cumbersome to make sure there's two spaces etc in front of everything? Is there some formatting tool that I'm not aware of that everyone else uses? Because in both forums I keep coming back to edits, and it takes forever to edit some of the things, manually. I feel like I'm being stupid or the UX of all of that is just so terrible.
- satvikpendem 2y agoI actually use a formatting tool online if on mobile, or just vim if on the computer, which can add two spaces in front of every line.
- Izkata 2y ago> or just vim if on the computer I use Firefox + Tridactyl + the native extension, so with the cursor in any text field I can hit Ctrl+i and it pops up a gvim window with the contents of that text field. When you save+quit, it copies the contents back into the field. So glad someone figured out how to do this again once Vimperator died.
- steveklabnik 2y agoI write it in play.rust-lang.org, then indent using the vim keybindings. I do this even for not rust code.
- pjmlp 2y agoCode editor and then paste.
- School-Cotton 2y agoI paste the code into an invocation of sed s/^/ /
- jasomill 2y agoSpecifically: 1. Copy code to clipboard. 2. From a shell prompt on macOS, pbpaste | sed 's/^/ /' | pbcopy Linux (Wayland), wl-paste | sed 's/^/ /' | wl-copy Linux (X11), xclip -o -se c | sed 's/^/ /' | xclip -se c Windows (PowerShell), Get-Clipboard | % { $_ -replace '^',' ' } | Set-Clipboard 3. Paste into HN.
- s17n 2y agoI have literally never used a doubly-linked list in my life, and I'm pretty sure that most programmers can say the same thing. As for the example... yeah, Python is pretty terrible (for writing production codebases, I think its a great language for short-lived, one-person projects). Interesting that you mention Python because if you're considering Python and Rust for the same use case that's pretty bonkers, for anything that you might possibly have used Python to do there are many more natural choices than Rust. If you wouldn't have done it in C/C++ ten years ago, you probably shouldn't be doing it in Rust today.
- deleted 2y ago[deleted]
- pjmlp 2y agoIf the programmers have a proper degree, they surely have used them, additionally they probably have done it inderectly, depending on what languages they use.
- iknowstuff 2y agoI haven’t had to „deal with” the borrow checker since like 2018. It’s quite smart
- CryZe 2y ago> huge pain in the ass Maybe if you structure your code weirdly? I haven't encountered a major borrow checker issue that I couldn't easily resolve in many years.
- delifue 2y agoIt's not appropriate to say that "having trouble with borrow checker means code is wrong". Sometimes you just want to add a new feature and the borrow check force you to do a big refactor. See also: https://loglog.games/blog/leaving-rust-gamedev/ https://loglog.games/blog/leaving-rust-gamedev/
- tinrab 2y agoI hear this constantly but never see any examples of what they actually mean, or it's coming from misunderstandings of what the language is. I've seen people say how well the async code could be if Rust got a garbage collector. For the borrow checker specifically, I think it's important to understand smart pointers, Cell/RefCells, other primitives, and the fact that you don't have to solve everything with references.
- RandomThoughts3 2y ago> it's coming from misunderstandings of what the language is “You are just not holding it right.” Rust borrow checker indeed does force you to make contorsion to keep it happy and will bite you if you fail to take its particularity into account. It’s all fine and proper if you think the trade-off regarding safety is worth it (and I think it is in some case) but pretending that’s not the case is just intentionally deluding yourself. The people here implying that the BC forces you to use a good architecture are also deluding themselves by the way. It forces you to use an architecture that suits the limitations of the borrow checker. That’s pretty much it. The fact that such delusions are so prevalent amongst part of the community is from my perspective the worst part of using Rust. The language itself is very much fine.
- 2y ago
- johnnyanmac 2y agoYeah. I wouldn't use Rust as a scripting language for that reason. But some critical applications want that enforced correctness and (hopefully) proper performance to be guaranteed if you pass the compiler. I want to eventually join the "50 engines for every game" race that is rust gsme engineer development, but I'm sure not going to have the fast iteration part of design be done in Rust. The renderer and all the managers should be absolutely solid, but some parts of games need you to break stuff quickly.
- s17n 2y agoEnforced correctness is great. Manual memory management isn't appropriate for most applications (games of course are an example of where it is!)
- XorNot 2y agoHaving just delved into Rust a little (and then given up and decided to learn Dart/Flutter for more practical applications development - I don't need another language to make command line tools in), this one I did feel while I was going through documentation. The problem is most of the important problems you deal with while programming require heap allocations: i.e. a lot of Rust advice is liable to lead you astray trying to find over-complicated solutions to optimizations you probably don't need up front. So in terms of systems programming, Rust is technically good here - these are all things you'd like to do on low level code. On the other hand if you're making a bunch of web requests and manipulating some big infrequently used data in memory...Box'ing everything with Arc is probably exactly what you should do, but everyone will tell you to try not to do it (and the issue is, if you're like me, you're coding in the "figure out what and how to do it" phase not the "I have a design I will implement optimally" phase).