Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Rust looks nothing like C++.

It looks like Ruby.

The generics look like Java.



How do you feel the generics "look like" Java ?

Implementation-wise they're the same trick as C++, monomorphization.

Stylistically they're not very like either, however the effect is more like C++ because Rust idiomatically prefers to constrain functions not types so e.g. it's fine to talk about HashMap<f32, f32> a hypothetical hash table of floating point numbers mapped to other floating point numbers - even though we can't use such a type because if we try to insert into it we'll be told that insert requires its key parameter to implement Eq and Hash, which f32 doesn't because of NaN.

In both C++ and Java as I understand it these constraints live on the type not the functions associated with that type, although C++ does not have the same constraint here and is perfectly willing to try to make a hash table of floats... but where a constraint lives on a function in C++ it would behave similarly to Rust due to SFINAE - the function won't match so your diagnostics say there's no such function, probably worse diagnostics than Rust but that's par for the course in C++.


And here I was thinking we were talking about the syntax.

My Ruby claim doesn't hold much weight either if we're talking about the actual implementation.

C++ templates look like an entirely new language within the language.

Rust and Java make generics fit within the aesthetics and ergonomics of the language.

If anything feels "bolted on" to Rust, it's proc macros and (to a lesser degree) async.


Oh I see. Yeah, perhaps slightly for the syntax. I suppose Java's idiom of naming classes (its only user defined types) with capital letters stands out as more similar and so in Java our growable array of geese is ArrayList<Goose>, in Rust it's Vec<Goose> but in C++ std::vector<Goose> or perhaps std::vector<goose> if we're copying the style of the standard library.

It doesn't feel like very much, but now that you spell it out I guess I do see it.


> C++ templates look like an entirely new language within the language.

Templates cover more than just generics. Java full-sale lifted its generics syntax from sepples. I'm curious how you draw the line between the two, when all 3 of them use the angle bracket declaration lists bolted onto the symbol name, a unique style invented by CFront 3. Compare with the generics syntax found in contemporaries like ML, Miranda, Ada, Modula-3 and so on.


Java Generics look like C++ templates and Rust generics act much more like C++ Templates than Java Generics.


Also, “new C++” refers less to syntax and more to role in the development ecosystem.


Other than the `|var|` syntax in closures, I can't think of a single way Rust looks like Ruby. I mean that seriously, there is almost no other similarities.


Don't forget expressions and block expressions, and all of the Ruby-esque syntax sugar around them. How expressions work with functional methods.

I write a lot of chains with block expressions that almost look 1:1 with Ruby.


There's definitely some Ruby influence (closures syntax in particulary), but I think I'd argue that Rust syntax is closer to JavaScript/TypeScript than anything else.


i suspect the example was syntax like a.b().c().d(10)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: