Live data from Hacker News

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

jgayfer.com

1–10 of 45 posts

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

#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.

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

#3
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.

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.

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

#4
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.

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..

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

#6
> 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.

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

#7
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 give is to identify what the author calls "Service" as what is called "view type" or "newtypes" in rust. A newtype wraps another type, to give it a different set of methods. For example, a counter could wrap an i32 and only allow incrementing and reading the value. Or put together a set of references to fields/slices of a struct.

It can be useful, but the way it's used by the author here is not very rusty, and the final suggestion of using a function is a descent alternative. Although I think defining handle_session_completed as a method on CheckoutSession or UserRepo might be better.

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

#8
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.

Even in Java, the interfaces everywhere style was never great. Somehow Java got picked up by Architecture Astronauts that love writing enterprise pattern layer cake. Nothing in the language makes this style necessary, it's perfectly possible to write short and sweet code, and yet the Java culture got infected with this overcomplicate everything culture.

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

#9
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.

Even other JVM languages aren't safe from this, since you still need to interface with Java

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

#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 "platform types" in Kotlin) implicit nulls.

Post reply on HN