流畅的Python

最新书摘:
  • 眯眼西索
    2023-08-30
    异味的好处之一是,没有经验的人也很容易发现,即使他们既没有足够的知识来评判是否真的有问题,也不知道如何修正问题。我听说,有一些首席开发人员会提出“一周异味之星”,让团队成员寻找代码异味问题,找到问题后交给高级开发人员解决。一次解决一个异味问题是不错的做法,可以让团队成员循序渐进,引导他们成为更好的程序员。
  • 眯眼西索
    2023-08-30
    Q: dataclass 装饰器是做什么的?A: 减少创建类的时候的样板代码的。这个装饰器不关心定义类的时候的类型注解,除了两个: 1⃣️ClassVar伪类型,被注释属性会成为类属性。 2⃣️InitVar伪类型,被注释的属性不会成为实例属性,而是会在__post_init__方法中被调用。
  • 眯眼西索
    2023-07-05
    t0=time.perf_counter()result=func(*args)elapsed=time.perf_counter()-t0
  • 眯眼西索
    2023-06-27
    我们看到许多团队因为选择了复杂的工具、框架或架构而遇到麻烦,因为他们觉得“可能需要伸缩”。像Twitter和Netflix这样的公司需要支持极端负载,因此需要这些架构,但他们也有非常熟练的开发团队,能够应对由此带来的复杂性。多数时候,我们并不需要这类工程技术。团队应该克制对Web-Scale的渴望,选择更简单可行的方案。Web-Scale的关键是一个支持横向伸缩的架构。在这样的架构中,所有系统都是分布式系统,没有任何一门语言能够包揽全部解决方案。
  • 眯眼西索
    2023-06-26
    并发指同时处理多件事。并行指同时做多件事。二者不同,但有联系。一个关于结构,一个关于执行。并发用于制定方案,用来解决可能(但未必)并行的问题。 ——Rob Pike Go语言联合创造者
  • 眯眼西索
    2023-06-21
    起初,我们推动继承思想是为了让新手顺利使用只能由专家设计的框架开发作品。
  • 眯眼西索
    2023-06-21
    至于可读性,适当的组合比继承要好。由于读代码的频率比写代码要高得多,因此一般情况下要避免使用子类,特别是不要混合多种类型的继承,也不要使用继承来共享代码。
  • 眯眼西索
    2023-06-06
    就像“什么是美”没有确切答案一样,“什么是Python风格”也没有标准答案。因为对你来说是“地道的”,在我看来却可能不是。但我可以肯定的是,“地道”并不是指使用最鲜为人知的语言功能。如果想计算列表中各个元素的和,那么写出的代码就应该看起来像是在“计算元素之和”。如果不能站在一定高度上表明意图,却让语言去关注底层操作,那还要高级语言干嘛?
  • 眯眼西索
    2023-06-06
    我坚信,类型提示有存在的必要,然而很多时候得不偿失。用与不用由你自己选择,这多好。 ——Guido van Rossum
  • 夏夜寂寞属壁虎
    2022-06-13
    In contrast, consider Go. Some objects in that language have features that are magic, in the sense that we cannot emulate them in our own user-defined types. For example, Go arrays, strings, and maps support the use brackets for item access, as in a[i]. But there’s no way to make the [] notation work with a new collection type that you define. Even worse, Go has no user-level concept of an iterable interface or an iterator object, therefore its for/range syntax is limited to supporting five “magic” built-in types, including arrays, strings, and maps.Maybe in the future, the designers of Go will enhance its metaobject protocol. But currently, it is much more limited than what we have in Python or Ruby.
  • iNVAiN
    2020-03-29
    While coding with any framework, you spend a lot of time implementing methods that are called by the framework. The same happens when you leverage the Python data model.
  • iNVAiN
    2020-03-29
    You can think of the data model as a description of Python as a framework.
  • 三諼愺
    2018-08-09
    Changing a class or module at runtime, without touching the source code
  • 三諼愺
    2018-08-09
    Operating with objects regardless of their types, as long as they implement certain protocols
  • Brucie
    2016-05-24
    The second edition of Python Cookbook was written for Python 2.4, but much of its code works with Python 3, and a lot of the recipes in Chapters 5 and 6 deal with sequences. The book was edited by Alex Martelli, Anna Martelli Ravenscroft, and DavidAscher, and it includes contributions by dozens of Pythonistas. The third edition wasrewritten from scratch, and focuses more on the semantics of the language—particularlywhat has changed in Python 3—while the older volume emphasizes pragmatics (i.e.,how to apply the language to real-world problems). Even though some of the secondedition solutions are no longer the best approach, I honestly think it is worthwhile tohave both editions of Python Cookbook on hand.
  • 京宝梵Amazing
    2016-02-26
    If a class is designed to provide method implementations for reuse by multiple unrelated subclasses, without implying an “is-a” relationship, it should be an explicit mixin class. Conceptually, a mixin does not define a new type; it merely bundles methods for reuse. A mixin should never be instantiated, and concrete classes should not inherit only from a mixin. Each mixin should provide a single specific behavior, implementing few and very closely related methods.
  • 京宝梵Amazing
    2016-02-24
    Strong versus weak typingIf the language rarely performs implicit conversion of types, it’s considered strongly typed; if it often does it, it’s weakly typed. Java, C++, and Python are strongly typed. PHP, JavaScript, and Perl are weakly typed. Static versus dynamic typingIf type-checking is performed at compile time, the language is statically typed; if it happens at runtime, it’s dynamically typed. Static typing requires type declarations (some modern languages use type inference to avoid some of that). Fortran and Lisp are the two oldest programming languages still alive and they use, respectively, static and dynamic typing.
  • 眯眼西索
    2023-06-05
    发送时要保守,接收时要大方。 ——伯斯塔尔定律,又称稳健性法则
  • 尹麻子
    2017-06-03
    加州大学两位教授(Brian Harvey 和Matthew Wright)的课件 -- 两种计算机科学的教学观点:保守观点计算机程序在人类的思维中会变得非常庞大和复杂。因此,计算机科学教育的目的是教会人们如何训练它们的编程能力,比如以这种方式--让500个平庸的程序员聚集在一起,给出规格让他们生产出一个程序。激进观点计算机程序在人类的思维中会变得非常庞大和复杂。因此,计算机科学教育的目的是教会人们如何扩展自己的思维以和程序契合,学习更多的概念,将会比单一解决方法更加弹性和有用。一个程序每个单元的编程的想法都必须统观全局。