Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@Lensflare When the type hierarchy isn't very good in C++, C# and Java there's a tendency for downcasts to proliferate throughout the codebase. The mechanism by which this happens is usually as follows:
- class with broad purpose has property of abstract class or interface type
- specific code obtains instance of broad class which has specific meaning and therefore implies the subclass of the property
- relying on this assumption, engineer adds downcast to specific code to quickly access subclass data without needing to establish proper pathways
- since many specific fragments access the general class in specific ways, this repeats over and over. Whether the subclass assumptions are documented may change the severity of the problem but it's a problem nonetheless.
1/2 -
In data driven programming, the problem changes. Mutually exclusive cases which were previously subclasses become sum types, and pattern matching allows to formulate complex conditions. But a bad data model is still a bad data model, only this time it manifests as a crashing catchall pattern at the end of an exhaustivity-tested list. Basically, an unknown or large number of representable values that are invalid in context.
When the datastructure you're working with allows for a large number of variations that you can assert never to happen, the datastructure is probably wrong.
2/2 -
Voxera115851yNo pattern will save a bad basic architecture.
But some patterns offer more options to shot ones foot than others ;)
Related Rants
Turns out composition over inheritance won't save you from downcast hell, it just becomes `_ => abort()` hell.
rant
fp
rust
pattern matching
this was a comment
refactoring