In case you didn’t already know, 10gen, the company behind MongoDB offers free online classes for developers and DBAs that want to become familiar with their DB. I took and completed the M101P course (the P stands for Python, although you don’t need to know Python to take the class) and if you want to learn more about how to work with MongoDB, I strongly suggest you take the course when it next starts. You can find more information on the courses on education.10gen.com.

M101P certificate

Wikitten

Lately I’ve been looking all over the place for a small, fast personal wiki that I could use to store my notes, ideas and code snippets. I’ve tried a lot of solutions, but none of them really fit my peculiar needs, so in the end I’ve decided to do what every developer does from time to time – reinvent the wheel.

Enter Wikitten, a PHP self-hosted Wiki that parses Markdown documents and code snippets and displays them in a friendly, clean manner. No database necessary, simply drop it somewhere where Apache can run it, and you’re good to go:

dbv.php: Database version control, made easy!

Over the years, I’ve developed quite a few tools that make my life as a developer easier. These range from simple scripts to full blown automatic deployment software, and it started to dawn on me that it would be nice to share these tools with the Open Source community.

One of the more useful tools I made, is dbv.php, a database version control application that makes it easier for teams of developers to make sure their local databases are always in sync with each other. If your database hasn’t been under version control until now, it should be.

Without further ado, head over to the project website to read about the application’s features, documentation and download links!

Why doesn’t 0.7 + 0.1 == 0.8 in [PHP/JavaScript/etc.]?

Despite this issue having been addressed countless times until now, a variant of this age-old question still pops up on StackOverflow on a weekly basis (at least), and since I’ve bumped by own head into it before, I figured writing this down one more time couldn’t hurt, right?

The in-depth explanation for why programming languages cannot properly handle floating point precision has been too well-documented before for me to repeat it here. I strongly suggest reading What Every Computer Scientist Should Know About Floating-Point Arithmetic, but if you don’t have the time or inclination, here is a small quote from the PHP documentation on floating point precision:

[…] rational numbers that are exactly representable as floating point numbers in base 10, like 0.1 or 0.7, do not have an exact representation as floating point numbers in base 2, which is used internally, no matter the size of the mantissa. Hence, they cannot be converted into their internal binary counterparts without a small loss of precision. This can lead to confusing results: for example, floor((0.1+0.7)*10) will usually return 7 instead of the expected 8, since the internal representation will be something like 7.9999999999999991118…

So never trust floating number results to the last digit, and do not compare floating point numbers directly for equality.

The warning at the end of the quote is, of course, doubly important when you deal with numbers that represent money and prices.

The solution

Thankfully, PHP provides a set of math functions to handle arbitrary precision operations and comparisons. The example at the top of the page would therefore become:

A lot wordier, I know, and more difficult to read, but guaranteed to provide precise results that you can count on.