Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes. That is sane and important advice when talking about any optimization in any language.

Unless it's an execution hotspot in your code, value clarity and maintainability over performance.

Most of the speedups in these optimizations are very small in absolute terms (only a few milliseconds each) so they will only provide a real-world benefit if they're being called in a loop or something.

That all said:

1. A lot of these optimizations are also a win when it comes to clarity (Array#sample is faster and clearer than Array#shuffle.first)

2. Knowing that the "bang" version of a method is always destructive and nearly always faster is a good thing to remember in general for Ruby



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: