Article 5PJDN CodeSOD: The Programmer's Motto and Other Comments

CodeSOD: The Programmer's Motto and Other Comments

by
Remy Porter
from The Daily WTF on (#5PJDN)

We've got a lovely backlog of short snippets of code, and it's been a long time since our last smorgasbord, so let's take a look at some... choice cuts.

Let's open with a comment, found by Russell F:

//setting Text="" on the front end some how stoped a error on tftweb-02a on prealpha it may have also needed a new compiled version//but after two + hours it doesnt work and i am not shure i acutal did anything

"After two+ hours, it doesn't work, and I'm not sure I actually did anything," describes the experience of being a programmer so well, that I honestly think it's my new motto. The key difference is that, if it doesn't work after two hours, you do have to keep going until it does.

From an Anonymous submitter, we have:

[Required(ErrorMessage = "This field is required."), ValidateMaxLength(Length = 10)][Range(typeof(bool), "false", "true", ErrorMessage = "Enter valid value.")]public Nullable<bool> Nonbillable { get; set; }

Now, this is probably actually correct, because it's possible that the underlying data store might have invalid entries, so marking a Required field as Nullable probably makes sense. Then again, the chance of having invalid data in your datastore is a WTF, and apparently, it's a big problem for this API, as our submitter adds: "Looking at a very confused public-facing API - everything is like this."

"R3D3-1" was checking a recent release of Emacs, and found this function in python.el.gz:

(defun python-hideshow-forward-sexp-function (arg) "Python specific `forward-sexp' function for `hs-minor-mode'.Argument ARG is ignored." arg ; Shut up, byte compiler. (python-nav-end-of-defun) (unless (python-info-current-line-empty-p) (backward-char)))

"Shut up, byte compiler". In this case, the programmer was trying to get an "unused parameter" warning to go away by using the parameter.

"R3D3-1" adds:

The comment made me chuckle a little, not a major WTF.
The correct solution in Emacs Lisp would have been to rename arg to _arg. This would be clear to not only the byte compiler, but also to other programmers.

And finally, a frustrated Cassi found this comment:

// TODO: handle this correctly

Cassi titled this "So TODO it already!" If you're writing code you know is incorrect, it might be a good time to stop and re-evaluate what you're doing. Though, Cassi goes on to add:

I suppose it could be argued, since I'm only coming across it now, that this comment was a good enough "solution" for the five years it's been sitting in the code.

Perhaps correctness isn't as important as we think.

proget-icon.png [Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more. TheDailyWtf?d=yIl2AUoC8zAhCAFEanDKno
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments