On Fri, 25 Feb 2022 01:24:00 -0600 David Nicol <davidnicol@gmail.com> wrote: > IMO trim should operate in place in void context and return the > substring in nonvoid context. Optimizing Functions that do materially different things depending on context have been a constant annoyance to newbies and experts alike, ever since the language was first created. They are commonly agreed to be one of the worst mis-features of the entire language. What does this do? sub shortname { my $self = shift; return trim( $self->{fullname} ); } Does it mutate the object instance, or not? Perhaps it depends on the caller. Maybe far away in a script somewhere many files away: printf "My shortname is %s\n", $user->shortname; $user->shortname; printf "Fullname is now %s\n", $user->{fullname}; Oops. We just broke the object. This sort of "spooky action-at-a-distance" makes it hard to build robust code and reason about its behaviour in small modular pieces. -- Paul "LeoNerd" Evans leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/Thread Previous | Thread Next