Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
Python Programming

InfoWorld Lists 'Four Powerful Features Python is Still Missing' (infoworld.com) 79

InfoWorld's senior writer calls Python a "living language," citing its recent addition of the "walrus operator" for in-line assignments and the newly-approved pattern matching.

"And they're only two of a slew of useful features that could be added to Python to make the language more expressive, more powerful, more suited to the modern programming world. What else might we wish for?" True constants - Python doesn't really have the concept of a constant value... [E]very time a name is used, Python goes to the trouble of looking up what object it's pointing at. This dynamism is one of the chief reasons Python runs more slowly than some other languages. Python's dynamism offers great flexibility and convenience, but it comes at the cost of runtime performance. One advantage of having true constant declarations in Python would be some reduction in the frequency of object lookups that take place during runtime, and thus better performance. If the runtime knows ahead of time that a given value never changes, it doesn't have to look up its bindings...

True overloading and generics - In many languages, multiple versions of the same function can be written to work with different kinds of input... PEP 3124, advanced in April 2007, proposed a mechanism for decorating functions to indicate they could be overloaded. The proposal was deferred rather than being rejected outright — meaning the idea was fundamentally sound, but the time wasn't right to implement it. One factor that might speed the adoption of overloading in Python — or cause the idea to be ditched entirely — is the implementation of the newly proposed pattern matching system.

In theory, pattern matching could be used under the hood to handle overload dispatch. However, pattern matching could also be given as a rationale for not implementing generics in Python, since it already provides an elegant way to dispatch operations based on type signatures. So we might get true overloading in Python one day, or its advantages might be superseded by other mechanisms.

The article lists two more features Python "probably won't get" — starting with multiline lambdas (anonymous functions). Guido van Rossum had argued in 2006 he couldn't find an acceptable syntax, and the article argues "there is probably no way to do it that doesn't involve creating a special case." And it argues the final missing feature is tail recursion optimizations, "where functions that call themselves don't create new stack frames in the application, and thus risk blowing up the stack if they run for too long.

"Python doesn't do this, and in fact its creators have consistently come out against doing so."
This discussion has been archived. No new comments can be posted.

InfoWorld Lists 'Four Powerful Features Python is Still Missing'

Comments Filter:
  • by wonkavader ( 605434 ) on Saturday August 01, 2020 @11:08PM (#60356629)

    The most powerful feature Python is missing
              is curly braces.

    • You forgetted the more important feature: code portability. ^_^

      Oh no, syntax changes! One machine ran 2.7, and other machine ran 3.x. Now my program broke because of different machines. o`O

      It is not backwards compatibility because it make both backwards and forwards, kind of a joke here. Sound like AmiMoJo kind of logic. ;)
      • If "curly braces" is all you can find wrong with it, I'd say its going well.

        I spent a lot of the nintey cussing out C for not adopting Pascals BEGIN/END. It was just as silly a complaint.

        • This is a lot different than begin/end or many other syntax denoting start and ends of function.

          Pythonâ(TM)s lack of braces or any denotation of end breaks cut and paste both internal and external and it introduces many bugs with an inadvertent backspace.

        • I don't really care what it is (though bash's thing of reversing the opening statement is a bit lame) as long as it's something concrete.

    • by youn ( 1516637 ) on Saturday August 01, 2020 @11:19PM (#60356653) Homepage

      not entirely true, try:
            from __future__ import braces

    • by roskakori ( 447739 ) on Saturday August 01, 2020 @11:52PM (#60356715)
      But Python supports curly braces... for dictionaries, sets and f-strings. :P
      • by hawk ( 1151 )

        yes, those f-strings are *quite* common by programmers fighting with indentation . . .

    • The most powerful feature Python is missing is curly braces.

      Well Guido wanted to include more curly braces, but Larry Wall kept hogging them all.

    • by dfghjk ( 711126 )

      From the article:
      "“I find any solution unacceptable that embeds an indentation-based block in the middle of an expression. Since I find alternative syntax for statement grouping (e.g. braces or begin/end keywords) equally unacceptable, this pretty much makes a multiline lambda an unsolvable puzzle.”

      IOW, it's an "unsolvable puzzle" because I insisted on the mistake of eliminating curly braces in favor of white space delineation in the very beginning.

      Also, how about Python threads not being an out

      • by HiThere ( 15173 )

        Just because you want what Python calls "multiprocessing" doesn't make what it calls "threads" a fraud. It' just means that they're not using words quite the same way you are.

        If that's not what you mean, then try saying it in a different way.

        And I'm not thrilled by messy nests of brackets and parens as a way of implementing blocks in the middle of an expression either. Better is allowing assignment of an arbitrary block to a variable, and then allowing that variable to be called. How to properly maintain

        • by ceoyoyo ( 59147 )

          One of the things that makes Python not C++ is that it's readable. Personally, I think the walrus operator is a terrible addition because it introduces an operator that does two very different things at the same time, which is difficult to read, prone to mistakes, and really only saves a very small amount of typing.

          Multiline lambdas ditto. Just make a function. Make it a nested function if you absolutely must. I think extensive anonymous functions are one of the worst things about Javascript, now that they

          • by narcc ( 412956 )

            Python isn't exactly the most readable language either. It tends to get really messy the instant you try to do something non-trivial. Classes are particularly ugly. It's the only language I know that makes you wish you were using Java.

            • by ceoyoyo ( 59147 )

              I guess that's down to a matter of taste. Setting aside the script monkey code, I'd much rather read some object oriented Python than most other things. It's not as good as Turbo Pascal though.

        • Just because you want what Python calls "multiprocessing" doesn't make what it calls "threads" a fraud. It' just means that they're not using words quite the same way you are.

          In Python, what's the efficient way to share a read-only data structure between two processes? Using the typical copy-on-write paradigm for shared memory turns into copy-on-read as reference counts are increased and decreased within each page of virtual memory.

      • Oh here we go, the GIL thing again...

        Why does Python alone cop this criticism when all those JS implementations, Ruby, OCaml, etc that also have GIL don't?

        Oh sure I know many modern variants of these languages have solved the problem, but if we're going to ignore all the modern solutions that solve the problems in Python that seems fair to me.

        • You just don't know what Ruby people talk about, then. It has always been an issue. Always. It is a known tradeoff.

          In Ruby if you need something to be different than that, you write it in C and celebrate the simple C API. That is what limits the complaints. But finding the best balance is discussed endlessly.

      • it's an "unsolvable puzzle" because I insisted on the mistake of eliminating curly braces in favor of white space delineation in the very beginning.

        Exactly.

        Whitespace should have no meaning and his insistence/fascination with using whitespace as syntactically important feature was a stupid thing to do. It's why I never really found much interest in Python. There was no valid reason not to use curly braces.

      • by sjames ( 1099 )

        There's no fraud with Python threads, they're just not the way you want them. It would be nice if they could run truly concurrently on a multi-core machine, but that doesn't make the current implementation a fraud.

        Perhaps you're too young to remember things like green threads.

    • Wrong. Very wrong.
  • Five (Score:5, Funny)

    by Tablizer ( 95088 ) on Saturday August 01, 2020 @11:09PM (#60356633) Journal

    5. White space dependency removal. *ducks head*

    • Re:Five (Score:5, Insightful)

      by K. S. Kyosuke ( 729550 ) on Sunday August 02, 2020 @03:30AM (#60356953)
      Or at least equal opportunity for African-American space?
    • White-space style is my favorite feature of Python and Haskell, to be frank. Ignoring white space leads to a hard to read obfuscated mess. Precisely because the layout of the code and of its structure can diverge. And curly braces do too. Precisely because you can put them everywhere, where it's not readily apparent for the reader.

      I don't know why some people are so up in arms about it. Too stupid to set "Don't use tab characters" and "Insert 2 spaces when TAB is pressed" in their editors? Or ban other code

      • by cruff ( 171569 )
        Ever hear of programs that will indent format code for you? How about enforced coding standards?
      • Re: Five (Score:4, Informative)

        by dfghjk ( 711126 ) on Sunday August 02, 2020 @07:42AM (#60357259)

        Indeed, compound the problem as a solution. Makes perfect sense in a Python sort of way. Start with a prejudice and work your way back to the answer.

        Block delimiters do not preclude proper use of white space, and proper use of white space does not ensure readable code. What is ensured, though, is that mandating white space semantics precludes other formatting options when those options are actually superior, such as in an example in that very article.

      • by HiThere ( 15173 )

        That's not the problem. I uses tabs to indent code in Python without any problem. It's true that if I want to submit it to a repository, I need to reformat it to replace tabs by spaces, but that's no problem. There are decent tools to do that automatically.

        It *was* a problem in some versions of Python2. Using spaces was a real PITA. Fortunately, they fixed that problem over a decade ago.

        OTOH, braces have their points....as long as you align open and closed braces. Sticking open braces at the end of a

        • by ceoyoyo ( 59147 )

          You don't need a tool. Search and replace does it just fine.

          Search for \t, replace with x number of spaces.

          Going the other way usually isn't too much of a problem, but can mess up someone's pretty comment art, which is why I use tabs as well.

          • by HiThere ( 15173 )

            Search and replace works well if you iterate starting with a newline boundary, or if the only tabs in the file are those used to indent lines. But my editor has a built in tool to do the job, and that's even easier.

        • And you just stumbled on the problem with Python. Even worse is that Python allows both spaces and tabs but not both. Merging code is hell.

          • by HiThere ( 15173 )

            ???
            That doesn't make any sense. Python *doesn't* allow you to mix spaces and tabs when indenting. Old versions of Python2 did, but I don't think that's been allowed recently. Of course, I must admit that I never wanted to do such a silly thing, so I never tested it.

            And since if I'm importing code, I want to ensure that it matches my standard approaches in more ways than just using tab indentation, I always process it before importing it anyway. Ensuring that it uses tab indentation is the simple part of

            • by guruevi ( 827432 )

              That's what I was saying though, it doesn't allow you to mix, so if one developer writes with spaces and you need code from another project that uses tabs, you're in for a big translation step. And it's often not as simple as replace \t with \s\s if you have to insert when you're already 2 or 3 levels down.

              Basically, I want a program to be able to merge and then I use my IDE to format my indentations. In Python that is virtually impossible since formatting your indentations requires knowledge.

      • White-space style is my favorite feature of Python and Haskell, to be frank. Ignoring white space leads to a hard to read obfuscated mess.

        Yeah, if only someone would invent a code-formatter then all our problems would be solved. But no one will ever do such a thing so your complaint is completely understandable.

      • Precisely because the layout of the code and of its structure can diverge. And curly braces do too.

        I personally prefer a VB-like "X...End X" style. VB is inconsistent, but the idea itself has merit.

  • Types (Score:5, Insightful)

    by michaelmalak ( 91262 ) <michael@michaelmalak.com> on Saturday August 01, 2020 @11:19PM (#60356655) Homepage

    Or, you know, type safety (even if it's optional, for backward compatibility).

    Or a fluent (chaining) API that makes sense and is consistent.

    I was pleasantly surprised to see Scala at #15 on the IEEE Spectrum list, given that it's usually in the mid-20's on the TIOBE and other lists. Although Python has a long and storied history, at this point, when it's not used for actual scripting, it's filling the role of Visual-Basic-for-functional-programming and I have to wonder (dare I hope) that some are abandoning Python for Scala.

    • Python added types in 3.6. The syntax is like this:

      def get_first_name(full_name: str) -> str:
      • Re:Types (Score:5, Insightful)

        by fph il quozientatore ( 971015 ) on Sunday August 02, 2020 @01:36AM (#60356851)
        But they do nothing without an external type-checking tool. They are defined as just glorified comments.
        • by HiThere ( 15173 )

          That's currently what they are, yes. But getting them working properly is the first step. And I think they need to add a modifier to them that is something like "const", meaning "the function will not change any values hanging off of this parameter. After they've got the syntax working and finalized, then it would be reasonable to start enforcing them. And the syntax needs to handle cases like "this parameter may be either a string, a tuple of bytes, or a tuple of ints". (After all, given proper interp

    • I have to wonder (dare I hope) that some are abandoning Python for Scala.

      Some are abandoning Python for Javascript.

      Well, not really. But many places are hiring Javascript programmers instead of software developers, and NodeJS is finding inroads into places where you or I would write a Bash one-liner and maybe alias it.

      You would not believe the defense I've seen for a "program" that runs a MySQL command and formats the output. We're talking a git history of a dozen commits, I have no idea how many dependencies, something on the order of three or four screenfulls of main applicat

      • Declared "unmaintainable" because nobody knows Bash, Python, or Perl anymore.

        I'm sure they meant "doesn't mean maintenance" by that (it probably doesn't, unlike the changes in NodeJS dependencies whenever someone breaks a package).

      • by narcc ( 412956 )

        many places are hiring Javascript programmers instead of software developers

        Are you having a stroke?

    • by HiThere ( 15173 )

      Functional languages are interesting, but for many purposes they are extremely inconvenient. Even Erlang had to compromise on all variables being immutable. I don't like to fight city hall, though, so I gave up on Erlang BECAUSE of the immutability. Yeah, I could have put all the variables that needed to change in a local dict, but everybody who supports Erlang was down on that. What I need to do is safe, but it can't be done reasonably with immutable variables.

      That lets out Scala and Clojure, too. Lis

    • I abandoned scala years ago... with every frigging subrelease they broke vital apis.. no thanks.
      Also the language is so convoluted (well what basically makes up the language on top of the small core)
      that 10 scala programs from 10 programmers are not readable by 30% of the others!

  • This is exactly the wrong path to follow.
    • yea, Python is accreting pretty low quality "improvements" at a frightening rate..I don't know when this happened, but developers seemed to have lost the discipline necessary to say 'no' to new features...
    • by mysidia ( 191772 )

      Features mainly asked for by Academics and Java/C++/JS programmers who either have not learned to work in Python or who are looking for an excuse not to.

      How useful in the development of real-world scripts and programs? Not very.... And unnecessary use of function-overloading by such developers could be a huge source of bugs and unmaintainable code.

      And regarding Lambdas... if someone is wanting multi-line ones, then they are overusing lambdas - the functional-inspired shortcuts are to aid in code r

  • If it had ever feature anyone wanted, would it still be Python?

  • That's kind of odd. Sure in the beginning it was considering some pretty heavy duty complier magic, but it's well understood now.

    Also, no multi-line lambdas seems like an odd wart. Then again, without braces and syntactic whitespace, yea, it's probably a real pain.

    • * Haskell does multi-line lambdas with syntactic white-space just fine.
      * And contains a braces style without white-space too, if you really want to torture yourself like a C++ boy.
      * (A description of point-free style has been left out, as to not traumatize the reader.)

      • (A description of point-free style has been left out, as to not traumatize the reader.)

        Suffice it to say that point-free notation [wikipedia.org] is the mathematical counterpart to piping the output of one program through another program without first bouncing it off a file.

  • by Glasswire ( 302197 ) on Sunday August 02, 2020 @02:42AM (#60356887) Homepage

    [that is all]

  • Anyone remember taint checking in perl? (the -T switch)
    Quite an useful feature: a boolean property "tainted" for every object, with "taintedness" being propagated to other variables if they were set in a manner depended on them. Useful as an extra security measure in preventing user input affecting for example file open or database commands.

    Would be useful in python also.

  • ... a way to denote block of code that does not involve the troublesome vagueness of indenting.
  • In fact, the standard implementation has a very useful 'namedtuple' generic. To say that generics are missing is to not understand that Python is compiled at startup (yes, I do know that compiled code can be cached). But there because it is compiled at startup, generics are easily implemented with eval(). In fact, that's how the standard implementation is 'namedtuple' is done. There are also many other recipes which boil down to the fact that you can write generic code inside of strings and then eval it
  • Besides white spaces and curly brackets, the thing I miss in Python is the simplicity of var = (a == b) ? a : b

    That and some way of passing a reference to function because x = func(x) is ugly and confusing.

  • Surely this has to be one of the most pointless restrictions self-inflicted upon the language.
    Sheesh, even the Teletype 43 and DECwriter III printing terminals I had to use for comp sci at university decades ago had 132 column lines!

Don't tell me how hard you work. Tell me how much you get done. -- James J. Ling

Working...