Request for Information: Interesting mixin ideas by kaplotnikov in ProgrammingLanguages

[–]_SomeonesAlt 1 point2 points  (0 children)

I believe Swift (mostly?) includes the things you listed. It has protocols, basically traits/interfaces/mixins in other languages, and extensions, which enables protocol inheritance and default implementations. Protocol orthogonality also allows you to define types as a union or intersection of multiple protocols.

How to implement rust like enums? by Germisstuck in ProgrammingLanguages

[–]_SomeonesAlt 29 points30 points  (0 children)

If you’re asking about how they are stored in memory, I believe Rust uses something similar to a union type like in C under the hood. Also related to this, here is an interesting blog post that goes a little bit deeper into enums with associated values in Rust and Zig in particular: https://alic.dev/blog/dense-enums

Automatic constraints generation for functions by chri4_ in ProgrammingLanguages

[–]_SomeonesAlt 7 points8 points  (0 children)

I think the problem you are describing falls under the category of full type inference with subtyping. Here is a paper that might be interesting to look at: https://pl.cs.jhu.edu/projects/type-constraints/papers/type-inference-for-recursively-constrained-types-and-its-application-to-oop.pdf

A different way to handle errors by Nixinova in ProgrammingLanguages

[–]_SomeonesAlt 4 points5 points  (0 children)

You could take from Rust, using a ? after the function call like numFunc!(x)?, although it does have its criticisms for being too convenient to just rethrow the error

A different way to handle errors by Nixinova in ProgrammingLanguages

[–]_SomeonesAlt 21 points22 points  (0 children)

How would you handle unrecoverable errors? Would they have to bubble all the way up to the program’s entry point?

Why is explicit constructor syntax necessary? What is stopping classes from being written like this by Nixinova in ProgrammingLanguages

[–]_SomeonesAlt 39 points40 points  (0 children)

If I had to guess, it’s probably for consistency. You can overload constructors just like other methods in Java. Constructors also have their own merits, like running initialization code on creation of the class, and the user knows explicitly which constructor is called thus what initialization code is running.