Jason Knight
1 min readJun 21, 2022

--

Laugh is most of what I thought was wrong had nothing to do with its shortcoming, and the problem you said being more a n issue of why I don't use Java a whole lot, and find it to be one of the bigger s***-shows when it comes to programming.

First thing I noticed was all the variables for nothing before a return. Second thing I noticed was this bizarre use of "equals" to do ==. Third thing I noticed was the use of "BigDecimal.zero" for nothing. Then the asterisk-9 making no sense at all, the lack of inversion in said regex,

As you said there are many answers. My rewrite of such a function would be:

public static boolean isZero(String tipAmount) {
return
tipAmount.isEmpty() ?
0 :
Float.parseFloat(tipAmount.replaceAll(“[^\d.]”, “”) == 0;
} // isZero

Again Java suckage that we have to test for the empty string since parseFloat of an empty string throws an exception. I think, again I’m not much of a Java guy… though I can fake it in a pinch.

--

--

Jason Knight
Jason Knight

Written by Jason Knight

Accessibility and Efficiency Consultant, Web Developer, Musician, and just general pain in the arse

No responses yet