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

[PATCHv2 1/5] gitweb: Remove function prototypes

From
Jakub Narebski <jnareb@gmail.com>
Date
May 10, 2009, 00:05 UTC
Message-ID
<200905100205.23733.jnareb@gmail.com>
In-Reply-To
<200905100203.51744.jnareb@gmail.com>

Use of function prototypes is considered bad practice in Perl. The ones used here didn't accomplish anything anyhow, so they've been removed.

>From perlsub(1):
  [...] the intent of this feature [prototypes] is primarily to let
  you define subroutines that work like built-in functions [...]
  you can generate new syntax with it [...]

We don't want to have subroutines behaving exactly like built-in functions, we don't want to define new syntax / syntactic sugar, so prototypes in gitweb are not needed... and they can have unintended consequences.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Perl::Critic::Policy::Subroutines::ProhibitSubroutinePrototypes
  Don't write 'sub my_function (@@) {}'.
  Contrary to common belief, subroutine prototypes do not enable
  compile-time checks for proper arguments. Don't use them.

See also Damian Conway's book "Perl Best Practices", chapter "9.10. Prototypes" (Don't use subroutine prototypes.)

This follows similar patch for git-send-email.perl by Bill Pemberton. Also "sub S_ISGITLINK($) {" line caused `imenu` in my old cperl-mode (4.23) in GNU Emacs 21.4.1 to fail, sometimes.

This patch was send with slightly different commit message as standalone patch earlier. This is the replacement patch, which differs only in the commit message.

 gitweb/gitweb.perl |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 3f99361..06e9160 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -838,7 +838,7 @@ exit;
 ## ======================================================================
 ## action links
 
-sub href (%) {
+sub href {
 	my %params = @_;
 	# default is to use -absolute url() i.e. $my_uri
 	my $href = $params{-full} ? $my_url : $my_uri;
@@ -1036,7 +1036,7 @@ sub esc_url {
 }
 
 # replace invalid utf8 character with SUBSTITUTION sequence
-sub esc_html ($;%) {
+sub esc_html {
 	my $str = shift;
 	my %opts = @_;
 
@@ -1296,7 +1296,7 @@ use constant {
 };
 
 # submodule/subproject, a commit object reference
-sub S_ISGITLINK($) {
+sub S_ISGITLINK {
 	my $mode = shift;
 
 	return (($mode & S_IFMT) == S_IFGITLINK)
@@ -2615,7 +2615,7 @@ sub parsed_difftree_line {
 }
 
 # parse line of git-ls-tree output
-sub parse_ls_tree_line ($;%) {
+sub parse_ls_tree_line {
 	my $line = shift;
 	my %opts = @_;
 	my %res;
@@ -3213,7 +3213,6 @@ sub git_print_header_div {
 	      "\n</div>\n";
 }
 
-#sub git_print_authorship (\%) {
 sub git_print_authorship {
 	my $co = shift;
 
@@ -3269,8 +3268,7 @@ sub git_print_page_path {
 	print "<br/></div>\n";
 }
 
-# sub git_print_log (\@;%) {
-sub git_print_log ($;%) {
+sub git_print_log {
 	my $log = shift;
 	my %opts = @_;
 
-- 
1.6.3
Previous: Jakub NarebskiNext: Jakub Narebski
Message 2 of 16 in “gitweb: Some code cleanups (up to perlcritic --stern)”
  1. 0/5 gitweb: Some code cleanups (up to perlcritic --stern)Jakub Narebski, May 10, 2009
  2. 1/5 gitweb: Remove function prototypesJakub Narebski, May 10, 2009
  3. Jakub NarebskiMay 10, 2009
  4. 2/5 gitweb: Do not use bareword filehandlesJakub Narebski, May 10, 2009
  5. Petr BaudisMay 10, 2009
  6. Jakub NarebskiMay 10, 2009
  7. 2/5 gitweb: Do not use bareword filehandlesJakub Narebski, May 11, 2009
  8. 3/5 gitweb: Always use three argument form of openJakub Narebski, May 10, 2009
  9. 3/5 gitweb: Always use three argument form of openJakub Narebski, May 11, 2009
  10. 4/5 gitweb: Localize magic variable $/Jakub Narebski, May 10, 2009
  11. 5/5 gitweb: Use block form of map/grep in a few cases moreJakub Narebski, May 10, 2009
  12. Junio C HamanoMay 11, 2009
  13. Jakub NarebskiMay 11, 2009
  14. Junio C HamanoMay 11, 2009
  15. Daniel PittmanMay 11, 2009
  16. Jakub NarebskiMay 11, 2009

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.