git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Dan Zwell <dzwell@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] Git.pm: Don't return 'undef' in vector context.
Date: Thu, 15 Nov 2007 22:39:26 -0800	[thread overview]
Message-ID: <7vfxz61yox.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <473D3593.9080806@zwell.net> (Dan Zwell's message of "Fri, 16 Nov 2007 00:15:47 -0600")

Dan Zwell <dzwell@gmail.com> writes:

> Previously, the Git->repository()->config('non-existent.key')
> evaluated to as true in a vector context. Return an empty list
> instead.
> ---
> I don't know whether this breaks anything, because I don't use most of
> the git perl scripts. I can't imagine that there is a script that
> relies on the fact that config('non-existent.key') actually returns
> (''), in an array context. Is this a reasonable change?

I did not examine the callers but my gut feeling is that it
would be simpler and cleaner to always return () without
checking the context.  In scalar context:

	sub null {
        	...
                return ();
	}
	my $scalar = null();

would assign undef to $scalar anyway.

I generally try to stay away from functions that changes their
return values depending on the context, because they tend to
make reading the callers to find bugs more difficult.  An
exception is a function that tries to mimic a built-in operator,
because reading the callers to such a function, as long as it is
clear which built-in the function is imitating, can apply the
same knowledge on how the callee would behave you already have
by knowing Perl itself.

The same thing can be said about functions with prototypes to
force certain context on the caller's side.  Avoid it unless
there is a good reason.

Maybe it is just me, but that's my reaction.

  reply	other threads:[~2007-11-16  6:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-16  6:15 [PATCH] Git.pm: Don't return 'undef' in vector context Dan Zwell
2007-11-16  6:39 ` Junio C Hamano [this message]
2007-11-16  8:00   ` Dan Zwell
2007-11-17  0:39     ` Junio C Hamano
2007-11-16 12:47   ` Sebastian Harl
2007-11-16  8:43 ` Jakub Narebski
2007-11-17  3:20   ` Dan Zwell
2007-11-17 15:19     ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vfxz61yox.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=dzwell@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).