Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Im I forking properly ?

by leostereo (Beadle)
on Apr 18, 2016 at 14:50 UTC ( [id://1160809]=note: print w/replies, xml ) Need Help??


in reply to Re: Im I forking properly ?
in thread Im I forking properly ?

just one thing ... Why is it so horrible to read??

Replies are listed 'Best First'.
Re^3: Am I forking properly ?
by Athanasius (Archbishop) on Apr 19, 2016 at 07:00 UTC

    Hello leostereo,

    Why is it so horrible to read??

    Because the haphazard indentation makes it almost impossible to tell, at a glance, where each logical block of code ends. Here’s the original version of sub write_register, with a single comment added:

    Now, quickly: which block of code is terminated by the right brace named X?

    Here’s a preliminary clean-up of the code, with consistent indentation:

    Easier to follow now? Yes, and that makes it easier to spot where it can be improved:

    1. As noted by Anonymous Monk++, the variables $output and $fver are never declared. In addition, the variable $bsid is neither declared nor initialized anywhere in the script.
    2. Perl allows you to return, exit, or die at any point in the code. Since these statements are forms of flow control, the code can often be simplified when these statements are used. For example, this:
      if (condition) { return; } else { ... }
      is logically equivalent to the shorter and simpler:
      return if condition; ...
    3. It’s bad practice to exit from a subroutine. You should die (i.e., throw an exception) instead: that way, the subroutine’s clients have the option to either handle the exception locally or allow it to propagate upwards and so terminate the script.

    Here’s an improved version of the subroutine:

    As a rule, the shorter and simpler the code, the easier it is to debug and maintain. Disclaimer: I haven’t looked at the code’s logic, only its form.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-05-25 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found