TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

My Wish for Python 4

31 点作者 lumpa大约 4 年前

11 条评论

rchowe大约 4 年前
I think one of the nice things about Python is that most people write it in a similar way (with the exception of classes vs not and annotations). &quot;There should be one-- and preferably only one --obvious way to do it.&quot; There are already &quot;accents&quot; on how people write code, and the beginner dialect sounds a bit too close to Visual Basic to me.<p>There are some chances to smooth out some warts. I like typed languages like TypeScript, though I find Python&#x27;s type system not very natural comparatively.<p>My biggest gripe though is that it&#x27;s not possible to write functional code where you can read the operations in order. For a contrived example, if you wanted to know the total length of all strings in a list that start with the letter &#x27;a&#x27;, you would do the following in C#:<p><pre><code> strings .Where(s =&gt; s.StartsWith(&#x27;a&#x27;)) .Select(s =&gt; s.Length) .Sum() </code></pre> Each step follows the last: first you filter the list, then you get the lengths, then you add the lengths together.<p>The equivalent in Python is this (I broke it out into multiple lines for a better 1:1 comparison):<p><pre><code> sum( len(s) for s in strings if s.startswith(&quot;a&quot;)) </code></pre> Okay, maybe in this example the only difference is the location of the if, but in more complex example I really lose the flow by using list comprehensions.<p>And before anyone says I can use `map` and `filter` assign each step to a variable and write it in an &quot;imperative-ish&quot; style, I find it difficult to come up with descriptive names for each intermediary variable, and don&#x27;t want to call them `l1`, `l2`, etc.<p>Gripe over, hopefully I conveyed my message.
评论 #26188771 未加载
评论 #26191046 未加载
评论 #26188615 未加载
评论 #26188831 未加载
评论 #26192589 未加载
swagonomixxx大约 4 年前
&gt; [Yes, type annotations can be extremely useful, but they do not (currently) &quot;fit my brain&quot;.]<p>Why don&#x27;t they fit your brain? I wonder if the author ever tried statically typed languages.<p>&gt; I would like for Python 4 to get inspired by Racket and introduce &quot;dialects&quot;.<p>&gt; Having repeat as a keyword as is available in TygerJython and Reeborg&#x27;s World for the construct repeat nb_steps:. It might perhaps be also useful to have repeat forever: as equivalent to Python&#x27;s while True: . [Other possible uses of this keyword are described here.]<p>I don&#x27;t see how this would be beneficial. You&#x27;re basically proposing that beginners learn something that is literally not Python - then when they switch to the &quot;main&quot; dialect, they have to re-learn basic things all over again.<p>Lisps have this neat functionality where you get to basically define your own syntax, and that&#x27;s really useful in a small set of cases (i.e macros in Racket, super duper useful, would wish C macros were as clean as Racket macros). But Python simply does not fit this mold. It wouldn&#x27;t do Python any good to have a macro system - and it definitely wouldn&#x27;t do it good if it has 4 different sub-languages, each of which have it&#x27;s own syntax and warts.<p>Stroustrup said &quot;Within C++, there is a much smaller and clearer language struggling to get out.&quot; The Python the author is describing is to me, even worse than C++ in terms of complexity.
评论 #26189252 未加载
smitty1e大约 4 年前
My Python4 wishes would be to:<p>- make python packaging as polished as the rest of the language<p>- modularize the standard library a bit more, so that the precise chunks of battery to be included at install time can be more finely tuned<p>- start making the all the shiny new features (I grasp the marketing need for MOAR FEETURES!!!) to be library opt-ins. While I&#x27;m personally turned on by structural pattern matching, the anti-featuritis crowd has a point, too.
评论 #26189251 未加载
pizza大约 4 年前
I think having pluggable language features would be nice; on the one hand, you’d keep the “1 obvious way only” people happy- just don’t use it, or come to some agreement with your team - and on the other hand you’d be able to scratch itches for people whose main value for Python is plugging into its ecosystem rather than the language itself. Heck, why limit it to 4 dialects, you could have a whole Babel scenario where you could pip dialect install some nice language feature. I think people would mainly be using this type of feature to reduce mental burdens, for a small buy-in
评论 #26186228 未加载
BerislavLopac大约 4 年前
&gt; A second dialect would be an &quot;experimental&quot; dialect.<p>Python already has that in the form of the `__future__` module.<p>&gt; A third dialect would be a &quot;beginner&quot; dialect. &gt; This beginner dialect would be, in version 4.0, a strict subset of the main dialect. &gt; it might perhaps make sense to eventually introduce a few additional keywords and constructs not available from the main dialect<p>While I like the idea of the beginners using only a subset of the language, I don&#x27;t like the alternate keywords; while it might make getting into the language easier for someone coming from another one, I&#x27;m afraid it might actually slow down the adoption later on.<p>In fact nothing (except for the effort required to actually do it) prevents that &quot;strict subset&quot; concept to be introduced in Python as it is, by marking certain features&#x2F;keywords as &quot;advanced&quot; and adding a flag on the interpreter to throw a warning (or even an exception; there could be two settings) if one is used. That is not unlike the way the -O and -OO flags currently work.<p>&gt; a fourth dialect would be a &quot;static&quot; dialect<p>I don&#x27;t think that this could (or should) be introduced, as it goes directly against some of the Python&#x27;s basic concepts.
mjevans大约 4 年前
I agree with the post (by ggm) desiring that Python 4 were instead called something else; I think Python 3 should have been something else too.<p>I would also really like Python 4 to take a different approach to strings; more similar to Python 2.<p>The native format for strings should be a byte vector, with additional tags denoting if it has an encoding and if that encoding is validated. Coertsion of data type between byte vector and validates string should be automatic, but only performed in contexts that require a type.<p>Additionally the native type should be either UTF-8 (matching the 96% on the web as of 2021) or WTF8 (Like UTF-8, but encodes invalid byteforms in escape sequences so they round-trip) from Rust.<p><a href="https:&#x2F;&#x2F;www.w3.org&#x2F;International&#x2F;questions&#x2F;qa-who-uses-unicode" rel="nofollow">https:&#x2F;&#x2F;www.w3.org&#x2F;International&#x2F;questions&#x2F;qa-who-uses-unico...</a><p><a href="https:&#x2F;&#x2F;simonsapin.github.io&#x2F;wtf-8&#x2F;" rel="nofollow">https:&#x2F;&#x2F;simonsapin.github.io&#x2F;wtf-8&#x2F;</a>
ggm大约 4 年前
My wish for python4 is that it isn&#x27;t called python. I think at this point, language divergence would be more beneficial
评论 #26186779 未加载
dopidopHN大约 4 年前
I&#x27;m far from a python expert, but I&#x27;m a user since a long while now. I never followed closely the dynamic of the community. From my point of view the 2.x vs 3.x was never too much of an issue. The stuff I had to maintain in python were either already dead dev-wise, non-critical, or green-field.<p>All that introduce my thought while reading : &quot;is it too much too ask?&quot; If the need for having 3 dialects is all is needed in for core python 4... It&#x27;s a good place too be, no?
sergiomattei大约 4 年前
My wish for Python 4 is for it to get faster.<p>There was a proposal on here recently about a guy who wanted to speed it up by like 3x. What happened?
评论 #26189801 未加载
评论 #26188032 未加载
xiphias2大约 4 年前
My wish for Python 4 is to compile to the same IL as Python 3 to be able to mix Python 3&#x2F;4 libraries, or keep backwards compatibility. Rust showed that it can be done.
monkeycantype大约 4 年前
Mine : Make the colons optional