Live data from Hacker News

Don't write Rust like it's Java (2023)

jgayfer.com

11–20 of 45 posts

Re: Don't write Rust like it's Java (2023)

#11
Everybody worth their salt should know that those languages have completely different working models in mind.

Java puts everything into the heap and creates easy expressability by having pointers everywhere. In contrast, Rust often avoids pointers, prefers the stack and is very stingy with memory access.

These languages are completely orthogonal to each other and it has consequences in their usage. Not that a good chunk of people wouldn’t butcher the code they are given in any codebase…

Re: Don't write Rust like it's Java (2023)

#12

Yoo, congratulations to the author for going from this blog post dated to October 2023 to shipping an actual rust crate (bevy_light_2d)! I suspect the author might be reading this post back and cringe a bit. That last code listing with handle_session_completed triggers my inner clippy. Why clone session.customer_id to then pass it as a reference? Why are those CheckoutSession fields Options? The other advice I would…

[deleted]

Re: Don't write Rust like it's Java (2023)

#13

Everybody worth their salt should know that those languages have completely different working models in mind. Java puts everything into the heap and creates easy expressability by having pointers everywhere. In contrast, Rust often avoids pointers, prefers the stack and is very stingy with memory access. These languages are completely orthogonal to each other and it has consequences in their usage. Not that a good ch…

you'd be surprised how few developers today even know what general subject you're talking about

Re: Don't write Rust like it's Java (2023)

#15
post #4

Earlier quoted context omitted.

Totally. The amount of indirection and badly written code with hundreds and thousands of classes which take a simple data and combine it with magic methods which you have to open the class to understand is crazy.

A whole beach of sand,every grain a unique object,influenced by water,milled from a clifffactory.No other way to model a holiday..

This made my morning, thanks.

Re: Don't write Rust like it's Java (2023)

#16

I’ve also had some success writing Java more like as if it’s rust, using Java Records instead of classes to create immutable types. I’m not sure if I would recommend it if you’re working as part of a team though, other java devs will hate your code lol.

Hasn't the use of behaviourless value objects (essentially structs) been commonplace in both the JVM and the related .NET-world for the better part of a decade now, maybe more?

Re: Don't write Rust like it's Java (2023)

#17
post #2

Of course this is on point, you shouldn't write Rust like it's Java, however looking at Java, you shouldn't write anything like it's Java. Java has brought forth the biggest madness of tacking on OOP to everything that is still making 3 billion software projects unreadable.

> Java has brought forth the biggest madness of tacking on OOP to everything

It was C++, if we are being historically accurate. It’s actually a positive in Java’s case that it managed to make these systems even run.

Re: Don't write Rust like it's Java (2023)

#18
post #10

I look at Rust more as an FP lang than an OO lang. By FP I mean: you have data and logic; never a combination of both (classes/objects). Java makes this king of separation between data and logic really hard. Kotlin came to the rescue for us. It allows us to move our Java/OO codebase in a slightly more FP direction: uncouple data and logic, immutability is preferred, no (or very little: yes looking a you shitty "platf…

Kotlin is easily the best modern language for DX. After writing server-side Kotlin for the past three years, I'm not sure I ever want to write anything else.

Re: Don't write Rust like it's Java (2023)

#19

> Remember that great feature of Rust being memory safe? It comes at the cost of not being able to easily “inject” something that implements a trait. This is not at all the reason. The real reason is that Rust chooses to make the runtime overhead required for dynamic typing and heap allocation explicit, not anything to do with memory safety.

Well, java won’t have any overhead in many cases (e.g. only single implementation), as the JIT compiler will do its job.

Re: Don't write Rust like it's Java (2023)

#20

I feel like this axiom is true in general. Don't write [insert lang here] like it's Java. I've seen this in Ruby code bases, TS code bases, even Erlang code bases (using gen servers like an OO primative.)

This makes me immediately think of NestJS which copies everything from classes, annotations & ORMs to service locators. It still managed to grow to 3M weekly downloads.

Maybe there's a certain safety in doing thing how they've always been done - even if that seems backwards to me.

Post reply on HN