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."
"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."
The most powerful feature Python is missing (Score:4, Insightful)
The most powerful feature Python is missing
is curly braces.
Re: (Score:2)
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.
Re: (Score:3)
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.
Re: The most powerful feature Python is missing (Score:1)
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.
Re: (Score:2)
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.
Re:The most powerful feature Python is missing (Score:5, Funny)
not entirely true, try:
from __future__ import braces
Re:The most powerful feature Python is missing (Score:4, Informative)
Re: (Score:2)
yes, those f-strings are *quite* common by programmers fighting with indentation . . .
Re: (Score:3)
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.
Re: (Score:3)
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
Re: (Score:3)
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
Re: (Score:3)
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
Re: (Score:2)
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.
Re: (Score:2)
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.
Sharing data between processes (Score:2)
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.
Re: (Score:2)
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.
Re: (Score:3)
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.
Re: (Score:2)
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.
Re: (Score:3)
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.
Re: (Score:2)
Five (Score:5, Funny)
5. White space dependency removal. *ducks head*
Re:Five (Score:5, Insightful)
Re: Five (Score:2)
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
Re: (Score:3)
Re: (Score:2)
Enforced coding standards are Python does.
Re: (Score:2)
One World Order is what Python does.
Re: (Score:1)
Re: (Score:2)
True is that is.
Re: Five (Score:1)
How does an IDE divine which subroutine Iâ(TM)m currently targeting in a long nested program? Iâ(TM)ve made plenty of mistakes because I inadvertently backspaced out of an if statement and itâ(TM)s unclear where I am.
Re: Five (Score:4, Informative)
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.
Re: (Score:3)
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
Re: (Score:2)
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.
Re: (Score:2)
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.
Re: Five (Score:1)
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.
Re: (Score:2)
???
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
Re: (Score:1)
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.
Re: (Score:3)
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.
X...End X (Score:1)
I personally prefer a VB-like "X...End X" style. VB is inconsistent, but the idea itself has merit.
Types (Score:5, Insightful)
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.
Re: (Score:2)
def get_first_name(full_name: str) -> str:
Re:Types (Score:5, Insightful)
Re: (Score:2)
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
Re: (Score:2)
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
Re: (Score:2)
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).
Re: (Score:2)
That's actually rather insightful. "This one doesn't need maintaining". I wish I had thought of that.
Re: (Score:2)
many places are hiring Javascript programmers instead of software developers
Are you having a stroke?
Re: (Score:2)
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
Re: (Score:2)
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!
"A Slew of Useful Features" (Score:1)
Re: (Score:2)
Re: (Score:2)
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
Re: How about (Score:2)
Wait, your editor doesn't delete any extra whitespace at the end of lines? Even my old editor from the eighties (emacs) does that!
On a more serious note every editor support this and I cannot see any reason to not enable it by default. Why is this not default behavior?
Re: (Score:2)
You mean you can't understand how authors of text editors can't possibly have the same opinions on white space as you do?
Re: (Score:2)
What about automatic tab expansion/compression which MY old editor from the seventies did but emacs from the eighties couldn't figure out how to do (and now dare not be used because of genius language definitions as in Python).
Once upon a time programmers actually knew what ASCII characters meant. Those days are long gone.
Re: (Score:2)
You didn't address his point....why should a python program blow up and crash (or not run) because of a single extra space?
It's ridiculous to use white space as a syntactically relevant 'feature'. Most other languages don't do that, and with good reason.
Would it still be Python? (Score:2)
If it had ever feature anyone wanted, would it still be Python?
Misread title (Score:2)
Re: Would it still be Python? (Score:1)
No, it would be Haskell. If pretty too. ;)
Or rather, Common Lisp... uglified Common Lisp... C++-style Common Lisp!
No tail call recursion optimization? (Score:2)
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.
Re: No tail call recursion optimization? (Score:1)
* 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.)
Point-free is pIpes (Score:2)
(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.
Case or Switch Statement (Score:4, Informative)
[that is all]
Re: Case or Switch Statement (Score:1)
Pattern guards? :D
Re: (Score:1)
Those who do not understand Common Lisp / Haskell,
are doomed to reimplement it. Badly.
I'm always entertained about how lisp (and Haskell) weenies are so salty that their languages didn't take over the world. They have interesting ideas but the languages have serious flaws.
Re: (Score:2)
Language snobs view the programming world as being subordinate to development of computer languages. Meanwhile, no programmer is ever "doomed" to reimplement any programming language, they have better things to do.
I, for one, welcome our "insufficiently evolved programming language" overlords. The vast majority of programming is dedicated devices, not academics or general purpose applications. They ain't got time for that.
taint checking? (Score:2)
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.
Also missing... (Score:2)
python is not missing generics (Score:2)
The most powerful feature python is missing (Score:2)
Real multiline comments...
Ternary and reference operators (Score:1)
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.
Re: (Score:2)
He probably meant "var=(a<b)?a:b". The Python equivalent is "var=a if a<b else b" though I am stumped as to why the ?: operator was not copied.
Lifting the ridiculous 79-character PEP-8 limit? (Score:2)
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!
Displaying multiple files at once (Score:2)
How many 80-column windows can you fit across your screen's width? How many 132-column?