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

Kotlin has optional OOP on the JVM. I still use it, but sparingly. Barely ever classes inherit from other classes in my code; I use interfaces, mostly to be able to fake services for testing.

Most of what I write are functions and data objects (records, basically).

One pattern I use is classes with one function, where the constructor takes the functions dependencies, and the function only takes non-dependency parameters.

 help



Functions and data objects are translated into OOP related JVM bytecodes.

Which is why, something like

    fun square(num: Int): Int = num * num
gets translated into

   public final class ExampleKt {
     public static final int square(int);
       0: iload_0
       1: iload_0
       2: imul
       3: ireturn
      }
    }

When running javap on the .class file.

People really should understand what they talk about avoiding OOP.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

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

Search: