3 ms·
Many languages don't distinguish between statements and expressions—in some languages, this is because everything is an expression! I'm most familiar with these
by ashton314 7y ago
Many languages don't distinguish between statements and expressions—in some languages, this is because everything is an expression! I'm most familiar with these kinds of languages.
I'm not familiar much with Python, beyond a little I wrote in my linear algebra class. How much does the statement/literal distinction matter to readability? What does that do for the language?
- nerdponx 7y agoThe only reason I can imagine being opposed to it is fear that hordes of bad programmers will descend on the language and litter the ecosystem with unreadable golfed garbage. I obviously don't want that. I don't think anybody wants that. But I also don't think that's going to happen as a result of the recent changes in the language. If anything, I feel like the average code quality in the wild has gone up.
- yxhuvud 7y agoPython being the start language for newbies these days, you already have the hordes of bad programmers. Everyone is bad when they start out, after all.
- stakhanov 7y agoThe philosophy that most of Python's language design is based on is that for everything you want to do, there should be one and only one obvious way to do it. The first part of the statement (at least one obvious way to do it) goes to gaining a lot of expressive power from having learned only a subset of the language specification corresponding to the most important concepts. So you invest only a small amount of time in wrapping your head around only the most important/basic language concepts and immediately gain the power that you can take any thought and express it in the language and end up not just with some way of doing it, but with the right/preferred way of doing it. The second part of the statement (at most one obvious way to do it) makes it easy to induce the principles behind the language from reading the code. If you take a problem like "iterate through a list of strings, and print each one", and it always always always takes shape in code by writing "for line in lst: print( line )" it means that, if it's an important pattern, then a langauge learner will get exposed to this pattern early and often when they start working with the language, so has a chance to quickly induce what the concept is and easily/quickly memorize it due to all the repetition. -- Perl shows how not to do it, where there are about a dozen ways of doing this that all end up capable of being expressed in a line or two. -- Therefore, trying to learn Perl by working with a codebase that a dozen people have had their hands on, each one preferring a different variation, makes it difficult to learn the language, because you will now need to know all 12 variations to be able to read Perl reliably, and you will only see each one 1/12th as often making it harder to memorize.
- uryga 7y ago> "iterate through a list of strings, and print each one" print(*lst, sep='\n') :)
- stakhanov 7y agoThat's exactly what I'm talking about. A REAL python programmer would immediately recognize that to be the bullshit way that someone would do it, if proving what a f*ing master they are were more important to them than clarity.
- uryga 7y agoi do it when i'm in a REPL and want to minimize typing, but probably wouldn't put it in an actual program... so i guess we mostly agree
- ezrast 7y agoIt's natural for some operations to be used only for their side effects, and for those a return value is just noise. What does a while loop evaluate to in your favorite language? Are there any circumstances where you'd want to assign one to a variable? What do you lose by making that a parser error?
- uryga 7y ago> What does a while loop evaluate to in your favorite language? depends on what you want! for example this Haskell package¹ defines three versions of while: -- collect the result of each iteration into a list whileM :: Monad m => m Bool -> m a -> m [a] -- combine the result of each iteration together into a final result whileM' :: (Monad m, MonadPlus f) => m Bool -> m a -> m (f a) -- drop the results and return `()` whileM_ :: Monad m => m Bool -> m a -> m () by convention, the ones ending in an underscore (`forM_`, `whileM_`, `sequence_` etc) drop their results, i.e. are only used for their side-effects. ¹ http://hackage.haskell.org/package/monad-loops-0.4.3/docs/Control-Monad-Loops.html http://hackage.haskell.org/package/monad-loops-0.4.3/docs/Co...