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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Python as a second language empathy (2018)

66 点作者 luu2 个月前

6 条评论

planckscnst2 个月前
I learned several languages before Python, but the one that made it the most difficult was Ruby. After having done Ruby for years and becoming really familiar with idioms and standard practices, coming to python feels like trying to cuddle with a porcupine.<p>List (or set, or dict) comprehensions are really cool... one level deep. The moment you do &#x27;in...in&#x27; my brain shuts off. It takes me something like 30 minutes to finally get it, but then ten seconds later, I&#x27;ve lost it again. And there are a bunch of other things that just feel really awkward and uncomfortable in Python
评论 #43228248 未加载
评论 #43228814 未加载
评论 #43237925 未加载
a_e_k2 个月前
Oddly, trying to occasionally place on the Advent of Code global leaderboard was the thing that got me most fluent in Python as its own language.<p>Before that, I tended to write Python in a much more imperative style, since C++ is my main language; think for loops and appending to lists. Thanks to AoC, I&#x27;m now addicted to comprehensions for transforming and filtering, know the standard library cold, and write much more concise, Pythonic code.
评论 #43226183 未加载
评论 #43226771 未加载
评论 #43227907 未加载
xg152 个月前
&gt; <i>But annotations are much less powerful than Python decorators.</i><p>Coming from Java and seeing what kind if stuff is practically done there with annotations (looking at you, Spring), Python decorators actually feel more constrained than annotations, in a fully beneficial sense.<p>Yes, Python decorators run arbitrary code, but at least, there is a straight-forward relationship between the decorator and the location of that code. Decorators are just syntactic sugar for a function call that takes the decorated function as an argument - so you just have to look up the definition of the decorator to find out what it does.<p>In contrast, a Java annotation does exactly nothing by itself - it&#x27;s literally a piece of metadata stapled to a function or field or argument, etc.<p>This metadata is accessible either at compile-time using compiler postprocessors, or at runtime using reflection. The code that accesses the annotation and implements its behavior can be essentially anywhere in your class path. In the worst case, you&#x27;ll have to go through every single usage site of the annotation to find the place where its behavior is defined.<p>(As a bonus, annotations can be annotated themselves, too - so you&#x27;ll potentially have to repeat the process recursively)
daveguy2 个月前
Title needs (2018). Data on language usage growth goes to 2018.
评论 #43225793 未加载
zahlman2 个月前
&gt; Who here has another language that they knew pretty well before learning Python? (most hands go up) Great! Terrific! That’s a superpower you have that I can never have. I can never unlearn Python, become fluent in another language, and then learn Python again. You have this perspective that I can’t have.<p>It felt a little strange to read this. I knew many languages &quot;pretty well&quot; (or would have said so at the time) before Python, but it&#x27;s been my primary programming language pretty much the entire time since I first picked it up 20 years ago. So I do have that perspective (I also spend a fair amount of time thinking about PL design in the abstract), but I don&#x27;t feel &quot;PSL&quot; at all.<p>&gt; Does the value stored in `a` know the name of that variable?<p>Okay, I&#x27;m stumped - in what other language <i>would</i> it &quot;know&quot; (I assume this means automatically recording the string &quot;a&quot; as part of the object&#x27;s state in some way)? Or is this just referring to debugging information added in some environments?<p>&gt; Python = is like Java, it’s always a reference and never a copy (which it is by default in C++).<p>Java has primitive types, for which it is a copy. But it&#x27;s more accurate IMO to attribute this as a property <i>of names</i>, rather than a property of assignment. Python&#x27;s names (and most Java values, and some C# values) have reference <i>semantics</i>. Having understood that properly, saying that Python (like Java) is &quot;pass by assignment&quot; then just follows naturally, and all the usual confusion around this point vanishes. Passing an argument to a function is simply assigning it to the corresponding parameter. (C++&#x27;s idea of &quot;references&quot; <i>in the type system</i> is far more complex IMO - e.g. <a href="https:&#x2F;&#x2F;langdev.stackexchange.com&#x2F;q&#x2F;3798&#x2F;_&#x2F;3807#3807" rel="nofollow">https:&#x2F;&#x2F;langdev.stackexchange.com&#x2F;q&#x2F;3798&#x2F;_&#x2F;3807#3807</a> .)<p>&gt; We have both reference counting and garbage collection in Python.<p>This is strange phrasing, because reference counting is a garbage collection strategy. I assume that here &quot;garbage collection&quot; is meant to refer to mark-and-sweep etc. strategies that operate in a separate pass, timed independently of the explicit code. But also, the reference-counting system is a CPython implementation detail. (Although it does look like PyPy tries to emulate that, at least: <a href="https:&#x2F;&#x2F;doc.pypy.org&#x2F;en&#x2F;default&#x2F;discussion&#x2F;rawrefcount.html" rel="nofollow">https:&#x2F;&#x2F;doc.pypy.org&#x2F;en&#x2F;default&#x2F;discussion&#x2F;rawrefcount.html</a> )<p>&gt; I’ll translate this one to the transcript later - for now you’ll have to watch it because the visual is important: explicit super.<p>Raymond Hettinger&#x27;s video is also a useful reference here: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=EiOglTERPEo" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=EiOglTERPEo</a><p>&gt; It takes less characters in Python!<p>This checks out, but it would be fairer to show what it looks like on the declaration side rather than just the usage side.
评论 #43224505 未加载
评论 #43224886 未加载
评论 #43227377 未加载
评论 #43226022 未加载
评论 #43225690 未加载
svilen_dobrev2 个月前
i have taught quite a few people of various backgrounds and levels. And still provide a short crash-course, once in a while.<p>IMO in this article the elephant is missing, esp. for C&#x2F;C++&#x2F;java people: there are no variables as storage-spaces in Python. There are names&#x2F;labels in namespaces, attached&#x2F;referencing some value (stored in VM), and that is taken&#x2F;examined at runtime-usage of those labels&#x2F;names. The values themselves are living on other side of the fence, inside the virtual machine.<p>The most important piece of the language Python in docs is the execution model, and in it, the &quot;naming and binding&quot; part:<p><a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3.11&#x2F;reference&#x2F;executionmodel.html#naming-and-binding" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3.11&#x2F;reference&#x2F;executionmodel.html#n...</a><p>i.e. what constitutes a namespace, how are they stacked at declare-time or run-time (visibility&#x2F;shadowing), lifetimes, scopes and all that.<p>The most usual gotcha is that inside of class xyz: ... is only a temporary namespace - and becomes class&#x27; attributes when closed (well, subject to metaclass behaviour).<p>i usually present the &quot;storage&quot; as &quot;imagine 2 notebooks of ~transparent-sheets&quot; : one is the names&#x27; visibility (so called &quot;variables&quot;) - namespace-hierarchy, where each sheet is one namespace level, and you see only the inner-most page that has something in certain row - shadowing all those towards the root at module level; the other is the attribute-on-something visibility, where the instance (if any, of whatever type) is (only one and) always on top, and then inherited <i>classes</i> (not instances) underneath one under another. Also, all instance-or-static methods in Python are virtual, i.e. using the topmost available - while class-methods are not, they use the specified-or-below but not above.<p>Frankly, took me ~10 years, occasionally rereading that chapter each time when hitting new category of errors, to grasp the whole of it. <i>Each comma there matters</i>. Take your time.<p>Edit: this &quot;names-only&quot; thing is similar in javascript, and other interpreted languages. Python also exposes the whole VM-runtime - from programmer&#x27;s side of the fence - i.e. locals() is the current namespace, inspect.stack() gives the current namespace hierarchy, etc. Self-reflection can be taken quite far
评论 #43230822 未加载