- 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
Would "InsertString := Route + space(35-Len(Route));" be too easy?
Admin
Stop writing methods called padMe, you're reminding me of Star Wars Episode 1.
Admin
in defense of the person who wrote this sad pool of sick (NOT in defense of the code itself) i want to point out that we don't know whether he would even call himself a programmer. i have witnessed situations where in a company (or university) some secretary was send to a "comprehensive VBA workshop" or similar (= 2 days off drinking free coffee while being shown slides), because "s/he is reasonably good at excel/access data entry anyway" and "we need someone to do [some coding which the executive considers simple]". i mean, no educated programmer can produce anything that annoying... please?
Admin
And than someone uses it on a string of 32 characters long ....
In short, lose the '>'
Admin
Of course he must be a graduate. There are no bad self-taught programmers out there and of all the programmers out there, only those with the highest education write bad code.
Admin
It's what you get when you get paid per line of code.
Admin
I can't even work out why I'd even do all that copying and pasting, not without scripting a quick forloop to increment the numbers, print and then cop/paste that
Admin
I've seen supposedly professional programmers do some quite disgustingly nauseating things in the industry. Usually this is before a round of cost-cutting causes the management to investigate directly the coding skills of their staff. Companies which fail adequately to discriminate between the good guys and the bad guys tend not to last in troublous times.
But it's true. I have found myself in the past trying once more to explain to one of my colleagues (in some cases better positioned and therefore presumably better paid) the subtle concept behind such an abstruse control structure as a loop. "How does a loop work again, Q?" Aargh.
Admin
Imagine the same thing, but with each of the following IF nested with in the preceeding. You're welcome.
Admin
Admin
Admin
I would have done this with a switch and fall-throughs.
Admin
It is of course possible that the OP is alluding to the fact that there may be other worse sins that have been committed which result in severe inefficiencies that do affect the runtime adversely.
Admin
35 bottles of space on the wall 35 bottles of space Take one down, paste it all around 34 bottles of space on the wall
Admin
The real WTF of course is that it's bad form to put an if statement all on one line. It makes it difficult to read. It says this in a book I read. So it should be rewritten as:
[code] if StrLength > 0 then { ArrayElement[1] := Route[1] } else { ArrayElement[1] := ' '; }
if StrLength > 1 then { ArrayElement[2] := Route[2] } else { ArrayElement[2] := ' '; }
if StrLength > 2 then { ArrayElement[3] := Route[3] } else { ArrayElement[3] := ' '; } [code]
... and so on.
I think every right-thinking person would agree with me that the above is unarguably the very best way of implementing the required functionality.
Admin
Apologies, I misformatted it.
Admin
Or just to save memory:
Redim ArrayElement[30]; StrLength := Len(Route); if StrLength > 0 then ArrayElement[1] := Route[1] else ArrayElement[1] := ' '; if StrLength > 1 then ArrayElement[2] := Route[2] else ArrayElement[2] := ' '; if StrLength > 2 then ArrayElement[3] := Route[3] else ArrayElement[3] := ' '; if StrLength > 3 then ArrayElement[4] := Route[4] else ArrayElement[4] := ' '; if StrLength > 4 then ArrayElement[5] := Route[5] else ArrayElement[5] := ' ';
//well let's use the clipboard to optimize this Clipboard.SetText(" ");
if StrLength > 5 then ArrayElement[6] := Route[6] else ArrayElement[6] := Clipboard.GetText(); if StrLength > 6 then ArrayElement[7] := Route[7] else ArrayElement[7] := Clipboard.GetText(); if StrLength > 7 then ArrayElement[8] := Route[8] else ArrayElement[8] := Clipboard.GetText(); if StrLength > 8 then ArrayElement[9] := Route[9] else ArrayElement[9] := Clipboard.GetText(); if StrLength > 9 then ArrayElement[10] := Route[10] else ArrayElement[10] := Clipboard.GetText(); if StrLength > 10 then ArrayElement[11] := Route[11] else ArrayElement[11] := Clipboard.GetText(); if StrLength > 11 then ArrayElement[12] := Route[12] else ArrayElement[12] := Clipboard.GetText(); if StrLength > 12 then ArrayElement[13] := Route[13] else ArrayElement[13] := Clipboard.GetText(); if StrLength > 13 then ArrayElement[14] := Route[14] else ArrayElement[14] := Clipboard.GetText(); if StrLength > 14 then ArrayElement[15] := Route[15] else ArrayElement[15] := Clipboard.GetText(); if StrLength > 15 then ArrayElement[16] := Route[16] else ArrayElement[16] := Clipboard.GetText(); if StrLength > 16 then ArrayElement[17] := Route[17] else ArrayElement[17] := Clipboard.GetText(); if StrLength > 17 then ArrayElement[18] := Route[18] else ArrayElement[18] := Clipboard.GetText(); if StrLength > 18 then ArrayElement[19] := Route[19] else ArrayElement[19] := Clipboard.GetText(); if StrLength > 19 then ArrayElement[20] := Route[20] else ArrayElement[20] := Clipboard.GetText(); if StrLength > 20 then ArrayElement[21] := Route[21] else ArrayElement[21] := Clipboard.GetText(); if StrLength > 21 then ArrayElement[22] := Route[22] else ArrayElement[22] := Clipboard.GetText(); if StrLength > 22 then ArrayElement[23] := Route[23] else ArrayElement[23] := Clipboard.GetText(); if StrLength > 23 then ArrayElement[24] := Route[24] else ArrayElement[24] := Clipboard.GetText(); if StrLength > 24 then ArrayElement[25] := Route[25] else ArrayElement[25] := Clipboard.GetText(); if StrLength > 25 then ArrayElement[26] := Route[26] else ArrayElement[26] := Clipboard.GetText(); if StrLength > 26 then ArrayElement[27] := Route[27] else ArrayElement[27] := Clipboard.GetText(); if StrLength > 27 then ArrayElement[28] := Route[28] else ArrayElement[28] := Clipboard.GetText(); if StrLength > 28 then ArrayElement[29] := Route[29] else ArrayElement[29] := Clipboard.GetText(); if StrLength > 29 then ArrayElement[30] := Route[30] else ArrayElement[30] := Clipboard.GetText();
InsertString := ''; for i := 1 to 30 do InsertString := InsertString + ArrayElement[i];
return InsertString.Trim(); // :-)
Admin
Ouch! That brought back a painful memory. Once, I was tasked with writing a report that was to be displayed on one of the first Teletype units that used heat-sensitive paper. This beast was the size of a typewriter, but it was not built like one - it had a notorious temper and when a RETURN character was sensed, it would try to send the carriage back, but often would stop a few characters shy of the left margin. My pleas to get it serviced fell on deaf ears. (Apparently, The Phone Company didn't have the money.)
To make the text line up, I had to resort to prepending the report line with about two dozen backspaces.
It all worked beautifully, until someone decided to send the output to a line printer. Instead of looking like the text was snaking down the page, the printer software dutifully backspaced to the previous line.
I had to install a software switch to indicate where the output was to go. TTY=extra backspaces at the front of the line, otherwise, print the report normally.
Admin
Clearly, sprintf() or a padding function is the correct approach, that's why the code is on the front page. But clearly, these developers were blissfully ignorant of such methods (or have a terminal case of NIH) and went with the CS 101 approach.
My point was that they unrolled a loop in "step 1", then used a loop successfully in "step 2" - even though they could have done it all in a single loop by applying basic math. So they knew how to use a loop but still managed to create an eye-stinging mess - which to me is TRWTF.
Admin
There is functions to pad strings in almost any language.
And as a real programmer, if the language I'm currently using doesn't have one, I'll just code it myself and then use it to do it in one line ever after.
Admin
Now, the self-taught DO produce WTFs. Usually, this is at the beginning of their careers or when they transition from a pure-imperative language to an OO or declarative language, and keep writing FORTRAN where it doesn't belong.
I have never met a self-taught dev that failed to impress me. But I've been let down several times by CS-laureates who can't pass FizzBuzz. They make me long for my self-taught assembly programmer that my CTO wouldn't sign off on due to personality...
Addendum (2011-09-01 09:43): On the other hand, a good CS or SE guy will usually be much better than self-taught, since they'll know all the fundamental algorithms like hashing, sorting, searching, and they'll almost always pick the right data structures.
Admin
So thank you for saving me from my delusion of being a "real programmer", since obviously "real programmers" don't use .NET. Real programmers transform XML using a combination of lithography and a wooden table. Real programmers reinvent every single wheel themselves. After all, there's no way it's already been done better by any of the millions of programmers who came before you.
Admin
==========
StrLength := Len(Route);
//well let's use the clipboard to optimize this Clipboard.SetText(" ");
if StrLength > 0 then Clipboard.SetText(Clipboard.GetText()+Route[1]) else Clipboard.SetText(Clipboard.GetText()+" "); if StrLength > 1 then Clipboard.SetText(Clipboard.GetText()+Route[2]) else Clipboard.SetText(Clipboard.GetText()+" "); [...] if StrLength > 28 then Clipboard.SetText(Clipboard.GetText()+Route[29]) else Clipboard.SetText(Clipboard.GetText()+" "); if StrLength > 29 then Clipboard.SetText(Clipboard.GetText()+Route[30]) else Clipboard.SetText(Clipboard.GetText()+" ");
InsertString := Clipboard.GetText();
==========
Of course, this still isn't enterprisey enough. What's really needed is an SQL database consisting of strings of spaces from 0 through 100 characters long. Then a stored procedure which selects the appropriate-length spaces value, creates a temporary table, inserts a row consisting of Route concatenated with the previously-retrieved spaces value, retrieves this value, deletes the temporary table, and then returns the value retrieved.
Admin
A lot of self-taught people will know hashing, sorting etc, and be good at picking data structures. (Even if they may not be able to write a quick-sort algorithm from memory, they'll know about it, and be able to find it online if necessary)
Self-taught people often have a lazy streak (because they don't like writing tedious code), which means they'd never write code like this.
Even if you've done a CS degree, that was in the past. Everything since then should be self-taught.
IMV, if you regularly look back at your own code from 3 years ago and wonder 'what on earth was I on?', then you're a decent developer. If not, then either you're the world's best ever developer, or someone who never learns.
Admin
WTFs have been of low quality lately; this one's a really good one.
Admin
Admin
Admin
I anyone else having trouble keeping their eyes off this meditating ChangeVision chick?
I especially like the horizontal one where you can't her hear - like she's been decapitated or something... Hot.
Admin
I started college (Math/CompSci major) with enough computer experience that I was able to take graduate-level courses my freshman year.
Admin
Yup. This is the kind of code that's easy to produce once you've mastered your editor's macro capabilities. Easier than writing foolish tight loopy code that's hard to read later. You can read this code from 10,000 feet. Good code.
Admin
Admin
And that, ladies and gentlemen, is why we occasionally need "troublous" times.
Admin
Except if it were CR, there's no reason to pad anything with spaces unless you're concatenating all of your strings into one field (which can be done but kind of defeats the purpose of using CR).
I will admit to doing something the quick easy way instead of the right way to get a report out, but I've always gone back and fixed my horrible syntax (if for no other reason than to not be embarrassed when I look at the code later).
Admin
Jokes, "improvements" and adaptations aside, the real bottom line with this fits the adage: "You can't make a silk purse out of a sow's ear."
Admin
Is this similar to the content padding trick this site is constantly playing on us?
Admin
For the uninitiated, Crystal Basic is a strange hybrid language that was apparenently written by someone who was told they wanted it to "be like Basic", but only knew C, or maybe pascal. At least, that is what it always felt like to me.
Because all the code is NOT contained in one place, it becomes a fun one to debug things. You put code attatched to different objects on the report so that they run at the appropriate time... only the final row of a grouping for example.
I used to really do "amazing" things with Crystal Reports. Sadly, I wonder if that is really something to brag about.
Then again, it could be worse... It could be using Microsoft's "expression" syntax from their reporting engine, or the one from SSIS -- that seems like someone knowingly wanted to see what would happen if VB and C# had a child together.
Admin
Admin
Unfortunately, I have seen many a Crystal Report that did a whole lot in the script that could have been done in simple formatting.
Of course, if you needed to use your report to also export data in a certain format, you may need to actually have the characters prepended to the report.
Admin
I think that's called Object Oriented Programming.
Admin
Been there, didn't like the view....
In my defence, I had to start making a database application (including underlying data model) from scratch (note, I'm not a SC major, my only formal computer education at that time was 1 year in 9'th grade, yes at school....) and I had only had time to read 3 chapters in a 'SQL for dummies' type of book and that had only covered INSERT, UPDATE and DELETE as well as CREATE TABLE up to that....
I'm sure you can see where that ended: no primary keys, no foreign keys, varchars as keys (only some keys unique) and NO normalisation......
Add to that for spice some spaghetti Perl-code with lots of backtics and alike....
The most amazing part is that that database + application is still beeing used and is fully functional although it is now 6 years since I made it.....
I have since learned a lot, but I still cringe when I have to look at that code and data model from time to time....
Yours Yazeran
Plan: To go to Mars one day with a hammmer
Admin
In other words, it is just like object oriented code with the added bonus built in game of "find the class file".
Admin
Time Bandit said: .NET programmers think that their language is the best because they don't know any better.
Yeah, plainly.
(Is it also true that non-.NET programmers don't realize that .NET isn't a language?
And that they don't get that "real programmers use .NET" was a joke in response to "real programmers would use recursion"?)
Admin
Admin
All good programmers decided to kick the bucket
Admin
There's an argument that suggests that the first programming course should be done in pseudocode. Programs that are generated from it as a response to exercises set are "run" by getting a co-student to perform what we used to call a "dry run". From there it could easily be assessed as to how effective such a program is.
So, having then learned the basic data structures and techniques for control flow, the student is then let loose upon a real computer language. Which one doesn't matter, but it helps to make it a fiddly, difficult and unnecessary one, so as to prepare the student for what it's really like in the outside world. Later in the course other languages will be introduced - real-life commercial languages - and the delight at its ease of use will stand the student in good stead and start him on his career on a high.
Admin
FTFY. (I removed that horrible loop)
Admin
Most costly? Not in Bangalore.
Admin
I find the constant sniping at Indian engineers distasteful, many are excellent...
Admin
Does that mean you're 65-70 years old?
Admin