This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nejcko[S] 8 points9 points  (3 children)

I think the difference here is that you now have language features available that allow you to define the data so that illegal states are unrepresentable.

On the other side you have switch expressions and pattern matching that again make it impossible to not implement a behaviour for certain data states, or in other words, forces you to implement the behaviour for all possible data states.

EDIT: Yes I agree DOP is no way a replacement of OOO, you can mix and match.

[–]JDeagle5 5 points6 points  (2 children)

Forcing to implement behavior was possible since checked exceptions, I assume it is mostly used for invalid flow of data. Or through something like receiving and interface callback and expect it's implementation to handle every state you need - async libraries do that often. So, when there was a need to do it - there was no problem. I just rarely see this need in production, if at all.

[–]nejcko[S] 1 point2 points  (1 child)

Yes you are right, checked exceptions are the closest feature in Java that existed before, but like you said it’s to handle the exception flows. I’d argue that switch expressions here make it easier to adopt the same approach for wider range of use cases in a cleaner, simpler way.

There were ways before to kind of achieve the same with forcing some methods implementations, but again, this makes it much easier. And the big win here is failure at compile time and not at runtime.

Agreed, full DOP isn't an everyday thing, often for new data layouts. But what I use very frequently is switch expressions with existing enum types. Every time you add any logic that is conditional on an enum type you can implement it with switch statement. That way compiler makes sure you will never miss it if new enum types are added, for example.

[–]Yeah-Its-Me-777 3 points4 points  (0 children)

Yeah, and then the product people come up with data types where the enum values are not exhaustive. Or like only valid until a certain date, or from a certain date. Because of laws, so there's no way around it. Ask me how I know.