Don't write Rust like it's Java (2023)
jgayfer.com
Don't write Rust like it's Java (2023)
1–10 of 45 posts
Re: Don't write Rust like it's Java (2023)
#2Re: Don't write Rust like it's Java (2023)
#3Of 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)
#4Of 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)
#5I’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.
Re: Don't write Rust like it's Java (2023)
#6This 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)
#7I 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)
#8Of 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)
#9Of 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)
#10Java 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.