[geeks] Misuse of Java

David Cantrell david at cantrell.org.uk
Wed Nov 6 17:54:55 CST 2002


On Wed, Nov 06, 2002 at 05:18:06PM -0500, Joshua D Boyd wrote:
> On Wed, Nov 06, 2002 at 10:09:53PM +0000, David Cantrell wrote:
> > > Also, I find parameter passing between functions to be amazingly insane,
> > If you mean pass-by-reference, then I beg to disagree.  There are times
> > when that's actually quite useful.  The recommended idiom makes that go
> > away anyway
> I was refering to having all the arguments be in @_. 

Oh, you mean not having named parameters.  Just about everyone* writes their
subroutines like so:

sub mysubroutine {
	my($foo, $bar, $baz) = @_;
	...

although I prefer to pass a hash and then do something like:

sub mysubroutine {
	my %args = @_;
	...

or if I want some of the parameters to be optional and have reasonable
defaults:

sub mysubroutine {
	my %args = (
		'foo'	=> 'rabbit',
		'bar'	=> sqrt(2),
		'baz'	=> 'nuclear weapon',
		@_
	);
	...

You'd call it like so:

$returnvalue = mysubroutine(
	'foo'	=> something,
	'bar'	=> something else
);

It's pretty easy to extend this to make parameters compulsory, ensure they
are of the right type, check that they're in the right range, and so on,
with the Params::Validate module.  Actually, that typifies what I like
about perl.  By default it doesn't get in your way and yes, it lets you
shoot yourself in the foot if you tell it you want to.  But on the other
hand, you can introduce as much bondage and discipline as you like, and
introducing a sensible level of bondage and discipline is really easy.

* - for values of everyone which exclude shitty programmers.  I don't care
about shitty programmers.  If I have to maintain their code, I tend to
rewrite it cos it's faster to do that.  This applies to other languages
too.

-- 
Grand Inquisitor Reverend David Cantrell | http://www.cantrell.org.uk/david

         Nuke a disabled unborn gay baby whale for JESUS!



More information about the geeks mailing list