The Daily WTF
Emma X maintains some software for a company that does mechanical engineering. In this specific case, her software needs to match a part on their equipment to a tube which can hold the part. They’re operating on the order of millimeters, so the smallest tube is about 8mm, and the largest is 155mm.
Now, obviously, not every possible millimeter size is possible- from 8mm to 58mm, the possible diameters all proceed at a step of 2mm. Between 60mm and 95mm, the step is 5mm, and between 100 and 150, the step is 10mm. As I describe this problem, you’re probably imagining a lookup table of some kind, or maybe just a list of possible diameters generated by for loops or some similar construct. If that were how this worked, the code wouldn’t be there.
fun tubeDiameter(partDiameter: Length): Length { val partDiameterWithBuffer = partDiameter + 0.001.toBigDecimal() val res = when {
To read the full article click on the 'post' link at the top.