Can knowing C actually hurt the code you write in higher level languages?

Neither knowing C nor knowing the lower-level details of implementation hurt you — in themselves. What can and will hurt you is if you consistently think and work in terms of the low-level details, even when it’s inappropriate. The old saying was that “real programmers can write FORTRAN in any language.” If you do the … Read more

x > -1 vs x >= 0, is there a performance difference

It is very much dependent on the underlying architecture, but any difference will be minuscule. If anything, I’d expect (x >= 0) to be slightly faster, as comparison with 0 comes for free on some instruction sets (such as ARM). Of course, any sensible compiler will choose the best implementation regardless of which variant is … Read more

Which “if” construct is faster – statement or ternary operator?

There’s only one type of “if” statement there. The other is a conditional expression. As to which will perform better: they could compile to the same bytecode, and I would expect them to behave identically – or so close that you definitely wouldn’t want to choose one over the other in terms of performance. Sometimes … Read more

When is optimisation premature?

Don Knuth started the literate programming movement because he believed that the most important function of computer code is to communicate the programmer’s intent to a human reader. Any coding practice that makes your code harder to understand in the name of performance is a premature optimization. Certain idioms that were introduced in the name … Read more

Are Java static calls more or less expensive than non-static calls?

First: you shouldn’t be making the choice of static vs non-static on the basis of performance. Second: in practice, it won’t make any difference. Hotspot may choose to optimize in ways that make static calls faster for one method, non-static calls faster for another. Third: much of the mythos surrounding static versus non-static are based … Read more

tech