Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusingly, perlref calls a hash in the examples %array #16782

Closed
p5pRT opened this issue Dec 5, 2018 · 12 comments
Closed

Confusingly, perlref calls a hash in the examples %array #16782

p5pRT opened this issue Dec 5, 2018 · 12 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 5, 2018

Migrated from rt.perl.org#133712 (status was 'resolved')

Searchable as RT133712$

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2018

From choroba@matfyz.cz

Created by @choroba

The subject says it all. $array{ aaa }{ bbb }{ ccc } is confusing,
since it's a hash, not an array.

Patch attached.

Perl Info

Flags:
     category=docs
     severity=medium

Site configuration information for perl 5.29.6:

Configured by choroba at Wed Dec  5 23:20:19 CET 2018.

Summary of my perl5 (revision 5 version 29 subversion 6) configuration:
   Commit id: 421d395278133929e92518281fbc264c377cb281
   Platform:
     osname=linux
     osvers=4.4.162-78-default
     archname=x86_64-linux-thread-multi
     uname='linux still 4.4.162-78-default #1 smp mon nov 12 19:08:10 utc 2018 (a013c8b) x86_64 x86_64 x86_64 gnulinux '
     config_args='-Dusedevel -des -Dusethreads -Dprefix=/home/choroba/localperl'
     hint=recommended
     useposix=true
     d_sigaction=define
     useithreads=define
     usemultiplicity=define
     use64bitint=define
     use64bitall=define
     uselongdouble=undef
     usemymalloc=n
     default_inc_excludes_dot=define
     bincompat5005=undef
   Compiler:
     cc='cc'
     ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
     optimize='-O2'
     cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
     ccversion=''
     gccversion='4.8.5'
     gccosandvers=''
     intsize=4
     longsize=8
     ptrsize=8
     doublesize=8
     byteorder=12345678
     doublekind=3
     d_longlong=define
     longlongsize=8
     d_longdbl=define
     longdblsize=16
     longdblkind=3
     ivtype='long'
     ivsize=8
     nvtype='double'
     nvsize=8
     Off_t='off_t'
     lseeksize=8
     alignbytes=8
     prototype=define
   Linker and Libraries:
     ld='cc'
     ldflags =' -fstack-protector -L/usr/local/lib'
     libpth=/usr/local/lib /usr/lib64/gcc/x86_64-suse-linux/4.8/include-fixed /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/lib /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib /lib64 /usr/lib64 /usr/local/lib64
     libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
     perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
     libc=libc-2.22.so
     so=so
     useshrplib=false
     libperl=libperl.a
     gnulibc_version='2.22'
   Dynamic Linking:
     dlsrc=dl_dlopen.xs
     dlext=so
     d_dlsymun=undef
     ccdlflags='-Wl,-E'
     cccdlflags='-fPIC'
     lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'



@INC for perl 5.29.6:
     /home/choroba/localperl/lib/site_perl/5.29.6/x86_64-linux-thread-multi
     /home/choroba/localperl/lib/site_perl/5.29.6
     /home/choroba/localperl/lib/5.29.6/x86_64-linux-thread-multi
     /home/choroba/localperl/lib/5.29.6


Environment for perl 5.29.6:
     HOME=/home/choroba
     LANG=en_US.UTF-8
     LANGUAGE (unset)
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
     PATH=/home/choroba/perl5/bin:/home/choroba/bin:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/games:/usr/X11R6/bin:/opt/gnome/bin:.
     PERL_BADLANG (unset)
     SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2018

From choroba@matfyz.cz

0001-Call-a-hash-hash-in-the-documentation.patch
From 4f095002c0ee207d432500ebc63edc924f1d88b5 Mon Sep 17 00:00:00 2001
From: "E. Choroba" <choroba@cpan.org>
Date: Wed, 5 Dec 2018 23:49:57 +0100
Subject: [PATCH] Call a hash %hash in the documentation

Previously, %array was used which was confusing.
---
 pod/perlref.pod | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/pod/perlref.pod b/pod/perlref.pod
index cf3692212d..4982b65c8d 100644
--- a/pod/perlref.pod
+++ b/pod/perlref.pod
@@ -603,23 +603,23 @@ Similarly, because of all the subscripting that is done using single words,
 the same rule applies to any bareword that is used for subscripting a hash.
 So now, instead of writing
 
-    $array{ "aaa" }{ "bbb" }{ "ccc" }
+    $hash{ "aaa" }{ "bbb" }{ "ccc" }
 
 you can write just
 
-    $array{ aaa }{ bbb }{ ccc }
+    $hash{ aaa }{ bbb }{ ccc }
 
 and not worry about whether the subscripts are reserved words.  In the
 rare event that you do wish to do something like
 
-    $array{ shift }
+    $hash{ shift }
 
 you can force interpretation as a reserved word by adding anything that
 makes it more than a bareword:
 
-    $array{ shift() }
-    $array{ +shift }
-    $array{ shift @_ }
+    $hash{ shift() }
+    $hash{ +shift }
+    $hash{ shift @_ }
 
 The C<use warnings> pragma or the B<-w> switch will warn you if it
 interprets a reserved word as a string.
-- 
2.13.7

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2018

From @jkeenan

On Wed, 05 Dec 2018 23​:04​:52 GMT, choroba@​matfyz.cz wrote​:

This is a bug report for perl from choroba@​cpan.org,
generated with the help of perlbug 1.41 running under perl 5.29.6.

-----------------------------------------------------------------
[Please describe your issue here]

The subject says it all. $array{ aaa }{ bbb }{ ccc } is confusing,
since it's a hash, not an array.

Patch attached.

The code examples you are proposing to change were written by Larry Wall in commit 748a930 in March 1995. We haven't changed them in all that time ... which makes me suspect we have a reason for doing so (though I myself don't know what that reason is).

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2018

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2018

From @iabyn

On Wed, Dec 05, 2018 at 07​:07​:27PM -0800, James E Keenan via RT wrote​:

On Wed, 05 Dec 2018 23​:04​:52 GMT, choroba@​matfyz.cz wrote​:

The subject says it all. $array{ aaa }{ bbb }{ ccc } is confusing,
since it's a hash, not an array.

The code examples you are proposing to change were written by Larry Wall
in commit 748a930 in March 1995. We haven't changed them in all
that time ... which makes me suspect we have a reason for doing so
(though I myself don't know what that reason is).

I should imagine it's because until perl 5, hashes were called associative
arrays, and therefore using 'array' as the name for one of them was
reasonable at the time. I see no reason not to apply this patch.

--
The warp engines start playing up a bit, but seem to sort themselves out
after a while without any intervention from boy genius Wesley Crusher.
  -- Things That Never Happen in "Star Trek" #17

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2018

From @davidnicol

On Thu, Dec 6, 2018 at 3​:57 AM Dave Mitchell <davem@​iabyn.com> wrote​:

I should imagine it's because until perl 5, hashes were called associative
arrays, and therefore using 'array' as the name for one of them was
reasonable at the time. I see no reason not to apply this patch.

That's what we called them in data structures class at university.

Hash is either cannabis or corned beef and spuds, and the fact that Perl
implements its associative arrays with hash tables is an implementation
detail​: the interface would be just the same were they binary trees or
something else.

Associative arrays are called variously "maps" or "dictionaries" in the
nomenclature of other programming languages.

I guess I'm arguing to leave it alone, so we've got an example of calling
an associative array %array. It also drives home the point that the
differentiator is the sygill not the name.

--
"I don't know about that, as it is outside of my area of expertise." --
competent specialized practitioners, all the time

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2018

From jjuran@gmail.com

On Dec 6, 2018, at 12​:27 PM, David Nicol <davidnicol@​gmail.com> wrote​:

On Thu, Dec 6, 2018 at 3​:57 AM Dave Mitchell <davem@​iabyn.com> wrote​:

Hash is either cannabis or corned beef and spuds, and the fact that Perl implements its associative arrays with hash tables is an implementation detail​: the interface would be just the same were they binary trees or something else.

Unless you consider algorithmic complexity guarantees to be part of the interface. Also, is the hash table still an implementation detail when "hash" explicitly quotes it? That sounds like specified behavior to me.

Josh

@p5pRT
Copy link
Author

p5pRT commented Dec 8, 2018

From choroba@matfyz.cz

Here's the link to a confused newbie's question​:

https://www.perlmonks.org/?node_id=1226776

If we want to use "associative array", we should be consistent, and rename all the remaining hashes in the document (and probably other documents, too). But I find changing just these 6 lines much easier.

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2018

From @tonycoz

On Fri, 07 Dec 2018 17​:00​:53 -0800, choroba@​matfyz.cz wrote​:

Here's the link to a confused newbie's question​:

https://www.perlmonks.org/?node_id=1226776

If we want to use "associative array", we should be consistent, and
rename all the remaining hashes in the document (and probably other
documents, too). But I find changing just these 6 lines much easier.

I agree.

Thanks, applied as f06965b.

Tony

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2018

@tonycoz - Status changed from 'open' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented May 22, 2019

From @khwilliamson

Thank you for filing this report. You have helped make Perl better.

With the release today of Perl 5.30.0, this and 160 other issues have been
resolved.

Perl 5.30.0 may be downloaded via​:
https://metacpan.org/release/XSAWYERX/perl-5.30.0

If you find that the problem persists, feel free to reopen this ticket.

@p5pRT
Copy link
Author

p5pRT commented May 22, 2019

@khwilliamson - Status changed from 'pending release' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant