Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Perl aesthetics: the good, the bad, the ugly.

by PotPieMan (Hermit)
on May 01, 2002 at 14:48 UTC ( #163271=note: print w/replies, xml ) Need Help??

in reply to Perl aesthetics: the good, the bad, the ugly.

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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2021-04-17 04:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found