▲ | brabel 9 days ago | ||||||||||||||||
That’s only true in languages that do not have Algebraic Data Types and pattern matching, which nowadays is a minority of languages (even Java has it). | |||||||||||||||||
▲ | cyberax 9 days ago | parent [-] | ||||||||||||||||
Visitors additionally allow you to decouple graph traversal from the processing. It is still needed even in the languages with pattern matching. There's also the question of exhaustiveness checking. With visitors, you can typically opt-in to either checking that you handle everything. Or use the default no-ops for anything that you're not interested in. So if you look at compilers for languages with pattern matching (e.g. Rust), you still see... visitors! E.g.: https://github.com/rust-lang/rust/blob/64a99db105f45ea330473... | |||||||||||||||||
|