Live data from Hacker News

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

jgayfer.com

31–40 of 45 posts

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

#31
post #26
post #17

Earlier quoted context omitted.

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

I love how everyone likes to blame Java for OOP, when most of the stuff that eventually ended up in enterprise OOP patterns, predate Java for 10 years. Including those stupid "coding Java in C++" remarks, when Java OOP model is based on a mix of C++ frameworks, and Objective-C features.

And Objective-C is just Smalltalk with C syntax.

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

#32
Don’t even write Java like it’s Java!

Discussing curriculum and textbooks for a Java class today, someone recommended a book that was most recently updated for Java 7. When I pointed that out, the response was:

“The level we teach at, the new Java features won’t make much of a difference.”

Java is a culture just as much as a language, and the culture is stuck somewhere in the past in a lot of places, especially in education.

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

#33
Sometimes it is easier to arc dyn your way out of things especially in the async world and if you need to decouple two parts of the software. You get a sort of slower ref count gc similar to swift but it makes your life more enjoyable, always depends on your usecase.

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

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

Yep, "With enough thrust, pigs fly just fine" - Java's addition of GC was that brute force solution to the tangle of mutually mutating randomly interconnected objects that in C++ tended to collapse under its own weight without making it to production.

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

#35

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

That's funny. Writing Ruby with Sorbet works fairly well if you just pretend it's Java most of the time. Have to keep in mind that the static typechecking is broken, so can't go refactoring wildly and get it on the first go. Limiting use of metaprogramming to what amounts to being annotations is also friendly to coworkers.

Of course what's being picked upon is a specific kind of Java code. It's better to be specific than technically incorrect, as all written Java is Java regardless of how you write it. The article goes a good job (comments here less so), except for this bit:

> While not entirely accurate, there’s some truth to the trope that Java developers need everything to be an interface (I am one such developer).

That's not just Java, that's Dogma.

What does work for me is writing in most languages (Java included) as if they're functional ones without lots of variable reassignment or data mutation.

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

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

Java got picked up by the enterprise software crowd. (Maybe blame Sun for that - the enterprise people were going to buy a lot of servers.) The enterprise software culture is where you had "software analysts", which was a different job description from "programmer". That culture took over Java and made it what we now think of as "Java culture", but it wasn't really Java. It was really the enterprise software culture.

That's my opinion, anyway.

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

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

It's not bad. There are some rough edges though (like the platform types, that CAN be implicitly `null`, horrible).

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

#38
post #30

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…

Primitive types are placed on the stack, as are those classes proven to not escape current scope, thus not everything. When Valhala is finally merged, then value class and value record will also not be on the heap by default. Finally, even without Valhala, Unsafe and Panama allow for off heap allocation, thus again, not everything.

You are correct, I was oversimplifying to get the point across. Valhalla is one of the most promising upcoming technologies I am anticipating, but I don't expect it to change the approach to writing most Java programs.

What makes Java so good is that it is a language written for creating high quality libraries and frameworks. Sure, it will be nice to define your own zero-cost classes but the largest benefit will stem from improved an standard library as well as an enabler for high-performance programming and GPU access.

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

#39

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

I'm afraid you are right. But I believe some programming language communities suffer from a great deal more than others (looking at you Python).

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

#40
post #29

Generally good advice is: Don't program Rust like nearly any other programming languages you know. If you try to program Rust like C you are going to fight and lose. If you try to program Rudt like and Object Oriented Language you will eventually go mad. If you like a Zen master let all previous knowledge and pre-conceived notions of what beautiful code has to be out of the window and do it the Rust way, suddenly thi…

Also applies to: Lisp, Haskell, Smalltalk, APL, Forth, even C. Maybe you can write Kotlin like C#, or Lua like JS, but style is not portable in general.
Post reply on HN