betmatt has asked for the wisdom of the Perl Monks concerning the following question:

I was wondering if I could take the liberty to ask monks whether they have had thoughts on the absence of parenthesis in Python. And whether that has altered the evolution of the Python language in their opinion. Conversely also whether the presence of parenthesis has altered the evolution of Perl (Perl seems to encourage the condensing of complex code to one-liners - which is great if you have written the code yourself, but difficult for others to read). I was thinking about this yesterday when learning about immutable tuples in Python. I wondered whether Perl programmers would simply instead specify an array, as named, to a particular scope as specified by parenthesis. That is just one example, there must be loads of other examples like this.

Could a future version of Python finally adopt parenthesis? Do people have thoughts on that? I don't really understand why Python would ultimately not want to use parenthesise.

Update________

I have to apologise. I don't mean parenthesis, instead I mean nesting using curly brackets.

Replies are listed 'Best First'.
Re: Evolution of python
by soonix (Canon) on Jul 07, 2019 at 17:04 UTC
    Could a future version of Python finally adopt parenthesis braces? Do people have thoughts on that? I don't really understand why Python would ultimately not want to use parenthesise braces.
    Python began its life as a language for teaching of programming concepts. However, curlies aren't a concept themselves, they usually stand in for the concept of a block. Now, when blocks are written with curlies, it is very easy (especially for beginners) to misindent them, which makes it very easy (especially for beginners) to misinterpret the structure of the program. For this reason GvR chose indentation to denote blocks, which makes curlies unnecessary (and unwanted, because otherwise you'd have to set the curlies properly and correctly indent anyway)

    As soon as automatic prettyprinting / automatic aligning becomes mandatory (or even common), Python could go "back" to curlies. However, most programming languages are "free-form", so mandatory tidying might be seen as a step backwards. So, don't hold your breath for that to happen.

      It is so easy to press a tab key in an editor like Emacs to align the code correctly. In fact I actually enjoy that aspect of the coding process. The braces used in Perl help in viewing the code. There may be a tendency for Perl however to encourage a degree of nesting that would not be normal in Python. Has the development and use of functions and classes in Python been influenced by this? Was this a consideration when Python was first designed?

      The reason why I think that this is worth asking as a question: Maybe Perl designers need to consider whether some design rather than evolution is required on this aspect. I am not saying that Perl or Python is better, just that the issue is worth considering.
Re: Evolution of python (updated)
by haukex (Bishop) on Jul 07, 2019 at 11:58 UTC
    the absence of parenthesis in Python

    Sorry, but the premise of the question is a bit unclear to me. For example, Python requires parentheses on function calls (print("Hello")), while Perl makes them optional in many cases (print "Hello", map $_+1, 2, 3, ...). It is true that in Python, flow control statements such as if don't normally have parens around the condition, although you can add them - AFAICT, "if(b > a):" is the same as "if b > a:". It's also possible to write multiple statements on one line in Python. Perl does require the parentheses in such statements, except of course in statement modifiers. Also, Perl requires the braces around code blocks following if (...), unlike in other languages like C where they can be omitted for single statements.

    Perl seems to encourage the condensing of complex code to one-liners

    I don't think this is true. Perl simply offers the programmer a great amount of flexibility, and what the programmer does with that is up to them. Compared to other languages, writing Perl in a certain style consistently requires more discipline, partially because Perl code formatters like perltidy aren't perfect. I'm not saying that people who write "condensed" code are undisciplined - the fact that Perl gives a great amount of power, and that some people have taken the art of golfing to a new level using that power, is very cool! I'd say Perl encourages creativity - whether or not "creative" coding is appreciated in certain contexts, such as writing code other people need to work with, is another question ;-)

    the condensing of complex code

    I get the feeling that your question is more about this than about parentheses and brackets?

    Could a future version of Python finally adopt parenthesis?

    If you're asking whether a future version of Python would allow for more condensed code, then I'm willing to bet the answer is no - the strict indentation rules of Python is one of the major aspects of the language.

    I don't really understand why Python would ultimately not want to use parenthesise.

    Perhaps this helps: PEP 20 - The Zen of Python and PEP 8 - Style Guide for Python Code.

    Update:

    Update
    I have to apologise. I don't mean parenthesis, instead I mean nesting using curly brackets.

    Regarding whether Python will introduce something like blocks (by which I mean, blocks that can be used on a single line), see my answer above. Regarding Perl, see Acme::Pythonic ;-)

Re: Evolution of python
by eyepopslikeamosquito (Bishop) on Jul 07, 2019 at 12:43 UTC

    ask monks whether they have had thoughts on the absence of parenthesis in Python
    Parentheses are commonly used in Python and (unlike Perl) required when making function calls.

    Perl seems to encourage the condensing of complex code to one-liners
    As indicated in the "Which is the Most Popular Golfing Language?" section in this node, code golf is more popular in Python than Perl.

    - which is great if you have written the code yourself, but difficult for others to read
    Russian is difficult to read if you don't know Russian. Far more important than "readability" is "maintainability" - as described in more detail here.

    Update: BTW, see also Re^7: Curious about Perl's strengths in 2018 which contains a few quotes from Larry about Python (this whole long thread contains lots of interesting comparisons of programming languages). You can also find a long list of PM nodes comparing programming languages at Re: Honest question about Perl, Python and Ruby.

Re: Evolution of python
by stevieb (Canon) on Jul 07, 2019 at 15:58 UTC

    Instead of braces, Python uses specific indenting instead. It provides the exact same functionality as Perl's scoping braces:

    Python:

    # function definition def do_thing(name, country): print("Person's name: {}, country: {}\n".format(name, country)) # scoping a file operation with open("file.txt") as fh: # in file scope for line in fh.readlines(): # in for scope print(line) # file handle is now closed automatically

    Perl:

    # function sub do_thing { my ($name, $country) = @_; print "Person's name: $name, country: $country\n"; } # file { # file handle is scoped to this block open my $fh, '<', 'file.txt' or die $!; while (my $line = <$fh>){ # we're now in a lower-level scope print "$line\n"; } } # file handle is closed and unavailable here

    In the latter (Perl) example, I could left-justify all of the code, and it would work the same. Essentially, the indentation is for ease of reading. In Python, the indentation is mandatory. Get one indent spacing incorrect, and your program will either fail, or will cause weird issues, possibly in far-away code.

    One of the most basic problems Python newbies have is incorrect indenting. Sometimes Python will warn about it, but not always. However, in Perl, if you miss a closing brace, the process will fail, explaining what went wrong.

    "I wondered whether Perl programmers would simply instead specify an array, as named, to a particular scope as specified by parenthesis."

    If I'm understanding the question, yes, that's extremely common. It's called a lexical variable. If it's declared within a block, it is not accessible to any other part of the program (unless a reference is returned to it, but I digress).

      Scoping rules in python are very different to Perl (and extremely confusing for me*)!

      And to make things worse they changed between Py2 and Py3

      There are nothing like blocks, a function (def or lambda) is the smallest lexical unit.

      A variable on the class level becomes an attribute.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      *) Stack overflow has some discussions on that and you'd be surprised how often "experts" contradict themselves.

      Instead of braces, Python uses specific indenting instead. It provides the exact same functionality as Perl's scoping braces:

      I don't believe that this is true. I think that my $variable cannot be specified in Python. There does seem to be some differences offered by Perl.

        Python does not have lexical scope for variables. It has more or less dynamic scope.

        This is not relevant to the mechanism that provides the scoping levels, be it braces or indentation.

      I suspect the semantic white space makes the Python grammar ambiguous from a theoretical standpoint. Anyone have a proof of this?

      I ask as I was trying to think of how tools could be programmed to make the activity of programming easier for people with visual impairments. I think languages with clear block demarcations have advantages here.

        I suspect the semantic white space makes the Python grammar ambiguous from a theoretical standpoint.

        I'd be a bit surprised if that were the case... anyway, there's a Full Grammar specification available, and the source for the grammar is here.

Re: Evolution of python
by Anonymous Monk on Jul 09, 2019 at 17:58 UTC
    You can do vast disruption to the semantic meaning of a Python program by removing even a single 0x09 ASCII byte from the source code ... anywhere. Unlike braces, there is nothing to counter-balance the perhaps purely accidental removal of a TAB: there is no (missing ...) '}' which would allow the compiler to catch your mistake.
      The "significant whitespace problem" is one of the drawbacks of Python, IMO. I thought we deprecated that way back in make? That is, why would someone choose to do that, after having suffered through using make?

      In Python, I also miss having an enclosing block entity, to limit the scope of variables.

      And it seems it's too easy to accidentally create a tuple by grouping things in parens, which then returns the wrong type to something not expect an iterable. ARG!

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

Re: Evolution of python
by thechartist (Monk) on Jul 14, 2019 at 14:02 UTC

    The semantically meaningful white space in Python makes it unsuitable for quick admin tasks at the command line. I would also speculate that makes it unsuitable as a language for visually impaired users, as the fundamental assumption is that the code will be read, not parsed and output to either a screen reader or Braille output device.

    If any visually impaired users have some experience with this, please share it!

    I'm sure there are hacks to make this work 90% of the time, but how is a visually impaired user going to troubleshoot those times when there is space missing? The Perl philosophy is much more flexible in this area.