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

> thus compilation - happen at runtime, anytime, always.

To be a bit pedantic, you can compile Ruby code with `RubyVM::InstructionSequence.compile`, and then dump and load it as a String.

That's one of the things Bootsnap does to speedup boot time. And when you do that, there's no compilation at runtime.

But that doesn't change anything about OP's suggestion, it's still impossible to know if an interface will ever be implemented.

https://docs.ruby-lang.org/en/3.3/RubyVM/InstructionSequence...




Indeed, I did not mention Bootsnap so as to detract the core point.

> That's one of the things Bootsnap does to speedup boot time. And when you do that, there's no compilation at runtime.

Correct, if one does `bootsnap precompile`.

Bootsnap hooks itself on `Kernel#load` + `Kernel#require` and `RubyVM::InstructionSequence#load_iseq`:

https://github.com/Shopify/bootsnap/blob/f627992c52642394311...

https://github.com/Shopify/bootsnap/blob/f627992c52642394311...

https://github.com/Shopify/bootsnap/blob/f627992c52642394311...

https://github.com/Shopify/bootsnap/blob/f627992c52642394311...

Essentially this means that it makes LOAD_PATH lookup faster + intercepts iseq compilation to store to cache on a miss and return a cached version on a hit.

That does not change the load order.

> But that doesn't change anything about OP's suggestion, it's still impossible to know if an interface will ever be implemented.

Again correct, as even with `bootsnap precompile` it would only result in earlier ISeq generation (it is essentially cache priming instead of doing it "lazily" on demand), not the time at which these ISeq get loaded and effective, so even then an `abstract` keyword would be ineffective (or rather, equivalent to raising NotImplementedError, i.e syntactic sugar)

The only way to do it outside of runtime is with type information, ensuring that only certain types respecting a contract reach the point where the expected interface is made use of. I'm using RBS+Steep, not just for that but this is one of the main reasons and I can attest it does work very well in practice: when the types don't respect the contract it blows up as expected, at which stage raising exceptions is either redundant or a defensive coding mechanism (and I've actually had Steep yell at me because some clauses were unreachable due to types ensuring the contract)




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

Search: