Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
On fuction definition: I prefer specifying the parameters up front. In a way, the function is self-documenting if you force yourself to specify the parameters. Of course, you can document your %args hash, but chances are you'll forget. (In my experience, it's better to be skeptical about one's willingness to document.)

Compare the following (which are directly from your writeup):

### Parameters explicitly listed sub createIndex { my ($dbh, $indexName, $frontend, $backend, $scoring) = @_; ... } ### Parameters passed in by hash, but no documentation sub createIndex { my %args = @_; ... }

If I'm new to a project, or if I'm coming back to a project after a few months working on something else, the second version becomes more difficult to use/modify/understand - the method becomes less of a "black box", in my opinion.

I'm going to be somewhat of a heretic here, and say that function definition in other languages, such as C, C++, and Java, looks better and is easier to understand. For example,

public void createIndex(Connection conn, String indexName, String fron +tend, String backend, int scoring) { ... }

For me, the only issue with this is flexibility. If you don't want one of the parameters (say, scoring), you have to overload createIndex with a second instance of the method. Done wrong, this could lead to code duplication. Done right, there is one "base" method that can handle all cases, meaning no code is duplicated. It's just not as flexible as the Perl version.

A lot of my time recently has been spent considering how another programmer sees my code (another programmer was recently hired where previously I was the only one). We had to come up with certain rules for Perl programming, rules that we sort of took for granted in Java. This suggests, as you say, that Perl allows you to be more creative - but you have to weigh your creativity against your need to get the job done. I'm not saying that you can't have both - I program because I am creative. I've found that on the job, you have to be careful about how you program.

Update: Fixed a typo.


In reply to Re: Perl aesthetics: the good, the bad, the ugly. by PotPieMan
in thread Perl aesthetics: the good, the bad, the ugly. by vladb

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.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-15 15:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found