Issue 399

是什么令 Python 成为伟大的开发语言? 原文: PyCoder’s Weekly - Issue #399 191211 Zoom.Quiet(大妈) 用时 42 分钟 完成快译 191211 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄. 是什么使Python成为一种很棒的语言? STEVE DOWER “What makes Python a great language? It gets the need to know balance right. [… ] I would argue that the Python language has an incredibly well-balanced sense of what developers need to know. Better than any other language I’ve used.” (是也乎: 马后炮也是有技巧的…. 人家老爹从没说过类似的… Linus 倒是经常嗯哼… …有着令人难以置信的平衡感 Python 对各种开发者都有友好的切入点, 而且有统一的成品代码观感. ) ...

2019-12-18 · 4 min · 1598 words · ZoomQuiet

Issue 398

MicroPython 物联网编程没问题 原文: PyCoder’s Weekly - Issue #398 191211 Zoom.Quiet(大妈) 用时 42 分钟 完成快译 191211 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄. MicroPython: Python编程硬件简介 REAL PYTHON Are you interested in the Internet of Things, home automation, and connected devices? In this tutorial, you’ll learn about MicroPython and the world of electronics hardware. You’ll set up your board, write your code, and deploy a MicroPython project to your own device. (是也乎: 参考: PyCon19China 南宁场私人回顾 blog.PyChina.org | 蠎中国社区 blog 国内资深玩家的有关分享… ) PEP 591: 在 typing 中添加最终的限定词 PYTHON.ORG This PEP proposes a final qualifier to be added to the typing module—in the form of a final decorator and a Final type annotation—to serve three related purposes: Declaring that a method should not be overridden, declaring that a class should not be subclassed, declaring that a variable or attribute should not be reassigned. 正确进行 Python 配置 MICHAEL WHALEN “Let’s talk about configuring Python applications, specifically the kind that might live in multiple environments – dev, stage, production, etc.” (是也乎: 充分利用内置能力, 精心规划好开发/测试/运营环境参数, 综合使用环境变量, 以及自动加载机制… 当然, 俺推荐 Borg 类. ) 8 个超棒 pytest 插件 OPENSOURCE.COM • Shared by Python Bytes FM “One of the best aspects of the popular Python testing tool is its robust ecosystem. Here are eight of the best pytest plugins available.” 两个恶意 Python 库盗用 SSH 和 GPG 密钥 LUKAS MARTINI Also see the related discussion on Hacker News. Instagram 取消 Python 垃圾收集 INSTAGRAM ENGINEERING BLOG How Instagram’s Django backend runs with GC disabled and gets a 10% performance gain. (是也乎: 大厂商都必须有能力根本自己业务特点来定制运行时环境. ) Python 代码风格和 Pythonic 习语/惯用法 PYTHON-GUIDE.ORG A review of general concepts, language idioms, and Pythonic coding conventions. (是也乎: 已有中译: 代码风格 — The Hitchhiker’s Guide to Python 来自: Python 宇宙搭车客指南 ) Monads 没您想像的那么难 YING WANG Monads explained with Python code examples. (是也乎: 不是那个神人 王垠; 用 Py 来喷 Haskell… ) CPython 3.8.1rc1 可用于测试 PYTHON.ORG 讨论 Discussions NIL ...

2019-12-11 · 4 min · 1603 words · ZoomQuiet

Issue 397

Guido 退出 Python 指导委员会 原文: PyCoder’s Weekly - Issue #397 191204 Zoom.Quiet(大妈) 用时 42 分钟 完成快译 191204 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄. Guido van Rossum 退出 Python 指导委员会 PYTHON.ORG “Part of my reason is that in the end, SC duty feels more like a chore to me than fun, and one of the things I’m trying to accomplish in my life post Dropbox retirement is to have more fun. To me, fun includes programming in and contributing to Python, for example the PEG parser project.” (是也乎: 放弃争论, 清心编程… ) Python Descriptors: 简介 REAL PYTHON Learn what Python descriptors are and how they’re used in Python’s internals. You’ll learn about the descriptor protocol and how the lookup chain works when you access an attribute. You’ll also see a few practical examples where Python descriptors can come in handy. (是也乎: 配合装饰器才能发挥作用的描述符: …能在类上拦截对实例属性的访问,由此可以引出很多有趣的用法,和metaclass结合起来更是如此. 对于Python来说"性能"似乎从来不是牺牲"功能"(以及其他各种美德)的理由,这次也不例外. zhihu 上有人点评… ) ...

2019-12-04 · 3 min · 1436 words · ZoomQuiet

Issue 396

Guido: 代码的可读性如此重要… 原文: PyCoder’s Weekly - Issue #396 191127 Zoom.Quiet(大妈) 用时 42 分钟 完成快译 191127 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄. PyCon 2020 注册已上线 PYCON.ORG PyCon is the largest annual gathering for the community that uses and develops the open-source Python programming language. April 15–23 in Pittsburgh. Pro-tip: Get your early bird tickets today. (是也乎: PyCon2020 早鸟票已经有了,,, ) Python KeyError 异常以及如何处理它们 REAL PYTHON video KeyError exceptions are often caused by a bad key lookup in a dictionary, but there are a few other situations when a KeyError can be raised as well. Knowing how to handle these exceptions is essential to writing good Python code. (是也乎: 等等, 这个是常见, 但是, 不难追踪哪… ) 实用 Unicode (2012) NED BATCHELDER Timeless tutorial that teaches the basics of Unicode, and how both Python 2 and Python 3 work, as well as some key tips on solving Unicode problems. Guido van Rossum 论 Python 如何令思维的代码表述更轻松 DROPBOX.COM A conversation with the creator of the world’s most popular programming language on removing brain friction for better work. (是也乎: 全文如下: The Mind at Work: Guido van Rossum on how Python makes thinking in code easier By Anthony Wing Kosner Published on November 25, 2019 A conversation with the creator of the world’s most popular programming language on removing brain friction for better work. Nothing defines the 21st century more than the ubiquitous effects of computer programming. Almost everything we do, particularly at work, is mediated by screens displaying the results of the enormous amount of computation that we now take for granted. If you’re one of the 99.7% of the human race that are not programmers, how all of this happens is a bit of a mystery. As science fiction writer Arthur C. Clarke quotably wrote, “Any sufficiently advanced technology is indistinguishable from magic.” Of course, it isn’t magic. It is, however, both complicated and complex, with codebases of tech companies measured in millions of lines of code. When you’re reasoning about a real system you might want to build in code, you’re thinking about the complex relationships between different functions over time. Your code can be more or less complicated in how it is written and structured, but the problem you’re trying to solve has an inherent complexity that can’t be reduced to something simpler. Becoming a programmer is not just about ideas, and you won’t last long at it if you can’t deal with the laser-focused details of describing your ideas in code. “I’m a little skeptical of the claim that the systems thinking is primary there, because it’s much easier to come up with an idea for a system than it is to take an idea and turn it into working code,” says Guido van Rossum, the creator and retired BDFL (Benevolent Dictator for Life) of the Python programming language. JavaScript still owns the web, and Java runs 2.5 billion Android phones, but for general purpose programming and education, Python has become the default standard. If anyone has made turning an idea into working code easier, for more people, it’s Van Rossum over his 30-year history with Python. And he’s done it with a self-effacing grace and an understated humor—the language is named after the surreal comedy of Monty Python, not the actual Burmese python. In its quiet way, the Python programming language has managed to make some of the complications of programming computers less difficult for our brains to manage. To understand how Van Rossum accomplished this amazing feat, we have to go back into the history of computing to the era of mainframes and machine language. “The mainframe is a machine that costs many millions of dollars, and the combined pay of all those programmers is peanuts compared to the cost of the mainframe,” he says, explaining that cost logically prioritized machine time over human time. “But as I experienced desktop workstations and PCs, I realized that a change of mindset about cost of the programmer’s time versus cost of the computer’s time was overdue.” Van Rossum doesn’t think he was the first person to observe this shift, but he really capitalized on it in the design of Python. This simple idea of giving humans priority over machines is at the core of the philosophy behind Python. Certainly the fact that it’s an interpreted language as opposed to a compiled language means that the programmer gets immediate feedback about the code they’re writing without needing to take the time to recompile it after making each change. This is very common now, but thirty years ago it was quite controversial because the conventional wisdom was that faster (for the computer) was better. Updating this belief has had a large positive impact on the productivity of programmers. “In Python, every symbol you type is essential.” —Guido van Rossum “There are a whole bunch of common programming tasks that are easy in Python,” says Van Rossum. “For someone who is not yet a programmer, who wants to become a programmer, for those people Python is particularly easy to get.” Indeed, many computer science schools are switching over from Java to Python, because it’s much easier to grasp for beginners. The reasons behind this are complex, with many factors each reducing little bits of friction. What’s simple is the philosophy behind all of the improvements: Everything should have a necessary purpose. The lack of extraneous code makes it easier to focus on what you need to pay attention to. “In Python, every symbol you type is essential,” Van Rossum says. This concision makes it easy to accomplish something meaningful in Python, which is one of the reasons for its wide adoption. “The typical way that we introduce Python to beginning programmers is also important. We can show them very small snippets of code that require very little understanding of terminology and concepts from programming before they make sense,” Van Rossum explains, “whereas the smallest Java program, for example, contains a whole bunch of what are, to the uninitiated eye, noise characters.” This quietness and simplicity of design makes it easier to see what’s going on. “Python for me is incredibly visual,” says Van Rossum. “When I read Python, I definitely see it as a two-dimensional structure, rather than one-dimensional, like language. That is probably because Python uses indentation for grouping, but probably also because my mind just likes thinking visually.” He’s not the only one, of course, who thinks visually. We all do to some extent. But he’s particularly sensitive to the effects of the visual on cognition. “Some poorly formatted text can drive me crazy. They interrupt my visual parsing of the flow and the structure, and in that sense, I do think in Python,” Van Rossum admits. “I can grasp code much better when it’s formatted properly.” It takes more information to resolve the uncertainty about what code indentations mean if they’re arbitrary than if those indentations have a clear purpose, as they do in Python. So if the experience is easier, it’s because fewer bits of information have to be processed for you to know what’s going on. Python’s readability is not just typographic, but conceptual. Van Rossum thinks Python may be closer to our visual understanding of the structures that we are representing in code than other languages because, “Python makes that structure mandatory.” “While I was researching my book, CODERS,” says author Clive Thompson, “I talked to a lot of developers who absolutely love Python. Nearly all said something like ‘Python is beautiful.’ They loved its readability—they found that it was far easier to glance at Python code and see its intent. Shorn of curly brackets, indented in elegant visual shelves, anything written in Python really looks like modern poetry.” They also find that Python is fun to write, which is more important than it may seem. As Thompson writes, “When you meet a coder, you’re meeting someone whose core daily experience is of unending failure and grinding frustration.” “You primarily write your code to communicate with other coders, and, to a lesser extent, to impose your will on the computer.” —Guido van Rossum Building the priority of the programmer’s time into the language has had a curious effect on the community that’s grown around it. There’s a social philosophy that flows out of Python in terms of the programmer’s responsibility to write programs for other people. There’s an implicit suggestion, very much supported by Van Rossum in the ways he talks and writes about Python, to take a little more time in order to make your code more interpretable to someone else in the future. Expressing your respect for others and their time through the quality of your work is an ethos that Van Rossum has stealthily propagated in the world. “You primarily write your code to communicate with other coders, and, to a lesser extent, to impose your will on the computer,” he says. The universality of the culture that’s spread around Python has achieved some measure of what Van Rossum intended two decades ago with a short-lived project called CP4E (Computer Programming for Everybody). “I’m usually not a very visionary thinker. People always ask me, what’s next for Python, and I never know. But I put on my most visionary hat, and assumed that it would make sense for everyone to learn programming.” Personal computers had been around for 20 years, but mostly they were glorified typewriters and calculators. Van Rossum asked, “isn’t it crazy that all those people have computers, and very few of them learn to program?” In the time since, he has focused on making programming easier to learn and easier to do through the advancements in Python, now at version 3.7. He still thinks that programming teaches generally valuable skills, like problem solving, following directions carefully, and understanding what directions mean. But he’s also found that, “there are certain introductions to programming that are fun for kids to do, but they’re not fun for all kids, and I don’t think I would want to make it a mandatory part of the curriculum.” At the same time, the need for people to program their computers has also diminished because of the growth of software, particularly on the web, that allows you to intuitively do what used to require programing to accomplish. “I’m not so sure that it needs to happen anymore,” Van Rossum says of CP4E. “I think computers have made it to that point, where they’re just a useful thing that not everybody needs to know what goes on inside.” “Python is now also the language of amateurs, and I mean that in the best possible way.” —Guido van Rossum But that are a growing number of people who are using Python in many fields. “The currently prevailing theory about Python’s unexpected success,” says Van Rossum, “is that at some point, it established itself into data science and machine learning, and scientific data processing in general, and once you have critical mass, it’s easier for everyone to use the same system as their colleagues and their competitors, than to try something different.” And even though it started as purely a tool for professional programmers, Van Rossum says, “Python is now also the language of amateurs, and I mean that in the best possible way.” A successful open source software project, like Python, has to be easy to learn for beginners, but also have practical application to real world problems that more advanced users will want to solve. Just as for beginners you want to keep things simple so all of their brain energy is spent on learning the complications of the programming environment, for advanced users you want to help them manage the complexity of these competing abstractions. Part of the motivation for making the implementation of Python as simple as possible is to be able to change your mind, to learn, to iterate. “If you write a prototype in Python and you get it to work, often, that’s not a very big effort,” says Van Rossum, “and then you can afford to throw away your prototype and write the same thing again based on what you’ve learned. You can still write it in Python, but the second version will be much better than the first.” Part of the enduring appeal of Python is the optimism and humility of starting over. “If you’ve invested much more time into writing and debugging code, you’re much less eager to throw it all away and start over.” Co-founder and CEO, Drew Houston wrote the first prototype of Dropbox in Python on a five-hour bus ride from Boston to New York. “The early prototypes of Dropbox were thrown away, largely, many times,” says Van Rossum. What can we learn from Python about how to design better tools for thinking? Tim Peters, one of Python’s major contributors, offers some clues in the aphoristic The Zen of Python, in which he channels Van Rossum’s guiding principles. Particularly relevant to our present discussion are this pair: “Simple is better than complex. Complex is better than complicated.” This could almost be a recipe for how the brain prioritizes its functions to use energy efficiently. Equally important for Van Rossum is the social aspect of thinking and building tools. What has he taken away from his thirty year journey with Python? “I have learned that you can’t do it alone, which is not an easy lesson for me. I’ve learned that you don’t always get the outcome that you went for, but maybe the outcome you get is just as good, or better.” 简单说: Python 之禅 真的包含了老爹所有关键思考成果. ) ...

2019-11-27 · 8 min · 3627 words · ZoomQuiet