用顏色區分程式碼裡面的括弧

Hacker News Daily 上看到 VSCode 改善了 bracket pair colorization 效率的文章,才想到我的 Vim 好像沒裝這個功能:「Bracket pair colorization 10,000x faster」。

VSCode 這邊主要是引入了新的資料結構改善了計算量,有興趣的可以看一下:

Efficient bracket pair colorization was a fun challenge. With the new data structures, we can also solve other problems related to bracket pairs more efficiently, such as general bracket matching or showing colored line scopes.

我這邊則是去找 Vim 上的套件,目前看到是「Rainbow Parentheses Improved」這個,裝起來拿 PHP 程式碼看了一下還行,這樣就不用在那邊算哪個左括弧對應到右括弧...

IPv6 表示法的包袱

IPv6 address 表示法的確有不少問題,說「包袱」是因為應該是很難改了。

在「The IPv6 Numeric IP Format is a Serious Usability Problem」這篇文章裡作者討論 IPv6 address 表示法的問題,像是因為用 colon 切割造會跟 url 裡的 port 混淆,於是引入了 bracket 的 workaround:

An IPv4 URL of the form http://127.0.0.1:1234/ indicates that HTTP should be used to access a service at 127.0.0.1 port 1234. But what does http://dead:beef::1:1234/ mean? To fix the ambiguity, brackets were introduced. Now you have to type http://[dead:beef::1]:1234/.

Address Shortening Obfuscation 這邊講的就有點過火了,不過的確是不好讀,一眼看過去不是很容易切開一個 colon 與兩個 colon 的部份。

作者有提出一些建議方法,不過看起來只是 murmuring... XD

[ 與 [[ 的差異 (Left square bracket)

在寫 shell script 時,[[[ 到底用起來有什麼不一樣?查出來記錄起來:「What is the difference between double and single square brackets in bash?」。

第一高分的答案 (由 Kyle Brandt 回答) 與第二高分的答案 (由 abhiomkar 回答) 都值得看,尤其是 abhiomkar 寫的範例很清楚:

  $ [ a < b ]
 -bash: b: No such file or directory
  $ [[ a < b ]]

對判斷式子裡面的解讀是不一樣的。