5 ms·
Although I don't work with COBOL, I do work at a financial services company and we have a lot of old software that we are not going to replace with Ruby, PHP, o
by palehose 17y ago
Although I don't work with COBOL, I do work at a financial services company and we have a lot of old software that we are not going to replace with Ruby, PHP, or any other dynamic language because the precision and accuracy of decimals and floats in dynamic languages is inadequate. I'm really surprised that the precision issue gets ignored at the native numeric level within dynamic languages.
- rleisti 17y agoRuby does have libraries for dealing with real numbers with an arbitrary precision.
- palehose 17y agoI haven't gotten very far with this issue in Ruby, however in PHP there is also a way to get around the lack of precision by treating numbers as strings and then using additional libraries to perform the necessary calculations. The ability to do this in a clear and concise manner and be absolutely certain that everything is adding up properly is not easy. From my perspective, the fact that these calculations do not perform correctly right out of the box using dynamic languages is the problem, and adding additional libraries is not the solution.
- grandalf 17y agophp != dynamic languages
- cschneid 17y agoThe last project we did with money, we just treated all amounts as integers storing the number of cents. No accuracy problems w/ whole integers, so 1000 because $10.00. Easy to do math with, and keeps it's accuracy. Might not work for hard-core financial work, since the number of decimals might be too deep for that to be efficient. (although there's nothing stopping you from saying the last 5 digits of every number is the decimal part).
- gnaritas 17y agoA better thing to do is to not use raw integers to represent money at all, create an immutable money object, use integers to represent units and a currency string (cents/USD) inside the class. Use the money as the primitive it is, giving it the appropriate numerical operations added/subtracted/multiplied/allocated. Money is not an integer, or a decimal, or a double, or any other number, Money is Money and should be represented by an appropriate abstraction of its own.
- mrduncan 17y agoAs a bonus, this strategy also makes it (relatively) simple to handle multiple currencies. By using raw integers, you never have currency information attached so it's a lot tougher (and messier) to keep track of the currency.
- arohner 17y ago> A better thing to do is to not use raw integers to represent money at all...Money is Money and should be represented by an appropriate abstraction of its own. Good point. This makes me wonder though whether it is ever acceptable to use primitive math without some kind of units, except maybe in pure math. You are always counting something, be it dollars, or people, or widgets sold, or hard drive seeks.
- gnaritas 17y agoI would depend on whether adding different units together was an error. 1 dollar + 1 euro should be an error. So raw numbers for pure counting is OK, but raw numbers for counting units of a specific measure are not OK, an abstraction should be introduced. If you just willy nilly add feet and meters you might end up missing your desired orbit and losing a billion dollar satellite.
- kscaldef 17y agoAnd, in fact, Rails translates NUMERIC fields in the database to BigDecimal values in Ruby. (You still need to be careful, though that you don't inadvertently coerce a BigDecimal to a Float in the course of working with it.)
- silentbicycle 17y agoIt isn't ignored. While I don't use Ruby or PHP, Lua and Python both have libraries for high-precision numeric computing and rationals, and the Scheme standard requires the full numeric tower. Erlang also uses them by default. OCaml has arbitrary-precision numbers in the core language, though (somewhat characteristically) doesn't use them by default for performance reasons.
- rcoder 17y agoRuby bundles Bignum and BigDecimal libraries which provide arbitrary-precision math primitives in the standard library. Python similarly provides the 'decimal' module. Most other "dynamic" languages provided at minimum bindings to the GMP library. Basically, you seem to be considering only the fast, C-based math primitives most languages offer by default, and ignoring the more powerful options available to those who need them.
- omouse 17y agoYou could work with Common Lisp. It can handle rationals, arbitrary precision, it has macros, useful debugging tools, solid environments, it compiles code on a function-by-function basis to highly performant bytecode (or machine code or C, depending on which implementation you're using). I don't know, all the cool shit you can do with Ruby, PHP, etc. can be done with Common Lisp and you won't suffer from shitty performance or inadequate meta-programming facilities.
- patio11 17y agoFor instance, in Common Lisp, you could write your own web framework and fix all those mistakes they made in the ~100 man years of Rails development. Then, you could start working on your own versions of gems, plugins, and the like. And after you get done with reimplementing the ecosystem, you can crank out a bank website in, I don't know, a weekend or so.
- omouse 17y agoIf you did even the slightest bit of searching you would find a few web frameworks, a few package managers, etc.
- Shooter 17y agoI get your point, but that is essentially what my company does. We primarily use CL for bank software (not just the website, but for payment processing/fraud detection, trading algorithms, etc.) We've also used it for occupational medicine software, PEO management systems, pension administration systems, etc. [I'm largely using the royal "we" - essentially none of my woefully bad code ever makes it into a shipping product. But signing the checks gives me some sense of involvement.] CL is a fiddly mess to get started with, and there is not as much open-source code available, but once you get going it is a very powerful tool. If you're going to make the ecosystem argument, why did you stop at Rails? Don't you develop everything in Java? It has more of an ecosystem, so surely you've abandoned those wheel-reinventing Railheads for Javaland? Or PHPistan? Or C++ville?
- 17y ago