Canonicalise, Don't Remember β€” Smart Constructors in Kotlin

5 months ago by codeinabox to c/kotlin

If you have to remember to call mergeByX() before you pass a value around, you're sowing foot guns. Make the constructor do it once, and let the type carry the promise.
sch3lp 1 point 5 months ago

@codeinabox I’m confused. Does Cart live in your domain or is it input (just a container for the data that creates a Cart in your domain)? If it lives in your domain, then your article read like an FP programmer slowly realizing OO. πŸ˜… If it’s input, then I don’t think it’s duplication of concept because one is used for rendering and the other for creating. πŸ€”

path: 0 23719286, hotness: undefined, score: 1, children: 0
kotlin
kotlin

@programming.dev

login for more options
808
109
11

Kotlin is a statically typed programming language for the JVM, Android, JavaScript, and native.

Subreddit rules:

  • Be civil
  • No spam
  • Stay on-topic
  • No fluff

Resources:

go to feed...