Why is a CPU branch instruction slow?

A branch instruction is not inherently slower than any other instruction. However, the reason you heard that branches should avoided is because modern CPUs follow a pipeline architecture. This means that there are multiple sequential instructions being executed simultaneously. But the pipeline can only be fully utilised if it’s able to read the next instruction … Read more

Can Tail Call Optimization and RAII Co-Exist?

Taken at face-value, it would certainly seem like RAII works against TCO. However, remember that there are a number of ways in which the compiler can “get away with it”, so to speak. The first and most obvious case is if the destructor is trivial, meaning that it is the default destructor (compiler-generated) and all … Read more

default maven compiler setting

Create a pom-only (<packaging>pom</packaging>) project that has the compiler settings (and any other default settings) you want. You give treat it like any other project (release it; deploy it to your Maven repo, etc.). Put a parent declaration at the top of your pom files: <parent> <groupId><!– parent’s group id –></groupId> <artifactId><!– parent’s artifact id … Read more

recursive descent parser and functional programming

Answer derived from this blog article: So my question is what would a more traditional functional approach to parsing (i.e. few side effects) look like? Sounds like you need to separate functional (as in Lisp, Scheme, Standard ML, CAML, OCaml, F#) from purity (absence of side effects, as in Haskell) and incidental language features (algebraic … Read more

How do generics get compiled by the JIT compiler?

I recommend reading Generics in C#, Java, and C++: A Conversation with Anders Hejlsberg. Qn 1. How do generics get compiled by the JIT compiler? From the interview: Anders Hejlsberg: […] In the CLR [Common Language Runtime], when you compile List, or any other generic type, it compiles down to IL [Intermediate Language] and metadata … Read more