Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Yes, simple lexical scoping (a variable is known from its point of declaration to end of scope) and deterministic destructors are two things I find enjoyable when using both Perl and C++ ... and I feel confused and frustrated when forced to use the ugly and complex Python scoping workarounds introduced with the global and nonlocal (sic) keywords.

To give an illustrative example, Python happily compiles and runs the typo-riddled program below, printing vanilla:

icecream_flavour = 'vanilla' # ... if 1: icecream_flavor = 'chocolate' print(icecream_flavour)
while Perl detects the typo at compile-time:
use strict; my $icecream_flavour = 'vanilla'; # ... if (1) { $icecream_flavor = 'chocolate'; } print $icecream_flavour;
with the error message:

Global symbol "$icecream_flavor" requires explicit package name (did you forget to declare "my $icecream_flavor"?) at t1.pl line 5.
Execution of t1.pl aborted due to compilation errors.

Update: As pointed out by LanX below, this is an unfortunate example of Python violating the Zen of Python, specifically "Explicit is better than implicit". I feel it further violates "Beautiful is better than ugly" and "Simple is better than complex" and "Errors should never pass silently" and "If the implementation is hard to explain, it's a bad idea".

See also (further update):


In reply to Re^2: A short whishlist of Perl5 improvements leaping to Perl7 by eyepopslikeamosquito
in thread A short whishlist of Perl5 improvements leaping to Perl7 by rsFalse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found