Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Paid for crap

by holli (Abbot)
on Jan 25, 2007 at 09:36 UTC ( [id://596437]=perlmeditation: print w/replies, xml ) Need Help??

*Sigh*, Yesterday I had to look into a perl based application we use inhouse, and for which we pay a quarterly fee of €5,000, to find a small bug asap. Once I started to look into it my nose immedeatly began to bleed and my the internal pressure of my eyes raised up 200%. Have a look at a little gem from the code.

Now I ask you, which PHB buys such a crap and why don't I find somebody as dumb?


holli, /regexed monk/

Replies are listed 'Best First'.
Re: Paid for crap
by demerphq (Chancellor) on Jan 25, 2007 at 10:19 UTC

    The gotos and lack of return statements and in fact the general coding style strongly suggest to me that it was transliterated from (bad) VB, by a not very experienced VB or Perl programmer. (I might have said Pascal but using gotos is not Pascal)

    The whole assign to $_[0] as a return is strongly reminiscent of the VB concept of assigning to the function name for setting a functions return value, likewise VB (pre dotNet anyway) doesnt have a return statement, and normally relies on goto on err type logic for exception handling. Both routines have all of these characteristics.

    BTW, many of these issues are older design concepts that have long since been rejected as being generally bad ideas. Using the function name as a pseudo variable makes recursive calls a bit tricky to deal with, and long ago it was realized that the Pascal-esq single-point-of-entry, single-point-of-exit philosophy just created more problems than it solved (despite being an excellent way to teach disciplined programming, all you bottom sub'ers would get killed by Pascal). Relaxing it to Single-point-of-entry, multiple-points-of-exit (as perl does) makes for a much more "natural" feel, and avoids a whole host of bogosity, like the loop and a half problem, and avoids silly programming habits, some of which are well demonstrated in your WTF code.

    ---
    $world=~s/war/peace/g

      blockquote>VB (pre dotNet anyway) doesnt have a return statement, and normally relies on goto on err type logic for exception handling.

      I don't know VB but I find this very surprising; 25 years ago my good ol' Microsoft MSX BASIC 1.0 had subs (that you'd call with GOSUB) and RETURN statements. Of course you couldn't name the subs, you had to rely upon line numbers :)

      10 CLS 20 INPUT "choose a number", A$ 30 IF A$>10 GOSUB 100 40 if A$<5 GOSUB 100 50 PRINT "you typed ", A$ 60 END 99 REM the following 2 lines are a subroutine! 100 PRINT "you must enter a number between 5 and 10" 110 RETURN

      Wow, I couldn't imagine I remembered that sh*t so well, should have been 20 years :)

        Return doesnt return anything in the sense of a modern language would use return, it returns control to the next execution point.

        The moral equivelent of the MS basic 'return' would be 'exit sub' iirc. But this isnt the site for this discussion :-)

        ---
        $world=~s/war/peace/g

Re: Paid for crap
by reneeb (Chaplain) on Jan 25, 2007 at 13:45 UTC
    I think the programmer was paid per line ;)
Re: Paid for crap
by Zaxo (Archbishop) on Jan 25, 2007 at 09:52 UTC

    That's certainly WTF level coding, but it's also WTF code. I can't imagine what use the result might be.

    Only you know what PHB bought it.

    After Compline,
    Zaxo

Re: Paid for crap
by zentara (Archbishop) on Jan 25, 2007 at 11:28 UTC
    Hey, that might be my crap. :-) Seriously though, alot of things that go on in business and government don't make sense because of the way we are educated(brainwashed) to believe in the "truthfullness and righteousness" of our economic system. So when ignorance and corruption display themselves in the offices of the PHB's, we stand in disbelief, and mutter to ourselves " say it ain't so champ, say it ain't so".

    But the reality of the world is doing favors, corruption, payoffs, and the "in-law" factor.

    I often dream of a world where all leaders, whether government or private sector, are required to take a vow of poverty for life, so that they make desicions on merit, not on greed..... but I'm a dreamer.


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

      I often dream of a world where all leaders, whether government or private sector, are required to take a vow of poverty for life, so that they make desicions on merit, not on greed..... but I'm a dreamer.

      Many of them already vow to serve and uphold some principle or document or another, and that doesn't seem to make a difference. I'm not sure why I'd expect them to have integrity when it comes to poverty.

        I guess we would have to keep them all in jail :-)

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Paid for crap
by Nkuvu (Priest) on Jan 25, 2007 at 17:17 UTC

    A co-worker had issues with a PHB. The PHB in question was our customer, who was... well, let's just say "very specific" in his coding style.

    For example (just one example of many), my co-worker was told to change

    // variables not representative of actual names int alpha, beta, kumquat;

    into

    int alpha; int beta; int kumquat;

    My co-worker was not happy with the change, but had no position to veto the PHB's changes. -sigh- Moral of the story, it may not be the fault of the programmer, they may hate the code just as much as you do.

      char* a, b;
      doesn't do what
      char* a; char* b;
      does (the first one declares one pointer to char, and one char). (Pause for stares of disbelief from non-C programmers.)

      This is a shortcoming in C which the supervisor in question is trying to avoid. Explaining the reason in the coding standards document would be a nice idea. Assuming there actually is such a document, that is.

        The data types were really just integers. The supervisor was just trying to find something wrong with the code, when there really wasn't anything.

        He had a similar change made to a comment. It was broken up into two lines, he wanted only one long line. Brought defects up in reviews of spreadsheets because columns were too wide, too narrow, et cetera et cetera.

        Sanctified C programmers, guided by the holy writ (K&R), would never fall into that trap nor lead anyone else into peril. That's because they'd write the above as
        char *a, *b;
        Whitespace++.
      Moral of the story, it may not be the fault of the programmer

      I beg to differ:

      Moral of the story, a little knowledge is a dangerous thing

      :-)

      Cheers,
      Rob
      Frankly, the PHB's request doesn't seem unreasonable to me. If he thinks the code is more readable his way, then he should have it his way, since he is paying for it.
      If you bought a red car and the dealer delivered a blue car, would you be happy? Sure they both drive equally well, but if you like it red, why should you have it blue?
      The OP's example, on the other hand, is something different, for it raises doubts on the Perl skills of the vendor.
Re: Paid for crap
by toma (Vicar) on Jan 26, 2007 at 05:52 UTC
    It is Officially Okay to write baby Perl.

    See Natural Language Principles in Perl:

    "It's Officially Okay in the Perl realm to program in the subset of Perl corresponding to sed, or awk, or C, or shell, or BASIC, or Lisp, or Python. Or FORTRAN, even. Just because Perl is the melting pot of computer languages doesn't mean you have to stir."

    Some Perl programmers are well-compensated. Some of these write baby perl. At least you had the source code. PHB++ for that!

    It should work perfectly the first time! - toma

      Ok, but this isn't Baby Perl. It's a lack of basic algorithmic knowledge. Even that would be OK in a system that nobody is paying for.

      Seriously, I'd be willing to forgive not having read perlfunc and therefore not knowing that sprintf would work. But a string of ifs? That's bad programming, not just bad Perl.

      <radiant.matrix>
      Ramblings and references
      The Code that can be seen is not the true Code
      I haven't found a problem yet that can't be solved by a well-placed trebuchet
Re: Paid for crap
by dorward (Curate) on Jan 25, 2007 at 10:12 UTC

    Now I ask you, which PHB buys such a crap

    All of them, except those who get forced to use third party software selected by other PHBs in the business.

Re: Paid for crap
by syphilis (Archbishop) on Jan 25, 2007 at 16:10 UTC
    Have a look at a little gem from the code

    Aaaah ... that code speaks to me.

    What a pity that $numValue could not take on larger values .... (like up to 10 ** 5000000 :-)

    And ++ reneeb ... for perspicacity above and beyond the call of duty !!

    Cheers,
    Rob
Re: Paid for crap
by sgt (Deacon) on Jan 25, 2007 at 15:44 UTC

    poor you!

    One of the comments in the forum is interesting: for the computer language shootout (google for these 3 words if you don't know it -- I often use that page to check for new languages...) return in perl and ruby was taken off for speed. Still PBP indicates that sometimes it is not clear which statement will be last (especially if there is a loop construct or foreach). So too much optimization can be dangerous. Don't know what happens in ruby.

    cheers --stephan
Re: Paid for crap
by j3 (Friar) on Jan 26, 2007 at 05:05 UTC

    Now I ask you, which PHB buys such a crap ...

    I think it's the ones who don't trust or even really listen to the advice of their technical staff.

    ... and why don't I find somebody as dumb?

    Unfortunately, I don't think you'd find working for one very rewarding.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://596437]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-03-28 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found