| ▲ | MrBuddyCasino a day ago | |
> I’ve always felt that functions needing to be called in a specific order is usually a bad code smell Can you give an example where a different design eliminates the need for the ticket pattern? | ||
| ▲ | stouset 12 hours ago | parent [-] | |
This entirely depends on the underlying problem. All I’m saying is that having a set of functions that must be called in a specific order is often a code smell. Forcing them to be called in the right order improves the ergonomics, but doesn’t eliminate the smell. If there is no shared information in the ticket other than the fact that the earlier method was called, then you’re almost certainly modifying global hidden state. If you can avoid that, all the better. If you do need to package data along with the ticket, you can just use regular structs. Which is usually better from a naming perspective anyway.
The ticket pattern is just plain old structs but with a (usually unnecessary) layer of generics. | ||