技术的极限(12): 探索编译器

上一篇:技术的极限(10): 有趣的编程
下一篇:技术的极限(13): 对过程和细节的可视化

面对不同的技术,我现在的看法是,先不用问有什么好处,有机会就写起来用起来。很多真正的不同,只有在实际操作的时候才能理解。有很多新的设计,用老的思维去看,永远会看不到。这是我体会很深的一点,新事物来的时候,如果总是想用旧事物的概念去套,往往会变成「最后一个玩家」----等其他人都上车了才去试,很多时候会错过先发者才有的探索机会。

0x01 Compiler Explorer

https://godbolt.org/

在线实时查看你的语言被编译后的汇编,适合写一些小函数,直接查看。

0x02 新书介绍:Working in Public: The Making and Maintenance of Open Source Software

An inside look at modern open source software developers--and their influence on our online social world.
"Nadia is one of today's most nuanced thinkers about the depth and potential of online communities, and this book could not have come at a better time." --Devon Zuegel, director of product, communities at GitHub

0x03 命令行查询JSON

完整教程:https://www.howtogeek.com/529219/how-to-parse-json-files-on-the-linux-command-line-with-jq/

推荐一款处理Json文件的命令行工具: jq

试用了下,很强大,查询语句有点类似CSS Selector,并支持管道链式过滤,很好学习,测试文件test.json:

{
  apps:[
    {
        fid:''xxx',
        id:"xx",
        status:"xx",
        version:"" 
    },
    ...
  ]
}

那么,下面的命令查询test.json文件里的apps数组,并忽略fid和version字段:

cat test.json |jq '.apps[]|del(.version)|del(.fid)'

输出:

{
  "id": "xxx",
  "status": "start"
}
{
  "id": "yyy",
  "status": "start"
}

0x04 Rob Pike's 5 Rules of Programming

http://users.ece.utexas.edu/~adnan/pike.html

  • Rule 1. You can't tell where a program is going to spend its time. Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you've proven that's where the bottleneck is.
  • Rule 2. Measure. Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest.
  • Rule 3. Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. Until you know that n is frequently going to be big, don't get fancy. (Even if n does get big, use Rule 2 first.)
  • Rule 4. Fancy algorithms are buggier than simple ones, and they're much harder to implement. Use simple algorithms as well as simple data structures.
  • Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.

Pike's rules 1 and 2 restate Tony Hoare's famous maxim "Premature optimization is the root of all evil."

Ken Thompson rephrased Pike's rules 3 and 4 as "When in doubt, use brute force.".

Rules 3 and 4 are instances of the design philosophy KISS.

Rule 5 was previously stated by Fred Brooks in The Mythical Man-Month. Rule 5 is often shortened to "write stupid code that uses smart objects".

0x05 Concise shots of dev knowledge.

Byte-sized posts to answer your questions on the go.

https://www.educative.io/edpresso

这个站点很有意思,每个问题的回答都十分简短而精确,并且有可执行的用例,例如:

https://www.educative.io/edpresso/what-is-the-cpp-stl-map

0x06 PyOxidizer, 解决Python程序的分发问题

Python写的程序,存在一个问题是不好分发给第3方。PyOxidizer这个工具解决了这个问题,https://github.com/indygreg/PyOxidizer

这个工具本身是使用Rust开发的:https://pyoxidizer.readthedocs.io/en/latest/index.html

0x07 线性空间的对偶空间

Duality of Vector Spaces

https://solmaz.io/notes/duality-vector-spaces/

这篇短文很简洁地把 Duality 介绍清楚了。

简单说,通过对偶空间的算子,可以快速把向量关于基函数的系数求出来。 当然有的时候只能把对偶空间的算子的抽象形式写出来,用来做分析的时候,如果不能直接在原空间做分析,转换到对偶空间分析和推导更容易,并无实际计算价值。

0x08 发明一个Monad

https://stopa.io/post/247

这是我见过的通过构造来理解monoad的最简洁的例子。

0x09 亚马逊的机器学习课程

https://www.amazon.science/latest-news/machine-learning-course-free-online-from-amazon-machine-learning-university

0x10 从如何正确构造的角度看类型:Types as axiom schemas

https://lexi-lambda.github.io/blog/2020/08/13/types-as-axioms-or-playing-god-with-static-types/

This is the essence of the Haskeller’s mantra, “Make illegal states unrepresentable,” and sadly it is often misinterpreted. It’s much easier to think “hm, I want to make these states illegal, how can I add some post-hoc restrictions to rule them out?” And indeed, this is why refinement types really are awesome, and when they’re available, by all means use them! But checking totally arbitrary properties at the type level is not tractable in general, and sometimes you need to think a little more outside the box.

Types as axiom schemas:

  • Instead of thinking about how to restrict, it can be useful to think about how to correctly construct.
  • In Haskell, datatype declarations invent new values out of thin air.
  • We can represent a lot of different data structures using the incredibly simple framework of “datatypes with several possibilities.”

可以从产生式的角度看类型,有点类似数学里定义概念的思维,例如什么是群,一个集合要满足群的几条公理才算一个群。

--end--

posted @ 2020-10-05 22:53  ffl  阅读(415)  评论(1编辑  收藏  举报