Live data from Hacker News

Was Rust Worth It?

jsoverson.medium.com

711–720 of 736 posts

Re: Was Rust Worth It?

#711

Earlier quoted context omitted.

Sure, you can panic unwrapping a None, but there are two important distinctions. First, this is a controlled panic, not a segmentation fault. The language is ensuring that we don't access the null pointer, or an offset from the null pointer. Null pointer access can be exploitable in certain circumstances (eg, a firmware or kernel). Your use of "exception" suggests you're thinking about it in Java terms however, and J…

>First, this is a controlled panic, not a segmentation fault. But a segmentation fault is also controlled >Your use of "exception" suggests you're thinking about it in Java terms however, and Java is equivalent here. No, I am thinking in Delphi terms. It is overspecialized to Windows userspace. Windows gives an Access Violation, and that can be caught, and Delphi throws it as exception >Second, you can only encounter…

> But a segmentation fault is also controlled

A segmentation fault may not happen (which is to say, we may corrupt memory or worse) if the null pointer is mapped into memory (as in an embedded or kernel context) or if it's accessed at a large offset, which results in a pointer that's mapped into memory. This may be rotten luck or it may be exploited by an attacker.

> No, I am thinking in Delphi terms.

Fair enough, I don't know Delphi. I'll take what you're saying about it as read.

Re: Was Rust Worth It?

#712
post #367
post #320

Earlier quoted context omitted.

> I just wish Rust learning resources would be more upfront about this. While beginner resources don't dwell too much upon cyclic references, they don't consider unsafe blocks as unusual. All the material I've seen say that there are certain domains where Rust's compile-time safety model simply won't work. What Rust allows you to do instead, is to limit the scope of unsafe blocks. However, the beginner material often…

> Cyclic references can be dealt with runtime safety checks too - like Rc and Weak. Indeed. Starting out with code sprinkled with Rc, Weak, RefCell, etc is perfectly fine and performance will probably not be worse than in any other safe languages. And if you do this, Rust is pretty close to those languages in ease of use for what are otherwise complex topics in Rust. A good reference for different approaches is Learn…

You still need a main owner in those patterns, that owner must be part of a DAG of owners - you cannot have cyclic ownership.

Re: Was Rust Worth It?

#713

Earlier quoted context omitted.

Maybe for you it's unusual - in my previous work all the apps contained graphs, and I just joined a company where almost all the apps also contain graphs

I don't write Rust, but I never understood why graphs meant you need circular references. Doesn't it just come down to the question of who owns the node? If it's a tree, and parents are never removed before children, just make the child owned by the parent and keep a weak reference to the parent. If it's a general graph, and vertices can exist or not exist regardless of edges, keep a list of them independent of the e…

Things get tricky when you have a valid triangular relationship amongst equal objects. This comes up far more often than you’d expect.

Re: Was Rust Worth It?

#714
post #399

Earlier quoted context omitted.

An abstract syntax tree can't have cycles by definition.

Technically true, but sometimes you want parent pointers. You then have a more general graph in the underlying representation, but it still represents a tree structure.

Same shows up in Postgres Query* struct for SQL. Copying memory between parser, planner, execution would be too expensive in large queries - so instead you have an arena allocated representation.

Re: Was Rust Worth It?

#715

Earlier quoted context omitted.

An Abstract Syntax Tree / or Double-Linked List both qualify, but they're also a lower level implementation detail than I'd expect to frequently interact with in a reference safety focused language. I've still been meaning to write something in / learn Rust's ways of thinking; is there not an intended replacement for these data structures? Or do they expect it all to go under Unsafe?

> is there not an intended replacement for these data structures? Or do they expect it all to go under Unsafe? For linked-lists, there's one in std and the majority of people should never have to write their own as it's error prone and requires unsafe. For graph use-case then you can either use ECS, arena, ref counting or unsafe, but you're probably better off using/developing a dedicated crate that optimizes it and…

The one in std uses unsafe. My main concern with learning rust is that you can spend ages trying to learn “the right way” of doing things in rust, when the right way really is to use unsafe.

Re: Was Rust Worth It?

#717

Earlier quoted context omitted.

C# is underrated by the HN crowd, I find. I quite like how mid sized firms (100-1000 employees) use it.

I used to be .NET dev and don't agree. Couple of reaons: 1) Modern Java is almost as good as C# with some things I can't give up in Java (static imports => succint code, Groovy Spock => succint tests) 2) Kotlin is better than C# 3) JVM has much much bigger ecosystem (almost all the apache projects are JVM oriented) and default web framework is much less code to type (SpringBoot) is much more productiv 4) JVM has wide…

#1 => agree

#2 => don't know enough about Kotlin to comment

#3 => agree but quality > quantity

#4 => not terribly important to me (Clojure is cool but it's not "switch to the JVM" level cool)

Re: Was Rust Worth It?

#718
post #316

Earlier quoted context omitted.

I tried to get into rust for many years, I'm now in a C/CPP job (after Java/Python/Ruby and other gigs). What I've come to understand is that Rust's lifetime model is very difficult to work with whenever you have a cyclic reference. In C/CPP the same holds, but you deal with it through clever coding - or ignoring the problem and cleaning up memory later. Java, and other GC'd languages just work for these structures.…

Oh I just put up a blog post about this on Monday :) https://jacko.io/object_soup.html Agreed that I wish more beginner Rust books had a section about this. The pattern is quite simple, but it's hard for beginners who get stuck to realize that they need it.

I would have needed this when I started learning Rust! All my early programs were object soups.

Re: Was Rust Worth It?

#719
post #646

Earlier quoted context omitted.

Lifetime analysis matters a lot for way more than just garbage collection. File handles, iterators, mutex guards, database transaction handles, session types, scoped threads, anything where ordering or mutual exclusivity matters.

I don't know about all of those, but Python's context managers and built in constructs handle most of those, I think?

Only in the most basic cases. If your handle has to be passed into another function or outlive the current scope of your function, the guardrails end.

Re: Was Rust Worth It?

#720

Use C++ if you want control, use Rust if you want safety. And it seems to an extent that carbon will offer most of both.

Rust offers you great control when you need it (to the same level of C++, basically. This is what it was designed for). And even the Carbon docs say that if you start from scratch prefer languages like Rust.

No it doesn’t. The vast majority of what is taught in a college C++ course would be either impossible or extremely difficult to do in rust. You couldn’t implement std::tuple or std::variant for instance.

The carbon docs never recommend rust, they just urge you to use something already available.

Post reply on HN