2 ms·
>Lastly, it is far too easy to create complex types with questionable value all over your code. Any time a developer wants to unravel a pre-existing complex typ
by kajaktum 4y ago
>Lastly, it is far too easy to create complex types with questionable value all over your code. Any time a developer wants to unravel a pre-existing complex type, it feels like working with C++. It's utter garbage.
No. Having types is always better than not. If you have a complex functionality, it is going to have a complex type. But now you KNOW its complex and not have to unravel its complexity for the 5th time this month.
I had to write something like this recently:
```
pub SearchInfo {
matches: Arc<HashMap<PathBuf, Vec<(usize, (usize, usize), String)>>>
}
```
This is complex, yes, but just by reading the type and names given to it:
1. `Arc`. So that means it can be safely shared across thread.
2. `HashMap` from `PathBuf` to `X`. So I am probably mapping file/folders to X.
3. `Vec<(usize, (usize, usize), String)>`. So the first `usize` denotes the line number. `(usize,usize)` denotes the start and end characters and the `String` is the whole line itself!
Just imagine unraveling this whole crap if its all simply a JavaScript `Object`.
- pkolaczk 4y agoIt would be probably better if you haven't used naked usize, but wrapped it into a new type. When I find types get complex, I introduce type aliases or structs. That X in your signature likely deserves a name.
- tipsytoad 4y agoI'd convert that last tuple to struct, unlike the rest of the type it's undecipherable without some kind of documentation.