Hacker News new | past | comments | ask | show | jobs | submit login

Sure, but is there any alternative to C++ if you are looking for an object-oriented language that compiles to native code?

Many modern languages don't have "proper" object-orientation, with subclasses, polymorphism, liskov substitution principle and so on. Rather, they have compile-time polymorphism, or opinionated other ways of doing it (composition in Go, traits in Rust. Methods in Nim are wierdly attached to the language, and if you want interfaces, the author recommends you use a closure and function pointers...)

Other "classic" object-oriented languages are all managed (C#, Java).

What I'd want from a language is:

- a powerful but ergonomic type system (stuff like Nims "distinct" types are nice). Maybe we can even get simple dependent types.

- Class-based object orientation is nice for 1) writing UI code and 2) getting rid of duplicated ifs everywhere.

- Generics. Bonus if we can control contra/co/invariance of type arguments. (A Ptr<ToggleButton> is a Ptr<Button>, but a List<ToggleButton> might not be a good List<Button> everywhere, since you can add ToolbarButtons for example.)

- Functional programming: Functions and methods as first-class-citizens, built-in understanding of pure functions and const data

- Async programming: async/await as first class citizen

- Compiles to native code

- No frickin UB.




You probably know this, but for reference, while Rust doesn’t support implementation inheritance, it has inheritance and runtime polymorphism at the interface level.

You put your dynamic components into references and smart pointers of the form Box<dyn Component>, where Component is a so-called “object-safe trait” (which is exactly what you’d call an interface in the OO world). These traits can inherit from each other, and you can upcast a Box<ConcreteType> into a Box<dyn Interface> into a Box<dyn ParentInterface>.


No I don't know Rust very well, I really should put in some time to learn it properly! I did a bit of GUI programming in the past, and felt there is a bit of impedance mismatch with Rust there. And the kind of subtle mistakes with ownership and reference cycles you tend to make in C++, but discover when you move to unique_ptr: Rust also ruthlessly uncovers them, but I guess I need more experience how to solve them.


> Other "classic" object-oriented languages are all managed (C#, Java).

True, but there have been always ways to compile them to native code, granted not all of them as free beer.


That is asking for quite a lot. "Proper" OOP _and_ proper functional programming in one language...


Nah, I'll settle for good enough functional programming (map, apply, nice closures). Python, Kotlin, recent C#, JS/TS all have this.


Pretty sure C# had this since about 2008 with LINQ and lambdas in C# 3.


Swift? (minus the ability to specify co/contra-variance)


Probably a dialect either of Pascal or BASIC.


Ada covers quite a bit of what you want.




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

Search: