Nested functions pros and cons


#21

That will most likely not SIMD either. @simd is not a magic command that makes the code go faster, it does a very specific thing. It enables fast mode math on reduction variables inside a loop so that the compiler is allowed to do floating point accumulations in arbitrary order.


#22

Thanks for the reality!
Ok, I think I’ll stick to returning failure status and the actual result (or a dummy one if it failed).


#23

You cannot. Julia’s goto is limited to within a single function.


#24

I suspect that most of this comes from Dijkstra’s “Go To Considered Harmful” essay, which people read and parrot without understanding the context. At the time this paper was written, structured control flow was a brand new concept and goto was how all control flow was done in practice. Dijkstra was trying to convince people to use structured control flow at all not convince them that they shouldn’t ever use goto.

The occasional, judicious use of goto is just fine, but (as always) consider the alternatives. If I can use a couple of gotos and have much clearer simpler code, that’s way better than writing the same thing with no gotos but a nasty, unintelligible mess of structured control flow—and there are some cases where this is the choice. The whole argument against goto was that unbridled use of it lead to complex unintelligible code, but readability and maintainability is the end goal by whatever means.


#25

Just reporting back: I decided to implement a structure where functions return a result or nothing (depending on success/failure). This works really well because I could split functions into two, where the second part would have two methods, one for the real result and one short circuiting in case the type of the argument was Nothing. This cascades all the way through and felt pretty natural. I’m very happy with the end result, even though I’m not sure if this boosted the speed or hampered it.
Thanks for all the help!