Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
vane110525y@kaae it’s no different then golang ( that doesn’t have generics ) where you need to check if T is instanceof Number type either float or double and also don’t have operators overloading. ex add two custom types vector v1 and v2 would be Vector v3 = v1.add(v2)
Want to build simple api not add().magnitude().dot().sub().mult() syntax. -
What's wrong with Rust's generics? If you want to make a physics engine Rust sounds like the exact thing you would want to use
-
Golang is having the generics conversation at this moment.
C# has great generics.
F# has even better generics.
Scala will be damn near perfect once union types are official and you don't need to lean into curry-howard isomorphism. -
vane110525y@12bitfloat
struct Test<T> {
x: T,
y: T,
}
fn dot<T: Add<Output = T> + Copy + Mul<Output = T>>(a:Test<T>, b:Test<T>) -> T {
return a.x * b.x + a.y * b.y
}
seriously ?
And
impl<T> Test<T> {
pub fn dot(self, v:Test<T>) -> T {
return self.x * v.x + self.y * v.y;
}
}
no matter what I do doesn't compile, lost 2 days, 10 game engines and physics engines doesn't have it inside impl. Generics are nightmare syntax. -
@vane Here's a link to a working version of your code: https://play.rust-lang.org//...
You forgot to constrain T in the impl for Test that's why you couldn't add or multiply the numbers.
The num crate isn't strictly needed for this simple example but definitely helpful when you try to do something more complex
Here's my version of the code: https://play.rust-lang.org//...
Note that traits can have supertraits which makes this quite a bit more usable. You can also look at the cgmath crate for a (pretty complex but also pretty good) abstract vector implementation using traits -
@vane My Rust dot product looks the same (minus the impl block which is a one time thing anyways, and which allows for specilication) and is more efficient since it's using an immutable reference instead of an reference counted ref
-
vane110525y@12bitfloat thanks a lot maybe I will try to push it forward in rust I really don't want to do it with swift despite the beautiful syntax.
-
@vane Rust is definitely the right choice for super efficient code that's also intuitive and high level. I can understand your frustration, trust me I had a lot of that aswell when I started using generics and lifetimes in Rust
But once you're over the initial "what the absolute fuck is happening" period Rust becomes super fun and intuitive -
@Fast-Nop C11 generics are pretty meh. The fact that you as a C programmer have never used them is kinda a red flag
-
@vane Weelll, Rust is kinda the Beauty and the Beast at the same time. If you really want a beast look at C++ lol. Rust can be pretty damn beautiful when not abusing generics and lifetimes to hell
-
@12bitfloat But that's only because I don't come across use cases for the same function on different data types. Well, except qsort, bsearch etc, with the additional comparison function pointer call overhead because no templates in C, but that has rarely been a bottleneck for my stuff. And where it was, I had only one data type so that a normal function was sufficient.
-
@Fast-Nop I guess it becomes more of a problem when using utility libraries (e.g. a quicksort implementation) which is not something I'd really want to do in C anyway
-
If we're talking about just generics and good typesystems then nothing comes close to stuff like Haskell, Idris, Agda
-
Not to sound snarky (seriously) but what you typed only proves that you're bad at Rust. Not that Rust is bad at generics.
-
@RememberMe But we also need performance for a physics engine so functional languages are no bueno
-
@hashedram That's often the case with people who dislike Rust. I don't think I've heard any big criticisms from people who actually know Rust (apart from the large binary problem perhaps)
-
I have been reading about Nim and thus far I like the things I have seen, but would need to give it more time before I can recommend it.
-
vane110525y@LotsOfCaffeine I don’t like microsoft and I can’t overcome this issue for my entire life. I was born with microsoft hate problems.
-
vane110525y@LotsOfCaffeine I don’t like java too, worked with java and it’s like language for children. It’s hard to break things there and I like breaking things.
-
@vane java really restrains you in many ways, mainly memory management
In C# you can actually use pointers in unsafe blocks, similar to Rust. Though I haven't really had much use for it. -
@LotsOfCaffeine
Writing the entire app in structs and enums will make for interesting C# to be sure. Adventures in dispose. -
vane110525y@LotsOfCaffeine yeah I know c# a bit wrote some software for money, even reverse engineered some server internal c# protocol but I don’t like ecosystem as a whole.
Don’t get me wrong I’m not saying it’s good or bad just I don’t feel comfortable using it.
Maybe if microsoft will stand with it’s opensource statements same amount of time as they were fighting with linux with their patents portfolio ( 20-25 years someone know ? ) they will convince me to try it a bit longer then for a day or two. -
@vane That's fair, the ecosystem seems a bit... convoluted.
But I do have to say, it's improved in terms of platform compatibility, I've compiled and executed C#/.NET Core on my raspberry pi running Linux. -
@vane
To some degree I would encourage taking at least the C# team in absentia the Microsoft funding. The current membership and alums are a who's who of accomplished and extremely talented individuals whose contributions to the world have spanned numerous companies, industries and decades. The language itself has had penetration far beyond Microsoft, as has typescript, Anders hejlsberg's follow-on project. It represents some of the best things to come out of MS into the opensource domain.
Related Rants
Any good programming language with great generics support that is not dynamic ?
Rust generics sucks so much I puked 2 times.
Tried with swift and it looks great.
Golang doesn’t have them.
Java sucks.
Maybe I try julia if someone say it’s cool.
I want to implement some 2d vector algebra and simple physics engine.
I started by creating generic 2d vector and trying to create dot product from it.
I didn’t wanted to do it in swift but wasted 2 days trying to do it in rust vs 1 hour in swift including 49 minutes of installing swift tools.
Anyway anyone know performant language with good generics support, let me know in comments.
question
generic programming
generics
rust
swift
julia