How much do you use domain-specific types?

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 987 Views - Last Post: 23 March 2020 - 01:31 AM

#16 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2410
  • View blog
  • Posts: 5,050
  • Joined: 11-December 07

Re: How much do you use domain-specific types?

Posted 13 March 2020 - 03:14 PM

There is more than one codebase I have worked on where I wish we had used domain types, even just for the IDs. That is: DocumentId and AuthorId instead of UUID and UUID.

An advantage not mentioned above is allowing you to change the underlying implementation. I worked on a geology system where we had to swap floats for doubles at one stage, but only on some of the codebase. It would have been far easier if we had something wrapping them.

I've seen systems that got the concept of time wrong. It would have been far simpler to find and fix all the time-related stuff if it had been wrapped in a set of types designed for that application.

If there is a trick you can do to force yourself to get something correct then I say go for it. The cost in mistakes in terms of time, money and customer confidence is high so it pays to get things right.
Was This Post Helpful? 1
  • +
  • -

#17 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7389
  • View blog
  • Posts: 24,940
  • Joined: 05-May 12

Re: How much do you use domain-specific types?

Posted 13 March 2020 - 05:14 PM

The dilemma of every software architect: Fisher Space Pen vs. pencil. When is a pencil good enough, and when should you shell out money for that super cool space pen?
Was This Post Helpful? 0
  • +
  • -

#18 Yossu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 01-November 18

Re: How much do you use domain-specific types?

Posted 15 March 2020 - 08:03 AM

View PostSkydiver, on 13 March 2020 - 05:14 PM, said:

The dilemma of every software architect: Fisher Space Pen vs. pencil. When is a pencil good enough, and when should you shell out money for that super cool space pen?

Wonderfully summed-up! Exactly the dilemma I was trying to resolve!
Was This Post Helpful? 0
  • +
  • -

#19 Yossu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 01-November 18

Re: How much do you use domain-specific types?

Posted 15 March 2020 - 08:09 AM

View Postcfoley, on 13 March 2020 - 03:14 PM, said:

There is more than one codebase I have worked on where I wish we had used domain types, even just for the IDs. That is: DocumentId and AuthorId instead of UUID and UUID.

An advantage not mentioned above is allowing you to change the underlying implementation. I worked on a geology system where we had to swap floats for doubles at one stage, but only on some of the codebase. It would have been far easier if we had something wrapping them.

I've seen systems that got the concept of time wrong. It would have been far simpler to find and fix all the time-related stuff if it had been wrapped in a set of types designed for that application.

If there is a trick you can do to force yourself to get something correct then I say go for it. The cost in mistakes in terms of time, money and customer confidence is high so it pays to get things right.

Understood, but then you end up with a huge proliferation of types, each of which has to be instantiated when you need them, leading to a lot more code. Whilst the benefits are clear when/if you need to change types, I'm not sure this is a common enough occurrence to justify the extra code. Obviously it depends on your experience, but I've never seen that.

So if you were to start one of these code bases from scratch, would you use custom types for absolutely everything?
Was This Post Helpful? 0
  • +
  • -

#20 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7389
  • View blog
  • Posts: 24,940
  • Joined: 05-May 12

Re: How much do you use domain-specific types?

Posted 15 March 2020 - 10:10 AM

It tends to be a situation of pay now, or pay more later. You would need to justify to the customer that line item in burndown chart that shows an extra 3 story points for custom types in each sprint that is cummulatively costing an entire sprint to get the product to the customer, or about two years from now, they are going to find, interview, hire, and train a contractor for $80/hr to do the work over a span of 3-6 weeks.

Sometimes, it is worth buying and pulling that Cat6 cable through the walls while the studs are still exposed even though that you don't foresee using any of the rooms as a home office, or gambling that WiFi 6 and mesh networks costs will cheaper in the future than the cabling now.

Spoiler

Was This Post Helpful? 0
  • +
  • -

#21 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2410
  • View blog
  • Posts: 5,050
  • Joined: 11-December 07

Re: How much do you use domain-specific types?

Posted 23 March 2020 - 01:31 AM

Quote

So if you were to start one of these code bases from scratch, would you use custom types for absolutely everything?


For a Java or c# system that was going to be maintained for years, maybe decades? Yes, absolutely.

However, I may never get a chance to convince a team to work like this.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2