logoalt Hacker News

bedobi11/07/20241 replyview on HN

Partial instantiation is cool and all, but tbh I prefer just capturing the initial incomplete attributes in one complete record, pass that around, and then instantiate the real thing when you have all attributes

    data class IncompletePerson(val name: String)

    data class Person(
      val name: String, 
      val email: String
    )
or

    data class Person(
      val initialAttributes: IncompletePerson, 
      val email: String
    )
if you want to nest it.

if you're the type to instead do this

    data class Person(
      val name: String, 
      val email: String?
    )
I never want to work with your code. Now, there's no disambiguation between the complete object and the incomplete one, I always have to check before doing anything with it, and people will inevitably try send an incomplete object someplace that can't handle it and generate bugs.

Replies

skybrian11/07/2024

How would you define a cyclic data structure?