in reply to What's the correct and succinct way to refer to object attribute in (informal) description?

Peeking into attributes breaks encapsulation. It shouldn't be done under normal circumstances, so I'd consider it OK one needs to be wordy to tell others to do it.

With the new class feature, objects are no longer blessed hash references and their attributes (now called fields) can't be accessed without accessors, anyway.

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use 5.039.010; use experimental 'class'; class My { field $x :param :reader; } my $o = 'My'->new(x => 10); say $o->x; # No other way.

Update: Fixed a typo, thanks LanX.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
  • Comment on Re: What's the correct and succinct way to refer to object attribute in (informal) description?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: What's the correct and succinct way to refer to object attribute in (informal) description?
by LanX (Saint) on Jun 10, 2024 at 14:15 UTC
    > Peeking into attributes breaks encapsulation

    That's true, and I always defended the argument.

    But from my (limited) experience with Python it seems they generally don't care.

    Why is it so? Do they have a good a posteriori mechanism to override the attribute with accessor logic to fix potential problems?

    Or do they just succeed by being less anal?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      StackOverflow discussion about public attributes in Python.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Python also has no true read only values ("constants" are named with all caps but there's nothing mechanically in the language itself stopping code from changing the values they point to) so my days of not respecting their design chops have certainly come to a middle.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.