git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Git.pm: Don't return 'undef' in vector context.

From
Sebastian Harl <sh@tokkee.org>
Date
Nov 16, 2007, 12:47 UTC
Message-ID
<20071116124746.GW29439@albany.tokkee.org>
In-Reply-To
<7vfxz61yox.fsf@gitster.siamese.dyndns.org>
Hi,
On Thu, Nov 15, 2007 at 10:39:26PM -0800, Junio C Hamano wrote:
Show 13 quoted lines
> 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.
[...]
> 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.

In fact, if you simply return without any value, it will evaluate to "false" no matter which context it has been called in ("()" in list context, "undef" in scalar context, etc.). So, it's generally a good idea to use "return;" to indicate an error.

Cheers, Sebastian

-- 
Sebastian "tokkee" Harl +++ GnuPG-ID: 0x8501C7FC +++ http://tokkee.org/

Those who would give up Essential Liberty to purchase a little Temporary
Safety, deserve neither Liberty nor Safety.         -- Benjamin Franklin
Previous: Junio C HamanoNext: Jakub Narebski
Message 5 of 8 in “Git.pm: Don't return 'undef' in vector context.”
  1. Git.pm: Don't return 'undef' in vector context.Dan Zwell, Nov 16, 2007
  2. Junio C HamanoNov 16, 2007
  3. Dan ZwellNov 16, 2007
  4. Junio C HamanoNov 17, 2007
  5. Sebastian HarlNov 16, 2007
  6. Jakub NarebskiNov 16, 2007
  7. Dan ZwellNov 17, 2007
  8. Jakub NarebskiNov 17, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.