The EMA is a very handy tool. It lets us calculate an average over recent data. But, unlike a Simple Moving Average, we don't have to keep a window of samples around—we can update an EMA "online," one sample at a time.
But the perennial question is: how do you start an EMA?
First, here are a couple of wrong ways.
Continue reading "The correct way to start an Exponential Moving Average (EMA)"
In Fixing dispatch, we refactored some code that dispatched things from a switch
-statement or cascading if
-statements to dispatching by polymorphism.
This time, we'll refactor a different piece of dispatch in a completely different way, and cover another design principle.
Continue reading "Deciding once"
A fun thing about refactoring code is that after one refactor is finished, the next candidate is easier to see.
In An abstraction gone wrong, we refactored the state variable of a simple tokenizer from an integer into an object. Now that that's done, another problem is staring at us in the face. It's in this code:
if (state == INITIAL) {
} else if (state == IN_NUMBER) {
} else if (state == IN_STRING) {
} else if (state == AFTER_STRING) {
} else if (state == ESCAPING) {
}
Continue reading "Fixing dispatch"