Yoki

Notes

Shorter than essays, longer than thoughts. TILs, excerpts, fragments.

#til #css #typography

中英文之间的空格,交给 CSS

中英混排要不要手动加空格,争论了很多年。现在可以交给浏览器:

body { text-autospace: normal; }

它会在汉字与西文、数字之间自动插入约四分之一字宽的间距,不改变文本本身——复制出来依然没有多余空格。本站正在使用。

#til #git

git worktree:同时在两个分支上工作

修线上 bug 时不想 stash 手头的改动,可以给另一个分支开一个独立的工作目录:

git worktree add ../hotfix main
cd ../hotfix        # 这里是干净的 main
git worktree remove ../hotfix

两个目录共享同一个 .git,提交彼此可见,但工作区互不干扰。

#til #code

Names should describe what, not how

fetchUserFromCacheOrDb() tells me how it works and will be wrong the day the cache goes away. getUser() tells me what I get, and stays true. If the how matters to the caller, it usually belongs in a parameter, not the name.

#reading

学而不思则罔,思而不学则殆。

以前读这句,重点总放在“思”上。最近才意识到后半句更扎心:一直想、不去学,人会陷入一种很舒服的自我说服。写笔记大概是两者之间的桥——学来的东西,要用自己的话写一遍,才知道到底想没想通。

↑↓select↵openescclose