CodeSOD: Trimming the Fat |
There are certain developers who dont understand types. Frustrated, they fall back on the one data-type they understand- strings. Dates are hard, so put them in strings. Numbers arent hard, but they often exist in text boxes, so make them strings. Booleans? Well, weve come this far- strings it is.
Tyisha has the displeasure of working with one such developer, but with a twist- they didnt really understand strings, either. Tyisha only supplied a small example:
string RequestDate = dteRequestTB.Text.ToString().Trim();
string valid = string.Empty;
string Format = "yy/MM/dd".Trim();
valid = Dates.IsDateValid(RequestDate.Trim(), Format.Trim()).ToString().Trim();
if (valid == "False".Trim()) {
...
}
Now, IsDateValid does more or less what youd expect- it takes a date (as a string) and a format (as a string), and returns whether or not the input date matches the format (as a boolean).
Tyishas co-worker, of course, converts it into a string before comparing. This is dumb, but nothing we havent seen before. For a bonus, theres absolutely no consistency in variable naming conventions. Theres the mix of pascal case, lower case, and a splash of Hungarian notation.
The real magic here, however, is that this co-worker isnt simply happy calling ToString on everything, but instead needs to also Trim those strings. In fact, they call Trim on every string. Everywhere.
[Advertisement]
Atalasoft’s imaging SDKs come with APIs & pre-built controls for web viewing, browser scanning, annotating, & OCR/barcode capture. Try it for 30 days with included support.
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |