Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
I'll try to be very careful not to disturbe piece in the monastery. Intuition tells that this will be a tough errand...

First of all: why build-ins only? Don't you want all your subs to do the same? And if not - why?

Second: if what you wish were possible (and easy), that wouldn't work, you'd wish your wish back. Sometimes you want it to die, sometimes - do smth. else. E.g.:
for each dir ( dirs) # I am using pseudo-code...:-) => if chdir(dir) => do smth. there => else ==> print_warning(couldn't go to dir, skipping) ......


I think this whole problem is illusive, artificial and leads astray. Even worse; it hides the real problem. The real problem is: having a programming discipline. Monks must know what dicipline means, right? If one dont's check EVERY RESULT OF EVERY SINGLE CALL, whatever is the language, -- well I say (s)he still has a lot to learn.

Now, the most dangerous part. This ~shouldn't~ have anything to do with Perl. Seems that somehow it does. I'd really like to hear a scientific explanation. My best guess is: "Less typing" is a very popular paradigm among Perl programmers. Historical reasons? philosophical?..

In other words, a solution:
die unless chdir($dir);
doesn't even come to mind. (!!!!!!!)

Well, less typing won't save you your development time. On the contrary.

I often see one line of code where I would *automatically* without thinking type six. E.g.: ...
if kind($matter) == "solid" { dig_it($matter); } eslif kind($matter) == "liquid" { die "We don't support underwater activities yet"; } else { die "RTErr: Unexpected type of matter!";}


Instead, many people type only the 2nd line, some - 1st and 2nd, more rare - also 3d and 4th, and almost nobody - 5th and 6th.

Well you know what: those few extra lines save weeks of debugging.
So from all points of view the answer is very simple: get used to typing more.

Now, when you get to the discipline to always surround any call with if() or if(!...) or die unless..., only then the question "How to type less?" should be risen. There're plenty of techiques for achieving that...:-).

PS: Coding for production vs. "prototyping and for one-off scripts" in two different styles is IMHO also a terrible mistake. This way, you'll strep into same traps twice.

Sorry for such a long and emotional post. Just spent a weekend cleaning up smb. else's mess....

In reply to Re: wishlist: die-on-failure for built-ins by Mabooka-Mabooka
in thread wishlist: die-on-failure for built-ins by tlm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.