|
|
05.17.2005 |
|
||||||||||
| Programming Sloppiness | ||||||||||||
I've been a computer geek since a boy, and thoughts related to computers and software engineering get dropped here for the benefit of humanity and my own hubris.
|
I like to “sigh” along with an engineer that works with me. We roll our eyes especially at Java programmers, but I’ve seen the same laziness exhibited by Perl, PHP and other scripting languages; however, it is especially noted with Java programmers. Back in my younger days when I coded mostly in C, we had to not only manage our memory, but we had to do a lot of boundary checking and whatnot. Stack and buffer overflows were a common symptom of “programmer laziness.” But newer languages like Java now check for this sort of thing, so if a user gives me an input string that is too long, the Having the language do such lovely things like boundary checking and memory management lulls many programmers into a false sense of complacency. For instance, consider this code example: public byte[] myBlob(String s) {
byte[] blobBytes = new byte[s.length()];
for (int i = 0; i < blobBytes.length; i ++)
blobBytes[i] = (byte)s.charAt(i);
return blobBytes;
}
See anything wrong with this code? What if the While I’m up here, allow me to do a hand-stand on this soap box— NPE’s are quite useless. If calling your method with a null is incorrect, it would be better to throw a new, more helpful exception than to just let the NPE surface. So boys and girls, even if you are writing the client that is calling your code, at least check your inputs on your public methods… Come back next week for another rant… er, tip. Thought originally posted on Tuesday, 17 May 2005
© 2005, Howard Abrams • Except where otherwise noted, all original content is licensed under a Creative Commons License (see details). |
|||||||||||
|
||||||||||||