by draganm · 5y ago · 0 comments
message_handler = {type_0, type_1, ..., type_999}; // imagine it being generated
message_handler[message.type](message);
In the case of computed go to in Fortran, it's similar. I had the "pleasure" of maintaining this once. It's been a while so I had to look up the syntax, IIRC it used something like a dispatch tree and dispatched off each digit in the type but I could be wrong: go to (0, 100, 200, 300, ...), message_type / 100 -- integer division
0
go to ...
100
go to ...
200
go to ...
... //pseudocode
map(f, ns)
for i in (0 .. ns.length - 1)
f(ns[i])The key lookup in dict definitely has conditionals, though.
Of course, the guy could get rid of that by just using an 11-element array and addressing directly instead of hashing integers as keys.
And how does the iterator know that it should raise an exception? A conditional.