Earlier today I read a blog-post titled Of Debt And Decisions. It got me thinking...
I know that I tend to be a perfectionist. I want my code to be perfect both in functionality and style. Bug-free, fast and well-coded. And that's how it should be. Right?
Every now and then someone will say that we need more programmers. That every child should learn to program in school. That programming is the new writing.
In every field you will have a few people who are at the very top of their profession, more who are just good, even more who are average, and yes, you will also have some people who plainly suck.
Let's face it, not everyone is suited for every job. Just as most programmers will suck at being a salesperson or an actor or a physician or a lawyer, so will most lawyers or actors or salespeople suck at being programmers. There is a finite supply of people who are suited for any given job.
I was refactoring some code. After the change it didn't work as intended. There was no error-message, the code just didn't do what it was supposed to do. At first I thought it was because of some floating-point problem, but it wasn't.
Today I read on a mailing-list that someone is planning to release the code to a small app as open-source, but he needs to clean it up a little bit before he does that.
This is going to be a dry and boring post. Seriously. If you don't want to waste your time, just go away. I mean it. Hmm... you're still here... well, don't say I didn't warn you... :)
In my previous post I compared the performance of Node.js 0.10.35 and io.js 1.0.2. Since both relased new versions - Node.js 0.11.15 and io.js 1.0.3 - just yesterday, I thought I should retest. (Hmm... both released new versions on the day after my blog-post... I'll just pretend I'm innocent... I probably am... Yes, I'm certain... And I'm gonna stick to that story, no matter how long "they" will interrogate me...)
tl;dr - Depending on whether you use Node.js or io.js, you may experience performance differ by a factor of more than 5 for identical code.
[Update 21-Jan-2015: There is now a new blogpost that compares Node.js 0.11.15 and io.js 1.0.3. It also gives additional data and an explanation why io.js 1.0.2 performs so poorly in one of the tests here.]
First of all, let me make something clear. This is not, and cannot be, a comprehensive test. Every application is different. Depending on what your Node application does, my findings may or may not apply to your use-case.
We all know that we should frequently refactor our code, so that it stays in good shape despite all the things we changed or added.
So let's show up hands who of us actually does this? Oh... only a few out of all the people here? Just what I thought... :)
Hmm... how can we actually get this done, then?
While writing yesterday's blogpost, I noticed that I have several places where I load templates for blogposts, index-pages, RSS-feeds, whatever.
And I also noticed that each time the code is several lines long and that a lot of it gets repeated every time.
Let's take a look at one example:
Today let's take another look at
At the end of course is the initialization-code. Above that is the
which checks what the user wants to see, and then sends the request further down the line.
And we have
First thing we notice is that
handleBlogIndex() does a lot of
stuff which is not just routing further processing, but which is actual processing.
Well, that doesn't belong in this file. It's on a different level of abstraction. So let's move
it to its own file
In my endeavour to make the code for my blog-engine better, I will start
with the main file,
blogforum.js. Everything starts here. So I may as well
start here too. :)
Let's begin with some code-cleanup. And by that I mean eliminating some
console.log() statements which were used for debugging and have since then
been commented-out. No need to keep those.
If you want to see what I can do in Pascal, take a look at this: deusu.org
BTW: The sourcecode I wrote for the search-engine technology behind DeuSu is on GitHub. It is named OpenAcoon as DeuSu's predecessor was named Acoon.