Why goto is so bad
At any place I work there are was a moment with discussion about using of break. continue and goto operators.
I read a lot about goto in books and even McConnel "Solid code" wrote about how it is bad.
And in all these places, in code styles, style guides and books, there are only one point: missing the main line of code or loosing the control.
But I belive that with correct splitting of the program to smaller parts (methods, functions, classes) and with solid architecture there are no such a big deal about loosing control by using just break or continue. Sometimes it makes code shorter and easier.
Recently I read very good article (or is this a book?) What every programmer should know about memory I found good example of why we should not use operators which lead to assembly JUMP from the real performance point of view: (here is) and it is called Prefetching.
"Code has the advantage that it is linear between jumps. In these periods the processor can prefetch memory efficiently. Jumps disturb this nice picture because
- the jump target might not be statically determined;
- and even if it is static the memory fetch might take a long time if it misses all caches.
These problems create stalls in execution with a possibly severe impact on performance. "
Of course, this is all about the total optimizations at the low lever and probably doesn't have such influence at the high level or OOP level languages. But I think this is good and useful description from the technical point of view.
Комментарии
Отправить комментарий