Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Avoiding silly programming mistakes

by JavaFan (Canon)
on Aug 20, 2008 at 09:56 UTC ( #705463=note: print w/ replies, xml ) Need Help??


in reply to Avoiding silly programming mistakes

I've been coding for over 30 years, and I'm still making "doh" mistakes. I keep misspelling Fcntl. I keep putting a comma after the filehandle in a print statement. I keep forgetting to put Exporter in @ISA, and then I wonder why my subs aren't exported. Oh, and the number of times I left of '1;' (or another true value) at the end of a module.

And then I write some C, and I keep forgetting parenthesis around function arguments. Or forget that my variables need to be declared upon entering a scope. And that they don't need sigils, but may need casting. And when my job still required me to use Pascal, I tried using /* */ comments in Pascal, and (* *) comments in C. Worse is trying to use // comments in C, as some compilers accept it, and others don't.

And when (interactively) querying a database, the client has to remind me over and over again that 'cd' and 'ls' aren't valid commands.

Retirement or death, which ever comes first, will be the moment I stop making "doh" mistakes.


Comment on Re: Avoiding silly programming mistakes
Re^2: Avoiding silly programming mistakes
by GrandFather (Cardinal) on Aug 20, 2008 at 10:11 UTC

    Golly! At least 2/3 of those errors are caught by using strictures or a decent syntax highlighting editor!


    Perl reduces RSI - it saves typing
      Your point being?

      Sure, when I make them, they are quick to fix. But I still make them. Over and over again.

      strict and warnings detect (some) errors. But they don't prevent from making them.

        The OP was concerned about problems that can be slow to find and quick to fix. My point is that an early heads up about typos and other similar errors can save a lot of time.


        Perl reduces RSI - it saves typing

        Read the documentation carefully, pay attention, sleep well, take pauses and don't drink. Those may help in preventing making mistakes, but does not guarantee they won't happen. I'm a bit far from 22 years of experience in programming and still make silly mistakes. Good practices like the ones pointed by GrandFather will help spotting errors faster.

        In your comments I don't see you helping missingthepoint either not making mistakes nor figuring them out.

Re^2: Avoiding silly programming mistakes
by moritz (Cardinal) on Aug 20, 2008 at 10:12 UTC
    I keep forgetting to put Exporter in @ISA

    I don't really like to inherit from another module just to use one or two subs. Instead I write use Exporter qw(import);.

    And when (interactively) querying a database, the client has to remind me over and over again that 'cd' and 'ls' aren't valid commands.

    This happens to me all the time as well. When I use the mysql prompt and enter ls<return> I see my mistake, and then press Ctrl+C to abort the command. But of course Ctrl+C actually exists the client...

      When I use the mysql prompt and enter ls<return> I see my mistake, and then press Ctrl+C to abort the command. But of course Ctrl+C actually exists the client...

      I'd estimate I make the ctrl-c in mysql about twice a week. Of course, the only reason it's not once a day anymore is because I'm doing less database work.

      At this point, it's been years since I used Oracle, but I have problem overriding my old habits.

      Oh -- and as of mysql 5.1.10 -- ctrl-C aborts the running query, rather than dumping immediately. (still doesn't fix the problem when you're used to sqlplus and are just trying to clear the command, though).

Re^2: Avoiding silly programming mistakes
by rir (Vicar) on Aug 20, 2008 at 13:57 UTC
    Using a boilerplate to start a module will help with your problems with exportation and ultimate truth.

    The trick to using such templates is to make them congenial; make your own. Avoid building a template which is more comprehensive than you will be willing to alter.

    Here is what I'm currently using, minus pod.

    package XXX_name; use 5.008004; use strict; use warnings; require Exporter; our $VERSION = '0.01'; use Carp; use vars ( 'XXX_exported', '@EXPORT' ); ## no critic use base qw/ Exporter /; @EXPORT = qw/ XXX_exported /; XXX_code_here 1;
    Be well,
    rir

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://705463]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2014-09-18 04:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls