in reply to Re: A question of efficiency
in thread A question of efficiency

I just want to add my two cents and point out that the anti-.* attitude here theatens to install voodoo programming ideas in newcomers...

.* is often non-optimal, but it is very bad system of choosing which way to do it if you are using dogmatic rules.

Isn't the point of having many ways to do it the fact that the best way depends on context? Rather than encouraging bondage, I think it is healthier to encourage understanding of the cases where it causes problems.

In this case you're right that it would be more efficient to replace it, but not because .* is bad... simply because it's more work than is needed. On the bright side, since the regex is anchored the .* is a very small performance hit, not the order of magnitude that is caused by truely awful uses of it.
--
Snazzy tagline here

Replies are listed 'Best First'.
(Ovid) Re(3): A question of efficiency
by Ovid (Cardinal) on Jul 18, 2001 at 19:38 UTC

    Note: None of what follows applies to the original poster who started this thread. This is merely my following up on a thought that Aighearach sparked.

    Aighearach wrote:

    I just want to add my two cents and point out that the anti-.* attitude here theatens to install voodoo programming ideas in newcomers...

    I have to confess that I'm rather ambivalent about this. I'm starting to get to the point where I don't even want to bother to point out good programming practices. Obviously, simply saying "don't use dot star" or "you must use strict" is not sufficient. premchai21 did provide a link to back up what was said, but I'm discovering more and more that people don't give a fig about how to program well.

    That raises an interesting question: do we just answer questions for people, or do we take the trouble to care about the quality of answers? Dominus, if I understood him correctly, seems to argue for the just answer the question camp (in a reply to a review that I wrote about Perl and CGI for the World Wide Web). Specifically, he wrote:

    I've heard plenty of arguments that you have to learn these style rules right from the beginning, apparently from people who think that if you once turn down the Path of Darkness your Soul is Lost Forevermore, and I think it's bullshit.

    I differ on this. Have you ever studied chess with an expert? Or the martial arts, tennis, or anything require great skill? One of the most common complaints from experts in various fields is that they are sick and tired of trying to get people to "unlearn" bad habits. Quite often, these people are a lost cause. Teach them right from the beginning and you don't have to fight that fight.

    That being said, so what? I, for one, am getting discouraged at giving answers and being told that I'm over the top (which I may very well be). I constantly see newbies telling more experienced people that they don't want to use strict. They don't need to use warnings. <sarcasm>They know exactly what they are doing but won't we please, please point out the one little bug in their program and then they'll ignore the other advice because they're clearly good enough to do without it anyway.</sarcasm>

    If you check out my posts, you'll notice that I haven't been posting as much lately. That's due, in large part, because of this issue. I'm still showing up and reading the threads because I want (need) to continue to improve my Perl. Plus, I have a lot of friends that I've met here that I want to keep in touch with, but I'm getting burnt out on helping people who don't want to be helped.

    I suppose I'm probably just in a funk right now and I'll snap out of it.

    Cheers,
    Ovid

    Vote for paco!

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      Actually, I am an avid chess player and I never hear unlearning bad habits discussed. Actually a more common thing for the Masters to say is similiar to Perl's TMTOWTDI... it's something like, "the positional rules are generally good advice, but actually it's the exceptions that are most important."

      Personally, I think it's pretty much a law of nature. Not only the organisms with the highest populations survive, and survival techniques that would fail in most places, are ideal in others. I have a hard time seeing how this would fail to be true in all complex systems.
      --
      Snazzy tagline here

        Aighearach wrote:

        Not only the organisms with the highest populations survive, and survival techniques that would fail in most places, are ideal in others.

        You are right about techniques that fail in some places surviving in others. But what does this have to do with good coding practices?

        Scenario: Creature 'foo' has stubby little legs that doesn't allow it to outrun creature 'bar'. Thus, bar eats foo and discovers a belly fully of credit card numbers because foo didn't use taint checking or strict or ...

        This analogy is fails because Darwinian arguments don't reflect the nature of programming. If some deer in the wild dies, he doesn't take me down with it. If someone's database munging script is corrupting data, those are my medical records that are being screwed up.

        As for the chess analogy: I'm sure you've tried to teach someone how to play chess. You've probably patiently explained why opening with a rook pawn is a bad idea. You've probably explained why getting the queen into the fray early is not wise. Perhaps you've explained why using the King's gambit against a player with superior tactics is a stupid. If so, you're helping them unlearn bad habits, even if you didn't use that term.

        I remember how patiently my first Kung Fu instructor kept explaining to me why I need to curl my toes on a front snap kick. I didn't "unlearn" my bad habit of keeping my toes straight until I actually kicked something one day and nearly broke every toe. Pain is a great teacher. In fact, that's how I think most people learn. In chess, the pain of losing teaches those who wish to learn. After I hurt my foot and hobbled for a few days, I learned to curl my toes when I kick. After some programmer gets fired for ruining their company's data, perhaps that programmer will "unlearn" bad habits.

        Cheers,
        Ovid

        Vote for paco!

        Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.