- 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
Several people seem to be under the misconception that an inefficient method of returning a Boolean value is the main WTF with this piece of code. It isn't (though it is the hardest to understand why the coder thought it would be a good idea).
The main WTF is that instead of using Excel's built-in function to count the number of non-blank cells in a given range, the code loops through each cell, does a text replacement on the contents to remove manual line breaks, and checks to see if the result is empty.
A subsidiary WTF is that if a non-empty cell is found, the code continues to loop through all the remaining cells in the row, rather than ending the loop at that point.
Using an extra, unnecessary Boolean to store the result before assigning it to the function (inefficiently) and clearing the local variables before the end of the function are minor WTFs - it is stupid code but it's not going to hurt the performance.
No, it's more like the Futurama episode "Mother's Day": "Wouldn't it work better if the wheels were round?"Admin
Just remember that a chicken can be trained to play this game and win (usually against drunk bar patrons). I tend to think that not much has improved in Microsoft's version, still a "chicken language".
Admin
Python's plethora of 'slick' language features is what design patterns are for Java programmers - a great way to over engineer and over complicate.
There's shitloads of crappy python code out there, and there will be more as soon as self-taught hobbyists everywhere are discovering the language.
Admin
Last year I did about 3 weeks of consultancy for the same company as in the OP. From what I understood is that it takes a huge effort to convince IT to write an application for you. Because of the very rigid and procedural environment, they require a shit-load of documents, budgets approved, resources assigned and of course they need to get the right prioritization. If your problem isn't critical enough, it will never get placed on the road-map and you will never get past the first stage. So why bother writing up all documents for the pre-business case, business case, high level functional design, risk evaluation... ?
Even if they would get a project, it would take a very long time to get it launched into production. Letting the local VB6 hobbyist write some small programs at least produces solutions with immediate impact on the problems that HR faced. Also HR will know that hiring consultants is way easier than trying to hire an internal developer, because that internal developer would just get placed in the IT department (not in HR) so this will get them nowhere.
BTW, the code produced by their IT department is not really top notch. Because the name of the company is in the open now, it's probably not a good idea to go into details about this, but I might post it anonymized in the sidebar
Admin
I like how this tool claims that the result is production-quality. Simply because it's C#? Come on...
Mike5
Admin
C-hash of course - you have to smoke something to be able to use it! :-p
Admin
Even optimize it as:
return (expression);
Admin
Be careful what you wish for.
I suspect that you can get a lot of interesting examples from disassembling early computer virus code - especially the ones that obfuscated themselves.
And I also suspect that there have been programmers that have made "invalid" jumps into the code to obtain the wanted result with the least amount of code. Not that unheard of in the early ages when the clock frequency was similar on all machines and a time delay was wanted. Worked fine until the hardware was upgraded.
Even code that was designed with a specific version of the processor has been seen - like the classic Z80 CPU had a few "undocumented" operations, and if you installed a clone processor they weren't there. And some programmers did utilize these instructions to create more efficient code which caused problems in some cases.
Admin
So I guess your point is, spending 3 days doing this is really no better than spending 3 weeks? Talk to me again after you've seen this process done by a secretary with a typewriter.
Admin
It's not an interpreted language. VBS is interpreted. ASP Classic is interpreted. Excel VBA is compiled to a byte code machine, like Java or Python.
Can we laugh now?
Admin
You work where mid level managers can casually offer internships?
Admin
I call it a process that would of, or did, take 3 weeks out of a month to complete before it was automated.
Admin
this the one i use, find it nice and helpful :) http://www.developerfusion.com/tools/convert/vb-to-csharp/
Admin
Dutch people don't make mistakes
Admin
Belgian ones do. Just look at the politicians.
Admin
Note that the word "teller" is Dutch for "counter".
Admin
Non-IT people accept solutions like this because it still justifies their existence. Who cares if a fully-automated solution could complete this in 5 minutes? At least they're needed 3 days out of the month! And they actually get some "down" time, unlike the old way of doing it where they worked 60-hour weeks for the whole month to get it done.
For those who don't (or don't care to) read VB, the basic WTFs in the code are:
Admin
Dutch OR Belgium. KBC: 57000 employees (2007) Fortis: 56866 employees (2006, before the 2008 acquisition of ABN AMRO followed by the breakup and takeover by BNP Paribas)
My guess is that it's KBC. I have some friends&family who work or worked there. I could ask someone to verify this story.
Admin
Golly, gee whiz... Thanks for the lesson. I'm glad someone finally came along to explain the WTFs in this code. Here I was all confused and thought that it was obfuscated source code. Turns out it's actually VB code and I didn't know how to read it.
Admin
Wow, this one really fired everyone up...
My original point is this: There is a lot of incompetence in our field (duh...). Enough that we don't need people from outside the field bringing more of it in.
To those who said I understated the value of hobby programmers: No, I did not. You transposed "hobby programmer" with "junior programmer" in your head. Yeah, we need people to write the small jobs, and they are those who are working professionally, gaining experience. What we do not need is a power user who are learning to code by reading what the Macro Recorder in Excel spits out. I know a LOT of great programmers started out as hobbyists. But if you don't have a fundamental understanding of programming, you have no business writing production code.
And to the comment about Excel providing a valid solution to some problems, sure. Right after I made the comment that I hadn't written VBA in years, I received a request to add a function to a spreadsheet template that would check an account number across a database. For that, it worked. Did I use Excel to input information into the database? Frick no, I'm a professional for chrissake. Small, rudimentary functions serve a purpose in an Excel spreadsheet (beyond what it is already capable of doing). If you are writing large solutions to real problems in Excel, you're in the wrong field, or your company has wildly unrealistic expectations of what Excel can do.
Finally, which analogy works best? None of em. We're programmers. I said surgeon because it was the first thing that came to my head. Surgeons work in a REAL time crunch, and they often don't get second chances (we just hit "compile" and fix what's broke). A mechanic fixes an existing problem, not engineers a new one...although it is closer when you consider whether you want an experienced mechanic or a hack fixing your breaks.
The cart loader is interesting. It brings up a valid point...some people are OK with "It works". Me, not so much. If this guy built a cart, it would be a box with one dowel rod axel, one made of taped together paper towel rolls, three wheels (one of which is a hardened jelly donut), and it would never make right turns. Could you load a truck with it? Sure.
But when management comes down and asks for a simple upgrade, say, a bigger box on the cart...upgrading becomes fixing, which becomes replacing. With the RIGHT solution.
Economics 101: How much did the RIGHT solution COST. Not the set cost, the Economics cost. Start adding things up...like, the cost of the first cart...the development of the monstrosity...the labor involved in keeping it operational, then trying to upgrade it, fixing it...then, realize that management, at this point, is invested in the pot. They will bring in a pro now, but they will tell the pro to fix the abomination that they have. After a minimum month of paying the pro, they MIGHT find out that there jelly donut cart was a waste of money to begin with, and start on a real solution.
So please, don't tell me that employing hack programmers is better than none at all. For the record, I've been the hack programmer. I look back on the train wrecks I've created and shudder. And I also think "Man was I a jerk for thinking that I was a programmer..."
Be proud of what you do, and get pissed when someone tries to trivialize it.
Admin
'Sright. A clbuttic example was "Centipede" on 8086 machines. Then Amstrad came along with their whizz-bang 8MHz CPU and you needed Jedi reflexes to play it on the easiest setting. So a little TSR COM was written and included on most coverdiscs to "slow" the box down by grabbing slices of CPU time...
Admin
(For those that never envcountered one, it didn't speed the machine up when pressed, it slowed the machine down when released. But you can't label a button 'slow down' when you can label it 'speed up' instead.)
Admin
Not suprising at all. Some time ago i worked at one of the major retail sellers here. They would do HR tasks in Excel. For the other department, i had to program Excel spreadsheet, that would grab data from tables prepared weekly by SP on SQLserver, then they would edit data in excel, and submit it back. And that kinda tool for supply chain management. Some reporting was done via Excel too, until they reimplemented it via SSRS. As for this tool, row count was ~10.000. Other reports were generated from tables with ~600.000 rows(via excel pivots)
Admin
Back to the point: Yes, Python allows plenty of WTFs. It's just sometimes more obvious when your code is NOT a WTF, and requires some experience to spout WTFs regularly.
Admin
Admin
Admin
Admin
Hang on a minute though - isn't that how programmers do write code? Isn't that why we're all here in the first place?
Admin
From a professional, yes, but it's clearly stated it was an amateur, who really ought to be forgiven such things.
The real WTF is that the consultants who came in didn't recommend replacing the partially automated solution with a professionally developed, fully automated solution.
Admin
Thank you, thank you! for submitting this. Although not a programmer even I can see the WTF-ness of this, and I can also see past employers' IT practices wherein one department, usually HR and accounting, had their own "IT gurus" who usually weren't much good but had special "suck up talents" and were very protective of their territory. "Security" was the usual justification for such a setup, which makes no sense. Better to have another pair of eyes watching. It's actually worse security to have only one guy running the system - what if he goes bad?
Admin
Admin
I prefer stack overflows
bool IsTrue (bool expression) { return IsTrue(expression); }
Admin
Admin
Do you seriously care about points as utterly insignificant as this during your code reviews? I'm not even sure it's worth the time it would take to point this out.
My code reviews aim to report two types of items: broken and 'may break'. Broken means there's a bug, may break means under load/large data sets/other environments/future conditions, there may be a bug. We don't always fix the 'may break' ones.
Admin
What makes you think they didn't ?
Unfortunately, the power leverage of a consultant in the HR department of a huge banking firm is somewhat... limited.
Admin
I think the guy's problem is that he hasn't learned that if statements don't have to include an else statement.
What he was good at was the more important part: giving people more work to do. More work means more jobs means more people getting paid. A true patriot if there ever was one.
Even more importantly: He was able to convince these people to let him remain working for them even while increasing the amount of work they had to do. And getting money by applying a skill you don't have is a skill in and of itself.
Admin
Fortis?
Admin
I should add that I see this stuff all the time. That is systems based on Access and/or Excel.
Access can be useful for these ends, but only when connected to SQL server. It's terribly unreliable and slow when the data's stored in Access. Otherwise it can provide solutions to problems in an extremely short timescale - which seems to be the cause of these sorta things.
In both England and Netherlands.
It's worse with Government-related things, though. Much worse.
Admin
As far as I can tell, the function is testing for an empty cell. Any empty cell, not just the special case of an entirely blank row.
This is a surprisingly difficult task in Excel, as there's no concept of NULL and an 'empty' cell may contain a zero-length string or a numeric zero - and it's difficult to predict what an inspection function like IsBlank() or IsNumber() will do because the casting functions for imported csv files are unpredictable.
You may well be reduced to checking every single cell if attempts to use Range.End(xlToRight) and Range.CurrentRegion have proven ineffective.
Even so, the function is badly thought out and badly coded; and examination of the function itself should not distract us from considering it's fundamental flaw - namely, that it should not be needed at all, as there are better ways of importing csv data, both to Excel and to MS-Access.
And, indeed, better system architectures, although that might be beyond an amateur programmer: 'big picture' thinking and analysis doesn't come easy to people who started out on code alone.
Admin
teller = teller + 1 => INC A => 0x3C teller = teller => LD A,A => 0x7F
An optimising Z80 compiler (is there any such thing?) might even convert the latter into a NOP (0x00).
What do you mean, there's no reason to suppose that "teller" will be loaded into the accumulator? Obviously it's the most important variable in the whole dang function.
And if you're going to complain about the difference in clock cycles ... well ... that wasn't part of the rubric. I dimly remember that INC A takes one, and I strongly suspect that LD A,A also takes one. If not, you're gonna have to rely on your trusty optimising assembler.
Now, does anybody out there have the time to waste building a symmetric multiprocessor out of Z80 chips? I mean, the goddamn things probably cost less than a cent each these days...
Oh, and for those looking for Python WTFs, try the entire os and sys packages for starters. Garnish with severe abuse of exceptions, decorated nicely with the dismal default output thereof, et voila!
I truly love Python, but sometimes it gets on my tits. Idiots mixing space and tab characters do not, however. Python is capable of parsing itself, so there are a couple of neat little programs to sort this particular problem out which can be downloaded from the Web.
I've got one, but I'm not going to share it until somebody builds me a Z80 SMP machine for $1 and a cup of Joe.
Admin
Check out whitespace then:
http://en.wikipedia.org/wiki/Whitespace_(programming_language)
Admin
More likely it was done at work - Access usually ships with Office Pro, and the license is a bit pricey for home users. On the other hand Access and VB are on most corp desktops since they come with Office pro.
The sad thing is that Excel and Access with VB are almost always the only development "solution" available on the average locked-down corporate desktop. It's just a case of using a hammer because it's the only tool in the box.
Admin
Read comp.lang.python. It usually has several of them every day, usually unintentionally.
Admin
wtf?
Admin
Well said. A little too arrogant, maybe, but well-said nonetheless.