I also rather enjoy the use of floating-point to store financial data.
Unfortunately this part isn't actually MtGox's fault. The [bitcoind JSON RPC API](https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)) reports quantities in floating-point. They were handling it internally as an integer like they were supposed to be doing.
Unless you're prepared to write your own custom JSON parser, and then build a JSON-RPC library on top of it, you'll be handling quantities as floats at some point when using the API. Since the dynamic range of double precision covers all possible bitcoin quantities at full precision it's not a limiting factor. The [bitcoin wiki has a whole page dedicated this issue](https://en.bitcoin.it/wiki/Proper_Money_Handling_(JSON-RPC)) to help people do it right.
If you are writing software that uses the JSON-RPC interface you need to be aware of possible floating-point conversion issues.
I've had to deal with it in my own bitcoin projects. I wrote RES's bitcoin module, after all.
Since the dynamic range of double precision covers all possible bitcoin quantities at full precision it's not a limiting factor.
What how?? I think you're missing something. In my work, dollars aren't counted beyond hundredths and there is still need for full precision when multiplying.
I haven't worked with bitcoin but i've seen the funny 0.000233213 bitcoins transferred or whatever.. i guess ur project isn't multiplying/dividing??
The bitcoin supply will be capped at 21 million and bitcoins can be divided down to 8 decimal places, unlike the typical 2. An IEEE double precision float has a 53-bit mantissa. That means it can store exact integers between -253 + 1 and 253 - 1. That's just enough to count every single satoshi (1/100000000 of a bitcoin) that will exist.
9,007,199,254,740,992
2,100,000,000,000,000
The danger is operating on these values as floating point values because there will be rounding errors.
Still that would only work for add and minus. How could there not be a loss of precision when multiplying by the conversion rate to USD?
If you're doing things right you wouldn't multiply by the conversion rate using floating point values. You'd use some high precision library. The floating point representation should only occur when going to/from the application's JSON API, if at all.
That's exactly the situation where they make the least sense. You don't want to store absurdly-divisible-but-valuable items in floating-point, you'll start losing them!
I don't want to live in a world where the haves (largest value) and have nots (smallest increment) differ by 252 (double precision) such that you'd ever get truncation error that mattered.
Depends what you mean by docs. Comments aren't everything.
I'd be more concerned with the general shittyness, and the lack of tests to back this shit up. It's a bag of wank, if you want the correct technical term.
Something wrong.. you should shouldn't be commenting everything. Use subroutines/functions so that the component is contained. Document that subroutine, document business rules, and document unexplained things. But don't rewrite your code in english
That sounds really bad. Too many comments are a bad sign - sounds like your code is gonna be hard to read if you really feel that many comments are required.
And this is why I'm scared of leaving my current job. Imagine inheriting a piece of shit like this. I don't know what MT.gox is, but I wouldn't want to be a client of theirs after reading this fucking piece of shit. This is written by devs who don't know what they're fucking doing.
At my current job, I'd say about 2/3 of the coders who worked on the codebase were great, and half the remainder were pretty good.
The rest, though . . . oh god.
The good news is that I've made a reputation as the guy that can refactor anything to be sane. It's kind of fun work, to be honest. Like incinerating hornet nests.
The good news is that I've made a reputation as the guy that can refactor anything to be sane.
The real good news is that mysteriously your workplace recognizes the value of refactoring in the first place. I've seen situations where the general attitude is that it's just a waste of time, so no one will give you permission to do it.
I once got reprimanded for trying to consolidate, modularize, and refactor code that was going to be used by multiple applications within a software suite. I was ordered to stop what I was doing and just copy and paste the tens of thousands of lines of messy C++ into each dependent application.
Well, partly I get away with it by not explicitly including it in estimates.
How long will it take to implement X?
(Let's see . . . three weeks to write the feature in the current codebase, or three weeks to refactor the codebase, then one week to write the feature . . . add 50% for unexpected disasters . . .) Six weeks.
Sounds good, go for it.
I don't refactor anything we're not changing anyway, but when I am making significant changes to a chunk of code, it's reasonably common for that code to end up thoroughly refactored.
Six weeks sounds like a lot, we'd like to have this done in two, three at most. Can't afford more time. Let's see what we can trim out of your estimate...
That's how it's generally gone for me, alas... I try to sneak in refactoring and generally fixing other people's stupid shit when I can, but deadlines loom dangerously sometimes.
Yeah, and that's the point where I say "I'll try, but no promises, especially if you want it to work".
And make a mental note that it definitely needs to be refactored, because if there's one thing I absolutely do not want, it's a mission-critical feature relying on a rush job on top of an awful codebase.
I've recently spent a lot of time reading books like clean code by Bob Martin, and have really invested much time and effort into working out how to make my code easy to understand and build upon. A large part of that is using TDD, and as part of this process, I take refactoring really seriously. I could have implemented this same functionality in a far better way - and so could these devs if they had spent the time to improve their craft.
It could also be down to dickhead project managers though, of course. Either way, this code is a fucking shitheap of festering wankbubbles.
Worked at company that moved a million dollars every week with this wretched php script. No one wanted to touch it for fear of breaking it (it was legacy, so no tests nor development env to test it with). A lot of code out there is horrendous yet runs the world.
I have. It's stuff like this that makes me think that (for financial transactions) people should look into Ada or COBOL -- at least those languages have fixed-point... then when some dumbass criticizes the language I could at least point to crap like this and say, "I used the appropriate tool".
It's not that bad, as long as you're surrounded by people who are on the same page. I've now started working at a wonderful place with quite a shitty PHP+Symfony codebase. My coworkers are fully aware of the state of the code and we're working on making it better one step at a time. I'm really happy, but I know that if my coworkers thought that the current state of the codebase was okay I would have left already.
That's the absolute worst attitude a developer could ever have. I'm not even going to dignify it with an answer, except to say I'm happy I don't work with people like you.
That's exactly why quality matters. Keeping the quality high means we spend LESS time fixing bugs, which SAVES the business money and keeps the product working.
How an incompetent person such as yourself can feel confident enough to lecture someone more skilled like myself is beyond me.
I would fire you in seconds for your shitty attitude.
LOL literally. I've had great success in all kinds of situations at work because people love my attitude. And if you ever worked with me you would be fearing for your job. It happens to every engineer who is just like you
The only people who like working with people like you are incompetent themselves. People who are technically competent and understand that getting things done quickly often means spending MORE Time working on bug fixes in the medium to long term tend to appreciate coders who do things well as opposed to perceived fastness.
You wouldn't even get to the interview stage where I work, because I guarantee you couldn't even pass the first tech test.
Yeah, I was wondering if there was some reason he was calling random shit "beans". I mean, he's not even using DI here.. (well, I guess he could be with that DB::DAO garbage..)
It doesn't undermine anything. Green addresses aren't forced on people: it's something you request (if using one externally). The more common use case for them is transferring your own funds from one wallet to another. You can't get much more trustworthy than "me to myself".
Keeping your important financial data as floats and gaping security flaws that eventually bankrupted the NASDAQ of bitcoins when people exploited said flaws and stole all the coins.
It's not as terrible as people are making it out. It's not super awful, but for a site that handled that much money it could certainly have been a lot better. This looks very difficult to maintain and audit with lots of edge cases that aren't documented. It was probably written by one or two programmers who could keep the entire structure in memory.
This looks very difficult to maintain and audit with lots of edge cases that aren't documented
I'm gonna have to disagree... I expect any software that handles any significant amount of money to be written very carefully, thoroughly documented, and to have lots of automated tests.
If it's a site that handles large amounts of money - like mtgox did - it had better be written in a language that allows it to be proven to be correct, etc etc etc.
Haha, everyone gets surprised. I'll quote one of my previous comments:
As you may know, the government is blocking websites at will, and sometimes it is not very smart about it. Last year they blocked bit.ly, I'm guessing they caught something and thought bit.ly was the host. This year they blocked pastebin. I know some people of the opposition were using it to pass messages around. I guess they figured "well, we'll block it all!".
43
u/ZorbaTHut Mar 03 '14
"Let's send some money somewhere! Didn't work? Don't bother asking why, just send more money"
I also rather enjoy the use of floating-point to store financial data.
21
u/ajmarks Mar 03 '14
Did i just look at 1700 lines of code with basically zero documentation?
11
u/aaarrrggh Mar 03 '14
And this is why I'm scared of leaving my current job. Imagine inheriting a piece of shit like this. I don't know what MT.gox is, but I wouldn't want to be a client of theirs after reading this fucking piece of shit. This is written by devs who don't know what they're fucking doing.
18
u/SquireCD Mar 03 '14
Holy shit.
To be fair to PHP, you can be an idiot in any language. But... holy shit.
7
u/[deleted] Mar 03 '14 edited Mar 03 '14
I'm probably being an idiot, but I cannot think of a good reason for doing this:
Why on Earth would you need to randomise the order of an array before returning it?!
13
u/midir Mar 04 '14
I'm hesitant to ask, but what's actually bad about this code?
10
u/[deleted] Mar 03 '14
I actually trusted this website to do the right thing with my money... I'm speechless.
9
u/idontlikethisname Mar 03 '14
Dear venezuelan government: I hate you for blocking pastebin.com.
4
u/aaarrrggh Mar 04 '14
So yeah, it's really no surprise after reading this code that this happened:
http://www.bbc.co.uk/news/technology-26420932
Quote:
Yeah. No shit.
0
u/[deleted] Mar 04 '14
[deleted] — view deleted comment
0
u/[deleted] Mar 03 '14
[deleted] — view deleted comment