My buddy says that he tries to program with as little if/else statements as possible, for efficiency’s sake. When I asked why he said that if/else’s take a somewhat significant part of the program’s ressources, so he tries to stay away from them.
Is he right? Are there better ways to execute if/else style code without actually using that structure? Are switch/case structures any better?
EDIT: He wasn’t referring to a specific language but more as a general practice. As well as UNIX/Linux and Windows platforms.
Typically, a compiler will represent an if/then/else construct as a test followed by a jump to another location in the code. This is a very standard and well-optimized operation for any processor. Unless you are programming in something other than the standard compiled or interpreted languages, your buddy’s conclusion is seriously flawed.
Further, optimizing code at this level without profiling it first (to find where the slow bits are) is well, ill-advised. (More like a complete waste of the programmer’s time.)