Sunday, June 9, 2013

JIT compiling

Java is frikin fast now and in some cases it can be faster than C/C++. A large part of this is due to the Just in Time compiler (JIT). As it sounds, the Java JIT compiler does not compile all of the bye code at once. Instead it will analyze the code while it is running and figure out which chucks of code are frequently executed. Then it goes ahead and optimizes this code. Because it doesn't need to spend resources compiling code that is not run often, it can devote resources to compiling and optimizing the stuff that matters.

Why doesn't Python use curly braces(for blocks of code)?

If you've used Python at all you know that it uses indentation to denote blocks instead of curly braces. Theres a couple reasons for this but it boils down to the Don't Repeat Yourself(DRY) principal.

How is using braces repeating yourself?

Well you've probably worked in a language that relies on braces for scope since most of the most common languages do this (Java,C,C++, Javascript, PHP,etc.). When working with one of these languages have you ever had to refactor legacy code that wasn't indented properly? Although the code has braces, we can't easily figure out what is going on. Where does one method end and the other one begin? The first thing you probably did was use the auto-indent feature in your trusty IDE so you could at least get a high level idea of the format of the code.

So it ends up that those curly braces didn't help you much. And they shouldn't because they really aren't for you. They are for the compiler. You see blocks of code in terms of indentation. The compiler interprets blocks of code based on braces. There's no reason to have both.