2
vane
18d

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.

Comments
  • 2
    What is wrong with Java? Just curious.
  • 0
    I am guessing templates in C++ would work.
  • 1
    @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.
  • 5
    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
  • 2
  • 4
    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.
  • 2
    @SortOfTested i am going to hit on you now πŸ˜³πŸ‘‰πŸ‘ˆ
  • 1
    Just putting this out there
    @highlight
  • 1
  • 0
    @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.
  • 1
    @12bitfloat ok so you need to use num crate to have it working then.
  • 0
    @highlight swift and find me more beautiful syntax for dot product
  • 1
  • 1
  • 2
    @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
  • 0
    @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
  • 1
    @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.
  • 4
    @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
  • 0
    C11 introduced generics, though I've never used them.
  • 1
    @12bitfloat If llvm is Disney swift is Beauty and rust is Beast then :)
  • 1
    @Fast-Nop C11 generics are pretty meh. The fact that you as a C programmer have never used them is kinda a red flag
  • 0
    @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
  • 1
    @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.
  • 1
    @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
  • 1
    If we're talking about just generics and good typesystems then nothing comes close to stuff like Haskell, Idris, Agda
  • 1
    Not to sound snarky (seriously) but what you typed only proves that you're bad at Rust. Not that Rust is bad at generics.
  • 0
    @RememberMe But we also need performance for a physics engine so functional languages are no bueno
  • 2
    @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)
  • 1
    Kotlin
  • 1
    @12bitfloat big binary problem actually games from std library, but nowadays there is many libraries than support "no_std" what reduces size a lot. Also there is some other things to do when want to have minimal binary. But yeah by default Rust binaries are quite big, but on desktop use it's so small that it don't matter, and on embedded it is mostly needed to use all tools to minimize size so then you will learn them.
  • 0
    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.
  • 0
    Don't know about Rust but have you considered C#?
  • 0
    @LotsOfCaffeine I don’t like microsoft and I can’t overcome this issue for my entire life. I was born with microsoft hate problems.
  • 1
    Just Create your own language brahh😎
  • 1
    @vane enjoy Java then :p
  • 0
    @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.
  • 2
    @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.
  • 0
    @LotsOfCaffeine
    Writing the entire app in structs and enums will make for interesting C# to be sure. Adventures in dispose.
  • 2
    @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.
  • 1
    @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.
  • 1
    @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.
Add Comment