Monday 18 January 2021

Using Optional to prevent NullPointers In TrainWrecks

I don't usually post or comment on StackOverflow, but I thought I'd give it a stab.

I was thinking of using Optional.ofNullable to be able to "map" my way out of a sequence of NullPointers more or less cleanly, but I failed to get something nice.

I really like the solution give in the Answer, it's not something that would naturally occur to me.

References

StackOverflow - Using Optional to prevent NullPointers In TrainWrecks
https://stackoverflow.com/questions/65631864/using-optional-to-prevent-nullpointers-in-trainwrecks

Friday 8 January 2021

Branch Prediction

I accidentally came across the following question1 (and consequent answer) on StackOverflow, and it is awesome!

I knew these things existed, but never put two and two together.

Unfortunately, of course, if you have to sort the array prior to the work to gain the speed, you're unlikely to speed up the process "in total".

References

[1] StackOverflow - Why is processing a sorted array faster than processing an unsorted array?
https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array
Wikipedia - Branch predictor
https://en.wikipedia.org/wiki/Branch_predictor