• Sami (unregistered)

    Would "InsertString := Route + space(35-Len(Route));" be too easy?

  • Xythar (unregistered)

    Stop writing methods called padMe, you're reminding me of Star Wars Episode 1.

  • (cs)

    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?

  • Guest (unregistered) in reply to Gary
    Alternatively: while str.length <> 30 {str = str + ' '};

    And than someone uses it on a string of 32 characters long ....

    In short, lose the '>'

  • Anon (unregistered) in reply to Herby

    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.

  • Vla (unregistered)

    It's what you get when you get paid per line of code.

  • jspc (unregistered)

    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

  • QJo (unregistered) in reply to beginend
    beginend:
    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?

    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.

  • Iffy (unregistered)

    Imagine the same thing, but with each of the following IF nested with in the preceeding. You're welcome.

  • (cs) in reply to CT
    CT:
    And the business wonders why it takes so long to create new reports...

    And they should - if the above code causes a delay noticeable to anything but a finely tuned machine or a profiler, something is seriously wrong.

    Create. Not execute.

  • (cs) in reply to Vla
    Vla:
    It's what you get when you get paid per line of code.
    I'd rather get laid per pine of code...
  • (cs)

    I would have done this with a switch and fall-throughs.

  • QJo (unregistered) in reply to CT
    CT:
    And the business wonders why it takes so long to create new reports...

    And they should - if the above code causes a delay noticeable to anything but a finely tuned machine or a profiler, something is seriously wrong.

    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.

  • Number 7 (unregistered)

    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

  • QJo (unregistered)

    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.

  • QJo (unregistered) in reply to QJo
    QJo:
    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:
    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]  := ' ';
    }
    

    ... 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.

    Apologies, I misformatted it.

  • Spike (unregistered) in reply to Rumen's Boss

    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(); // :-)

  • Oh THAT Brian! (unregistered)

    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.

  • not first (unregistered) in reply to Almafuerte
    Almafuerte:
    You are worse that the retard that wrote that code. It's sprintf() that you are looking for.

    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.

  • TimeBandit (unregistered) in reply to Sigivald
    Sigivald:
    Real programmers also use .NET, because it lets them do that in one line
    .NET programmers think that their language is the best because they don't know any better.

    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.

  • (cs) in reply to Anon
    Anon:
    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.
    This has a significant thread of truth to it. The self-taught became so because they really dig this shit.

    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.

  • (cs) in reply to TimeBandit
    TimeBandit:
    Sigivald:
    Real programmers also use .NET, because it lets them do that in one line
    .NET programmers think that their language is the best because they don't know any better.

    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.

    .NET has strongly-typed function pointers, lexical closures, a constrained template system, and is missing only one major feature of OOP. In C#, you also get free use of pointers and unmanaged memory. In C++/CLI, you get most of the features of C++0x already-implemented.

    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.

  • Ken B. (unregistered) in reply to thistooshallpass
    thistooshallpass:
    Yazeran:
    Why did the developer not stop after the first 5 lines or so and thought 'I wonder if there is a better way of doing this?'...

    Yeah, after 5 lines I would have started to use the clipboard.

    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 > 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];

    I am not sure if there would be a cast problem, but if so, must be possible to inherit from Clipboard...

    You're still wasting resources by creating that unneeded ArrayElement[] variable.

    ==========

    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.

  • Calvin (unregistered) in reply to hoodaticus
    hoodaticus:
    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.

    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.

  • Brad (unregistered)

    WTFs have been of low quality lately; this one's a really good one.

  • (cs) in reply to Calvin
    Calvin:
    hoodaticus:
    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.

    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.

    This. Although, it's funny. The more I learn, the more I come back to my original programming style. For some reason, the way I first started ooping (domain-model parent-child style) gives me the most stability, flexibility, thread-ability, data-bindability, et cetera, at least for library dev.

  • Z00n3$!$ (unregistered) in reply to hoodaticus
    hoodaticus:
    This. Although, it's funny. The more I learn, the more I come back to my original style. For some reason, the way I first started ooping (dominating-a-model parent-child style) gives me the most stability, flexibility, angle-ability, rope-bindability, et cetera, at least for library sex.
    I love that style!
  • Z00n3$!$ (unregistered)

    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.

  • Ken B. (unregistered) in reply to Calvin
    Calvin:
    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.

    From the day I got my first copy of "Basic BASIC" (first edition), I've been self taught. (Sorry, but BASIC was the only thing available on the only computer available. Don't hold it against me.)

    I started college (Math/CompSci major) with enough computer experience that I was able to take graduate-level courses my freshman year.

  • Todd Lewis (unregistered) in reply to TopPost3r
    TopPost3r:
    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]  := ' ';
    The nice thing about this pattern is you can have a simple program generate maybe 100 lines like this, save them in a file, then just copy/pasta however many lines you need for the desired length of whatever string you're padding today. It speeds development, and that's the most costly part of computers.

    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.

  • (cs) in reply to Z00n3$!$
    Z00n3$!$:
    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.

    You missed out on Irish Girl, huh?

  • TopPost3r (unregistered) in reply to QJo

    And that, ladies and gentlemen, is why we occasionally need "troublous" times.

    QJo:
    Companies which fail adequately to discriminate between the good guys and the bad guys tend not to last in troublous times.
  • (cs) in reply to Mikerad
    Mikerad:
    It appears to be Crystal Reports formulas (VB6, only worse)

    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).

  • (cs)

    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."

  • eVil (unregistered)

    Is this similar to the content padding trick this site is constantly playing on us?

  • (cs) in reply to Mikerad
    Mikerad:
    It appears to be Crystal Reports formulas (VB6, only worse)
    I knew I recognized it. Yes, it appears to be what is now called Crystal Basic.

    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.

  • (cs) in reply to TheRider
    TheRider:
    Vla:
    It's what you get when you get paid per line of code.
    I'd rather get laid per pine of code...
    Yes. Then you could at least build yourself a wooden table.
  • (cs) in reply to tweek
    tweek:
    Mikerad:
    It appears to be Crystal Reports formulas (VB6, only worse)

    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).

    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.

  • TopPost3r (unregistered) in reply to The Bytemaster

    I think that's called Object Oriented Programming.

    The Bytemaster:
    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
  • (cs) in reply to Calvin
    Calvin:
    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.

    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

  • (cs) in reply to TopPost3r
    TopPost3r:
    I think that's called Object Oriented Programming.
    The Bytemaster:
    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
    I wish it was that simple. I think they finally included ways to see all of the code in the latest versions (I no longer used), but it used to be you would pretty much have to click on every object to see if it had code attatched to it. Almost every property could be set statically or set by a function, meaning code. Of course, this code could do a lot more than just return the set value, and could have things that impacted global variables, etc. You can do the same thing in bad object oriented code as well, and I have see a lot of code worthy of this site in a Crystal Report.

    In other words, it is just like object oriented code with the added bonus built in game of "find the class file".

  • Sigivald (unregistered) in reply to TimeBandit

    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"?)

  • iMalc (unregistered) in reply to RF
    RF:
    Looks like someone's getting paid by the SLOC.
    To quote the tank driver in Starcraft 2: "Absolutely!"
  • Ghost of Nagesh (unregistered) in reply to Herby
    Herby:
    In my first (no frist) programming class I was taught the concept of a loop. That was back in the 60's. I don't think the basic concepts have changed much, but the quality of the instruction seems to have changed quite a bit, as witnessed by code examples like this.

    The sad part is that this "programmer" was probably a graduate of a "top tier" school (or his resume said so). Sad, very sad!

    All good programmers decided to kick the bucket

  • QJo (unregistered) in reply to Herby
    Herby:
    In my first (no frist) programming class I was taught the concept of a loop. That was back in the 60's. I don't think the basic concepts have changed much, but the quality of the instruction seems to have changed quite a bit, as witnessed by code examples like this.

    The sad part is that this "programmer" was probably a graduate of a "top tier" school (or his resume said so). Sad, very sad!

    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.

  • (cs) in reply to Coyne
    Coyne:
    This is quite a pattern: We could use it all sorts of ways:

    //Add 5 to number a[0] = in; a[1] = 1; a[2] = 1; a[3] = 1; a[4] = 1; a[5] = 1; int out = 0; out = a[0]; out = out + a[1]; out = out + a[2]; out = out + a[3]; out = out + a[4]; out = out + a[5]; }

    Think of the efficiency improvements!

    FTFY. (I removed that horrible loop)

  • (cs) in reply to TopPost3r
    TopPost3r:
    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]  := ' ';
    The nice thing about this pattern is you can have a simple program generate maybe 100 lines like this, save them in a file, then just copy/pasta however many lines you need for the desired length of whatever string you're padding today. It speeds development, and that's the most costly part of computers.

    Most costly? Not in Bangalore.

  • Jon B (unregistered) in reply to SQLDave
    SQLDave:
    Most costly? Not in Bangalore.
    He's white, very British 50-something and so probably not an IT grad.

    I find the constant sniping at Indian engineers distasteful, many are excellent...

  • feugiat (unregistered) in reply to Herby
    Herby:
    In my first (no frist) programming class I was taught the concept of a loop. That was back in the 60's. I don't think the basic concepts have changed much, but the quality of the instruction seems to have changed quite a bit, as witnessed by code examples like this.

    The sad part is that this "programmer" was probably a graduate of a "top tier" school (or his resume said so). Sad, very sad!

    Does that mean you're 65-70 years old?

  • (cs) in reply to SQLDave
    SQLDave:
    Coyne:
    This is quite a pattern: We could use it all sorts of ways:

    //Add 5 to number a[0] = in; a[1] = 1; a[2] = 1; a[3] = 1; a[4] = 1; a[5] = 1; int out = 0; out = a[0]; out = out + a[1]; out = out + a[2]; out = out + a[3]; out = out + a[4]; out = out + a[5]; }

    Think of the efficiency improvements!

    FTFY. (I removed that horrible loop)

    Remember, loops are like the definition of insanity: repeating the same thing over and over, expecting different results!

Leave a comment on “The String Padding Trick”

Log In or post as a guest

Replying to comment #:

« Return to Article