Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^4: do/redo or for(;;): what's Kosher?

by Aristotle (Chancellor)
on Jan 04, 2002 at 06:31 UTC ( #136191=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: do/redo or for(;;): what's Kosher?
in thread do/redo or for(;;): what's Kosher?

I think you're wasting way too many brain cycles trying to save CPU cycles. I was heavy into assembly programming for a while and used to be the same way; however at some point your realize that 10,000 clock cycles just aren't worth the 3 hours extra work. If you're really so bent on speed as to mind every last CPU cycle, how did you end up with Perl?

> #while(1) psuedo-loop
> {

Isn't this kind of the worst of both worlds? You have to type out the while anyway, in addition to the redo, and get the horrible maintainability of the naked block you're using. And you also have to maintain all your pseudocode comments to match the actual code. I can't think of any way to make things more awkward.

To your subrant: smack them over the head if they don't use indentation. I don't care about exact formatting habits like where people put their curlies and whether their else's are cuddled, but indentation is an iron rule.

while(1) is misleading only to a person who has never seen this idiom before, while it is the most efficient way to signal "infinite loop" to someone who's spent any amount of time writing Perl. Personally, the moment I see that idiom, I know what's going on without even thinking. Learning these idioms is what makes you good at a language.

Questioning accepted good practice is a good way of thinking; throwing accepted good practice out of the window just for the sake of doing things differently, in your own style, is not. I used to question everything and often went about things my own way. In the end I discovered that I only repeated mistakes others had made before and which had led them to establish those accepted good practices I dismissed. Tradition becomes tradition, because it actually works well, not because everyone just does it that way. Sometimes, straying from it is good; but someone who is too quick to dismiss it will not stay true to his new, "better" rules for long either.

  • Comment on Re^4: do/redo or for(;;): what's Kosher?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: do/redo or for(;;): what's Kosher?
by Lord Wrath (Friar) on Jan 04, 2002 at 22:24 UTC
    First of all, I ended up in PERL because I took a job that deals with PERL, and in the current market slump, any job that pays is better than no job at all. I have grown to enjoy PERL, but it is not, and I don't expect it to ever be, my favorite language {ducks the hurled mugs}.

    Second, I don't see how maintaining a naked block is any more difficult than a labeled block. This might be due to my relatively short 8 years as a programmer, but it seems to me the psuedocode comments should pretty well fall into place when writing the loop. In a multi-leveled if structure I am in the habit of labeling most of my close brackets so those who are using editors that do not support matching bracket searches have less trouble debugging. So adding a beginning comment in place of a loop condition and then a comment at the end does not seem like a massive undertaking in my eyes. To some it may, and I guess this entire thread should not interest you and you can continue with your day.

    Third, you said you know what's going on without even thinking. I believe this is the problem with the whole sub-thread we are looking at here. This is no longer about PERL and it's not really even about programming at the root level. Many people will tell you the best way to improve is to make your own mistakes, and that forces you to have a fundamental understanding of the error. When I was in pre-veterinarian classes, my first chemistry class and my first biology class had us doing the most basic experiments possible. This was to help us to learn why the priciples existed, so we did not blindly memorize the work of others and have no real knowledge to make improvements of our own. Now I have been working with DBI for a while now, and many of the old scripts I come accross use ORAPERL. I change them to use the new way. I do not leave them because it used to be the vastly accepted way of doing it. If people did not question the ways things were done, there would be no USA, and I would probably be sitting in one of the English provinces banging away in COBOL and FORTRAN. I approve of all those who question the "accepted" ways, because this shows a person who has not rolled over and died. I refuse to crush the budding creativityof a programmer becuase I might not like the fact he used needless keystrokes to comment a naked block that seemed like a good way to go. I won't even argue that it is the best thing to do, but I will {obviously} defend their right to find out why it is or is not. Besides, your shop standards may be wildly different than mine, so that's why I suggested the monk who asked this question take it to their manager and group who will be maintaining this code. If they see it as good and not confusing then who are we to tell them different.

    Now, not to be stupid or to point out the obvious, but considering the author of this debated loop, and his long list of credentials, and his deep understanding of and link to the language itself, I cannot for the life of me figure out why this is even a matter of dispute.

    Lord Wrath
      yrav yam ,ylsuoivbo ,egaelim ruoY

      .etib tsrif eht ni teg nac I fi ees ot retaw eht ni daeh ym kcits ot denilcni ton m'I ,"luferac eb ,ereht srotagilla era ereht ,yeH" ,syas dna nisab revir nozamA eht ni sregnif ym gnilgnad em sehctac enoemos fi tub ,uoy tuoba wonk t'nod I

      .daeha og ,sllimdniw rewot yrovi deviecrep ta tlit dna mgidarap tnanimod eht trevbus ot deen evitaerc a evah uoy fI .lauqe detaerc era syaw lla ton taht tuo tniop ot ytirohtua eht dna ecneirepxe eht evah su fo wef a etiuq tub ,tI oD oT yaW enO nahT eroM s'erehT

        Secret Decoder Ring....
        % GET | perl -lne 'print scalar reve +rse if /yra?v/../oD/'

        yletanutrofun rehtar,

        .hsilgne ekil yltcaxe sesrap taht em To .cixelsid ma i that si meblorp ym fo traP .ereh srorre lacihpargopyt yna usecxe esaelp melborp eht fo trap sA

        .ewisrehto ro, syawedis, sdrawkcab, sdrawrof, edoc, htam, hsinaps, hsilgne eb ti rethew ;ykcliuq yllauqe (wonk i) seguagnal daer nac i nosaer emos roF

        .nwo reith hcae oT ,nuf evah

        (on a serious eton, while i can parse bare blocks mentally as quickly as a while(1) loop with little to on problems, that doesn't maen i think oneevery can. In edoc taht is for procudtion use, the code should eb as easy to daer as possible for eht average user, and that usullay means gniwollof idioms; tsuj like i t'nod normally tsop sdrawkcab text despite eht fact that i nac type ti as easily sa fordraw txet in tsom cases :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://136191]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2018-01-22 05:25 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (231 votes). Check out past polls.