Re:Show HN: CPU simulator in 60 lines of code
by wkoszek on Tuesday October 13, 2015 @02:46PM
(#10382566)
Quick, dirty and primitive was my primary motivation for this exercise :-)
Re:Show HN: CPU simulator in 60 lines of code
by rootlocus on Wednesday October 14, 2015 @04:08AM
(#10385479)
How would you rewrite it to "tighten it up"?
Re:Show HN: CPU simulator in 60 lines of code
by mtdewcmu on Wednesday October 14, 2015 @08:25PM
(#10390515)
I would make that series of if-statements more obviously deterministic, for starters. One way of accomplishing that would be a bunch of nested if-else blocks. However, that would be ugly. I'd prefer something like continue statements -- which would necessitate redesigning the loop to avoid bypassing the code at the bottom. Either way, the way this currently gives the appearance of being possibly nondeterministic makes me uncomfortable... and besides, executing those extra conditionals wastes CPU cycles.
Personally, my inclination would be to rewrite the loop to tighten it up. But maybe the point was to show how quickly and dirtily one can do this... it definitely looks quick and dirty.