Roberto Aley

menu

Blog

Why Use Integer In Finance

12/7/2022

I have implemented multiple payment processors in the past, and a rule I always follow is to use integers for all the currency calculations. The reason is simple. Floating-point arithmetic is not accurate.

And if you read the IEEE 754, it can be surprissing how innaccurate floating-point arithmetic is.

Floating point allows us to approximate all the values between a range due to its special encoding, but it cannot possibly represent all the numbers in that range and not even all the integers in that range.

Even though floating-point has its drawbacks, we may still want to use it to solve many computing problems where floating-point works and we accept its compromises.

However, this innaccuracies are a problem and as software developers we must understand how this encoding works and still produce correct results in our applications.

How real values are represented?

When we want to stor...

Expanding subdirectories in a batch file

8/24/2021

When I am working on C++ projects the way I compile my projects is by creating a shell script or a batch file and compiling the whole project every single time. Many C++ developers might not like this approach arguing that it increases compiling times substantially but in my experience this is not an issue if you write code in a sensible way without abusing features like templates and many other ways you can help the compiler be faster when compiling your code. The other approach is to use some build system like GNU Make or any of the other existing solutions. I find the script approach simpler even though it has its caveats like the one I'm going to talk about.

If I'm compiling on Windows I need to pass the .cpp files to MSVC compiler so it know where the definitions of my functions are, something like this:

cl src\\\*.cpp

and this will work if you have all your .cpp files in src/ in this case. But if yo...

A Case For Reduce Part 1

6/6/2021

JavaScript provides many useful functions to loop through an array and execute an operation on each element of the array like forEach, filter, map, reduce, find, some, every and many more.

Filter and map are generally over while forEach and reduce are not only less used but reduce also receives a lot of hate for "making" the code harder to read and not being useful at all.

During my career as a developer I have learned about clever and useful ways of effectively applying reduce and making it an important tool to have in your belt as a programmer. Regardless of the programming language that you use, it is important to learn the tools that your language offers and make them work to solve the problems that you are facing as a programmer.

So my plan with this post is to ma...