{"thread":{"id":"12854","subject":"[PATCH] gitweb: Uniquify usage of subroutine prototypes","startedAt":"2008-03-25T12:11:54Z","lastAt":"2008-03-25T22:06:12Z","messageCount":3,"participants":["Jakub Narebski","Junio C Hamano","Rafael Garcia-Suarez"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"73036","messageId":"1206447114-29349-1-git-send-email-jnareb@gmail.com","threadId":"12854","inReplyTo":null,"subject":"[PATCH] gitweb: Uniquify usage of subroutine prototypes","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-25T12:11:54Z","receivedAt":"2008-03-25T12:11:54Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"The idea is NOT to use subroutine prototypes to create new syntax;\nprototypes are to be purely informational and optional.  Subroutine\nprototypes are meant in gitweb to mark untypical parameters, like\nhaving hash as an argument, or using hash for last parameter to pass\nextra options to subroutine.\n\n(Truth to be told this change was caused by the fact that CPerl mode,\nPerl mode for GNU Emacs, got confused in presence of \"sub name($) {\"\nprototype...)\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\n gitweb/gitweb.perl |   10 +++++-----\n 1 files changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex ec73cb1..ee5cbd6 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -587,7 +587,7 @@ exit;\n ## ======================================================================\n ## action links\n \n-sub href(%) {\n+sub href (%) {\n \tmy %params = @_;\n \t# default is to use -absolute url() i.e. $my_uri\n \tmy $href = $params{-full} ? $my_url : $my_uri;\n@@ -740,7 +740,7 @@ sub esc_html ($;%) {\n }\n \n # quote control characters and escape filename to HTML\n-sub esc_path {\n+sub esc_path ($;%) {\n \tmy $str = shift;\n \tmy %opts = @_;\n \n@@ -754,7 +754,7 @@ sub esc_path {\n }\n \n # Make control characters \"printable\", using character escape codes (CEC)\n-sub quot_cec {\n+sub quot_cec ($;%) {\n \tmy $cntrl = shift;\n \tmy %opts = @_;\n \tmy %es = ( # character escape codes, aka escape sequences\n@@ -780,7 +780,7 @@ sub quot_cec {\n \n # Alternatively use unicode control pictures codepoints,\n # Unicode \"printable representation\" (PR)\n-sub quot_upr {\n+sub quot_upr ($;%) {\n \tmy $cntrl = shift;\n \tmy %opts = @_;\n \n@@ -982,7 +982,7 @@ use constant {\n };\n \n # submodule/subproject, a commit object reference\n-sub S_ISGITLINK($) {\n+sub S_ISGITLINK {\n \tmy $mode = shift;\n \n \treturn (($mode & S_IFMT) == S_IFGITLINK)\n-- \n1.5.4.4\n"},{"id":"73066","messageId":"7vlk46lh61.fsf@gitster.siamese.dyndns.org","threadId":"12854","inReplyTo":"1206447114-29349-1-git-send-email-jnareb@gmail.com","subject":"Re: [PATCH] gitweb: Uniquify usage of subroutine prototypes","fromName":"Junio C Hamano","fromEmail":"junio@pobox.com","sentAt":"2008-03-25T19:47:34Z","receivedAt":"2008-03-25T19:47:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Jakub Narebski <jnareb@gmail.com> writes:\n>\n>> The idea is NOT to use subroutine prototypes to create new syntax;\n>> prototypes are to be purely informational and optional.\n\nThat's unfortunately a grave misconception, isn't it?\n\nFor example, can you explain (1) how these three calls behave before\nrunning them, and (2) why these three behave the way they do?\n\n        sub foo       { my ($s, %f) = @_; print \"s = $s\\n\"; }\n        sub bar ($;%) { my ($s, %f) = @_; print \"s = $s\\n\"; }\n\n        my @it = ('This is my string');\n        my %hash = (rose => 'blue', violet => 'green');\n\n        foo @it, %hash;\t\t# call 1\n        bar @it, %hash;\t\t# call 2\n\tbar $it[0], %hash;\t# call 3\n\nBy adding ($;%) to an existing function that did not have prototype, you\nchanged the semantics of the function and:\n\n (1) it is your responsibility to make sure you did not break existing\n     callers when you made such a change, and\n\n (2) programmers who want to call any existing function in your program\n     need to check how the function groks its parameters and make sure\n     they do not fall into the same pitfalls as the call sites you had to\n     fix in step (1).  They cannot rely on the old fashioned \"arguments\n     are passed as a flattened list\" idiom anymore before checking if you\n     have prototypes to the function they want to call.\n\nPrototypes used carelessly tend to force users to do unnecessary things,\nbecause the caller cannot rely on the old fashioned \"arguments are passed\nas a flattened list\" semantics and check how each and every function is\nprototyped before making a call.\n\nI am not saying that Perl prototypes is a bad thing.  The point of the\nprototype is to change the syntax and semantics so that you can write a\nfunction to which arguments are _not_ passed as a flattend list, and\nwithout them you cannot write something that emulates \"push @a, $b, $c\".\n\nBut you need to be aware of what it does to your callers.\n"},{"id":"73077","messageId":"b77c1dce0803251506y443aab5uf0134a47e9cf28de@mail.gmail.com","threadId":"12854","inReplyTo":"7vlk46lh61.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] gitweb: Uniquify usage of subroutine prototypes","fromName":"Rafael Garcia-Suarez","fromEmail":"rgarciasuarez@gmail.com","sentAt":"2008-03-25T22:06:12Z","receivedAt":"2008-03-25T22:06:12Z","isPatch":true,"sender":{"key":"rgarciasuarez@gmail.com","avatar":null},"body":"On 25/03/2008, Junio C Hamano <junio@pobox.com> wrote:\n>  I am not saying that Perl prototypes is a bad thing.  The point of the\n>  prototype is to change the syntax and semantics so that you can write a\n>  function to which arguments are _not_ passed as a flattend list, and\n>  without them you cannot write something that emulates \"push @a, $b, $c\".\n\nI would agree with what Junio says here. The primary motivation of\nprototypes was to emulate the syntax of perl built-ins, and their\nextension (with the _ character) in Perl 5.10 has followed this\ngeneral principle. As a general rule, I tend to avoid using prototypes\nfor 'normal' functions. That's mostly an application of the least\nsurprise principle.\n"}]}