Search blog.co.uk

  • The myth of BigDecimal

    "A little learning is a dangerous thing; drink deep, or taste not the Pierian spring: there shallow draughts intoxicate the brain, and drinking largely sobers us again." (Alexander Pope)

    The words of this famous English poet never sounded truer in my ears than when I read for the N-th time some poor soul pontificating on the Internet on how double precision numbers are imprecise, BigDecimals are so much better and you should always do financial calculations with BigDecimals (or some other language's equivalent of this Java arbitrary precision number class).

    Wrong, wrong, wrong.

    IEEE 754 floating-point numbers, among which we find our doubles and floats, for all their flaws, are an amazing thing. There is a reason why they are used so much more often than the arbitrary precision numbers - they offer an excellent compromise between speed and accuracy. Almost all scientific software uses floating-point numbers. Contrary to the popular misconception, they are also used a lot in financial calculations, the exception being the accounting of actual cashflows, where special rounding rules apply and you need to represent numbers like 2.11 exactly, without any possibility of an error. However, nobody who is sane will bother to use Java's BigDecimal to price an option, it just doesn't make sense.

    Also, the accuracy of arbitrary precision numbers is lost whenever you perform any non-trivial calculations, like calculating a sine or cosine. In general, there is no way to do it exactly on a computer, and any precision you gain by avoiding floating-point numbers is lost. The fact that people recommend BigDecimal or C#'s System.Decimal to compute a square root using Newton's method (which does not compute the square root digit by digit, but as a converging sequence of approximations), shatters my belief in human intelligence. I prefer to use IEEE double numbers, knowing that I can trust only so many digits of the final result, than live with an illusion of arbitrary precision which just isn't there. Say nothing about the performance hit.

    Arbitrary precision arithmetic is very useful in some cases, but please don't answer any question "why is 1.0001 - 0.0001 == 1 not true in Java/C/C++" on the Internet with "because floating-point numbers are broken, use arbitrary precision libraries".

  • In defence of open plan offices

    A very popular notion on programmers' foras is that developers and other "brain workers" need "offices with door that close" to be productive. I beg to disagree. I have worked for five years on my PhD in an office with 3 other guys, often working alone because we didn't had to come to the office every day. I have also often worked alone at home. Guess what, I had problems concentrating on my work. Internet access means that you're never truly "alone", that the office door are never fully closed.

    On the other hand, I work now in a typical London financial company: there's about a hundred of us on a floor, only a handful of top-level executives have their own offices, all others sit together: managers, analysts, salesmen and developers. I am much more productive than when I was working in the small room, because:
    - the presence of so many other people working motivates me not to slack off
    - I have a good manager who's keeping the atmosphere in the team healthy and doesn't annoy me when I am getting the work done
    When I first saw the office, I was devastated and thought I would never be able to concentrate in such conditions. It turned out not to be the case. As long as the stuff is interesting and the atmosphere in the team encourages is that of work, not laziness -- it is quite easy for me to "get in the zone".

    In my opinion, the major source of distractions is often inside us. We like to blame working conditions directly, but perhaps the source of the distractions is a) our general propensity to be distracted, mostly by Internet surfing and b) our dissatisfaction when we feel we are not being provided by the employer with what we deserve to get, in terms of working conditions. I've found that I *will* get annoyed if the conditions do not fulfil my expectations. That is, I -- and many other people -- expect air conditioning to work, for example. When it was broken, all my team was complaining and our productivity suffered. If only the developers were not given private offices, we would feel unjustly singled out and our productivity would suffer. But as things like air conditioning, bathrooms etc are operating, and almost everyone on the floor has the same type of desk as me (including my manager, his manager, and their MD), we don't have the psychological problem of feeling neglected and the source of distraction is removed.

    I am not saying that open plan office is better than small offices with doors. Certainly not. But they're not as bad as they are made out to be, IMHO.

  • Cool lemur photos

    Here

  • End of an era

    I have recently dusted off my copy of Neverwinter Nights 2 and started playing. Trouble is, at the same time I have Fallout 3 installed, so I can make a direct comparison of the two titles. They are very different. One of them represents an era of CRPG's which has come to an end.

    You've guessed right, it is NN2 which did not stand the test of time. Obsidian Entertainment have put a lot of effort in making a great storyline and nice graphics. However, when contrasted with the open-ended gameplay of Bethestda's game, NN2 feels like a prison cell. No, you can't go this way. No, you can't avoid fighting this guy. Behave yourself. Adding witty conversations (there is more text in NN2 than in F3) didn't help much. You can read the dialogue only this many times without getting bored.

    I think that the contrast between these games is a contrast between being told a story (NN2) and being immersed into it. F3 lets my imagination run wild. And there are cool headshots, too.

Recent posts

Footer:

The content of this website belongs to a private person, blog.co.uk is not responsible for the content of this website.

"Integrate the javascript code between and : Integrate the javascript code in the part :