- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Well The I guess it's time to confess the biggest WTF i have made to day, and it was along the lines indicated above.
Some 8 years ago I was making an integrated process control and data acquisition system in Perl. We used Perl as it made it easy to use web interface for the control system as well as the data acquisition.
Well in that process I made a bit utility module including various functions (web controls, data location directory information, user identification etc., Yes I know now it is not a good idea to just glob things in a big pile).
I needed an error log function (logging if a file could not be opened for instance), and as it would be used quite a lot of places, i called it just log() which returned 0 or 1 depending on if it was successful in writing the information to the errorlog.
I'm sure you can see where this goes and I which I could that then. Things worked fine for some 6 months before I needed to make some data processing scripts to make some calculations on the data. I still needed some functions from the library, so I just included it as I always did, and as I was now doing math, I needed the natural logarithm of the result of a division, come along the log function in Perl right? :-)
Took hours to find out why the results was slightly off what they should have been.......
I had to use an external logarithm program to circumvent my own stupidity before I had the time to do it right.....
Yours Yazeran
Plan: To go to Mars one day with a hammer.
Admin
I'd suggest the following improvement, right before the first statement:
logFile.debug("Logging informational message."); logFile.info("START: Assigning variables.");
It's necessary for the case where the logFile.info() method contains a bug.
Admin
Admin
What is REALLY fun in MS Access 2003 is when just stepping through code fixes it.
Admin
I'm sorry. I attempted humour hear, but in retrograde, it failed.
Admin
Google "scare quotes" and you'll get plenty. Here's an excerpt from the Chicago Manual of Style's chapter 7.55:
Not saying that it's imperative to use the quotes, but notme wasn't pulling that rule out of his/her ass.
Admin
I'm sorry, I attempted humor there, but it just didn't work out.
Admin
FTFY
Admin
logFile.debug("Setting timeout to 999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999 9999999999999999999...");
Admin
What, like the back of a Volkswagen?
Admin
The WTF isn't the logging, it's manually instrumenting the code (and all the unnecessary comments).
In .NET you can log entry, exit, and arguments of desired methods without changing the code using PostSharp (http://www.sharpcrafters.com/). This code looks like Java; I suspect AspectJ would do the same thing. AOP (Aspect-Oriented Programming) is perfect for this.
Admin
While it is possible for the debugger to cause issues in your code, it's likely that a bug was causing the debugger to have issues in the first place.
The debugger interrupts processes and changes behavior. If you have an issue in your code, it's possible that this process of changing behavior causes the issue to actually be a problem, where as without the debugger, by dumb luck your code doesn't run into the problem condition.
The opposite is also commonly true. Sometimes your code can run perfectly within the debugger and crash and burn within the debugger. One likely cause of this is the debugger causing memory to be allocated differently.
Admin
Thanks for defending me their. I hate that frits guys.
Admin
Aww, don't hate me. I'm just playing around, I don't mean to be mean. I'm sorry, I'll never do it again.
Admin
I can see that surrogate is working out for me. [image]
Admin
Admin
Or maybe he keeps alienating everyone and jumping ship. So after 10 years of working he still hasn't established the experience/skill set involved with lead positions, and no company is willing to hire a lead from outside based on 10 years of experience as a peon.
(Also not trying to be offensive, but the phrase "low amount of time at the company" says it all.)
Admin
I am 10 years down the road from both of you with a little more experience (25 years), and I'll tell you that it doesn't end. There is no such thing as exactly right - so you will always be too young or too old.
What happens here is simple math though - people subtract 10 from 29 and figure you started 'getting experience' at age 19 - which is too young to get any actual experience, so they don't even look at your 10 years. I will say that I started at age 14 - which is actually a lie - age 14 is when I released my first commercial software. I can prove this too - but it doesn't matter. Any experience you get as a teenager almost counts against you. The fact that I look 10 years younger than I am doesn't help either. People basically think I'm lying about the experience.
So, I've stopped putting the number. Instead I make sure they can see I was working for an internet company in 1999, and going to college before that. Most people think the internet was created around 1995, and there wasn't any worthwhile computer stuff before then, so it's really just your 'internet age' they are interested in. This is of course, completely stupid, as those of us who started in the 80s, before "everything is the web", actually have a better foundation in programming principles.
Admin
There is a whole world of folks out there who take that rule too far using quotes for simple emphasis, where you would normally use bold face, or ALL CAPS. There is a whole web site dedicated to this mistake...
http://www.unnecessaryquotes.com/
Admin
Admin
Admin
logFile.debug("Setting timeout to: "); for(int i=0;i<300;i++) { logFile.debug("9"); }
Admin
Close, but forgot the ellipsis.
Admin
Admin
Since most things are logged as debug, they don't get logged under normal settings. For Java you can log under several levels:
SEVERE (highest value) WARNING INFO CONFIG FINE FINER FINEST (lowest value)
Admin
Admin
Admin
But where is XML in this?
Admin
If he actually changes the logging level, depending on the need (INFO,DEBUG,ERROR, etc.) it's not as bad as the code reads...
Admin
In this context, it would be more of a logorrhea... and the pun writes itself.
Admin
Admin
I should point out that conceivably you could configure a debugger to only break on a given breakpoint based on a given condition as well; this would be much like using an assert. I'm not sure if any modern debuggers have this feature though (that is, I haven't ever seen/used it myself).
Admin
Second, the place for such intense logging is not in the caller's code. It's in the called code. Those logging functions belonged in the methods of the drug and (puke) util classes if intensive logging was so important.
Admin
He needs to change that to 'assigned' if it's AFTER the statement being logged, or else move the debug statement BEFORE the line being referred to.
Christophe is obviously a useless tosser.
Admin
I don't know if any modern debuggers have this feature, because I'm stuck using Visual Studio 6.0. But it has conditional breakpoints, so I assume modern debuggers do too.
Admin
Admin
That's why I love scripting languages.
You can immediately do that thing more clever:
function myEval($statement) { eval($statement); log($statement); }
And then: myEval("brandNameDrugs = Utils.formatDrugList(dl.getDrugsByLabel(calculateBean.getDrugName()))"); myEval("majorClassifications = cl.getMajorClassifications(); ");
You can even do: function myEval($statement) { print "// $statement"; }
and you get perfectly commented code. Wheee. I have to use this for further programming!
Admin
Hey! It looks like someone took code out of one of my former employers!
Except that all of those logfile.debug calls were actually System.out.println calls. Stuff like "Entering payrollBatch function" ... "Exiting payrollBatch function" and other niceties, and no "debug" flag either.
Have fun.
Admin
It's called aspect oriented programming -- a highly useful way to create runtime-dynamic code.
Admin
Though I suppose if you really wanted to be thorough, it should say
Admin
Admin
The purpose of "myEval" (in contrast to "eval" itself) was to produce both: do the logging AND do the execution of the statement.
Well as I see ... you meant the code inside myEval. You're right, it could say log('myEval("' . $statement . '");'); or did you mean log(myEval("' . $statement . '"));
But then again. This would log the result of the statement. And as I read the original code only garbish is logged but not one useful value (of variables or anything).
A monster? :-) Thanks for the compliment
Admin
Admin
Rather than cluttering up all the code with manual calls to log(), can something like this be supported at the language level?
I'm imagining a language that keeps a streaming record of the program's run-state as it goes, and then you can later go back and do the "step-by-step debug" thing based not on the running program itself, but rather by replaying the log file.
This is all assuming that you have plenty of disk space, and that performance isn't an issue, of course.
Admin
Sure, you'll just spend all your time debugging the logfile instead of the real code. Brilliant.
Admin
Actually if you keep going North from anywhere, you can reach Canada. HINT: Ballistic missiles. Another HINT: Rotation.
Admin
The first time I was asked to implement a relatively straightforward process (every timer event, look for any zip files in target directory, open a zip file, find target data in a handful of possible text files for the database, move zip file to another archive directory) as a windows service, this is what my code looked like by the time I was done.
Admin
I have logged the code. Pray I don't log it any further.
Admin
I/0: 3 million transactions per second.
User response: 8 minutes per transaction.
Holding the disk storage contract for this company: Priceless.
Admin
Perhaps he makes hi-fi cables?