• 0 Posts
  • 7 Comments
Joined 3 years ago
cake
Cake day: June 12th, 2023

help-circle




  • That depends entirely on how the object is constructed. Plenty of implementations use object.new() and you’re expected to fill in the blanks.

    That’s because some languages simply do not give a shit about data types. They’re just like “your opinion man” and can even vary at runtime which creates lots of exciting errors as you’re pointing out. Enjoy writing lots of type-checks.

    In a language that does care about types you can control that and don’t worry about it.

    Besides, even if you have a constructor that takes parameters, it’s essentially the same as calling a function. Get it wrong and stuff breaks.

    data class UserRequest { 
       val id: Int,
       val name: String
    }
    

    No guesswork. All values must be provided and none can be ‘null’. Well designed languages help you avoid such problems. Poorly designed languages facilitate it.