ACM 宣佈停止發行紙本 (Journal 與 Transaction)

Hacker News 上看到 ACM 宣佈停止發行紙本:「Ceasing print publication of ACM journals and transactions (acm.org)」,原公告在「Ceasing Print Publication of ACM Journals and Transactions」。

從 2024 年一月開始停止紙本版本的發行,除了列出來的例外:

ACM has made the decision to cease print publication for ACM’s journals and transactions as of January 2024. The magazines Communications of the ACM, ACM InRoads, interactions, and XRDS: Crossroads will continue in print.

一方面降低成本,而替代方案就是有需要的人可以自己印,挑自己習慣的方式閱讀...

全自動化「印出來,簽名,掃描再寄回去」的事情

看到「falsisign」這個專案 (FalsiScan: Make it look like a PDF has been hand signed and scanned),完全符合這個 blog 的副標題「幹壞事是進步最大的原動力」的精神,不介紹一下好像說不過去...:

For bureaucratic reasons, a colleague of mine had to print, sign, scan and send by email a high number of pages. To save trees, ink, time, and to stick it to the bureaucrats, I wrote this script.

把「印出來簽名再寄掃描回去」這種事情在電子系統上全自動化:產生出來的 PDF 會把預先嵌好的簽名貼到程式指定的位置上,另外還會稍微把把紙張轉一些角度,並且加上影印時會產生的黑邊...

有超多這種雜事要處理,但是又閃不掉的人,可以研究一下...

Python 上取代「printf 大法」的工具

「printf 大法」大概是最早期學到的 debug 方式?不同語言有不同的指令,在 Python 裡對應的是 print 指令 (加上 % 或是 .format())。

剛剛看到「cool-RR/pysnooper」這個 Python 上的工具,只要增加 @pysnooper.snoop() 這組 decorator,就可以自動幫你把變數的值印出來。網站上的範例是這樣,可以看到就只是加了一行 decorator:

import pysnooper

@pysnooper.snoop()
def number_to_bits(number):
    if number:
        bits = []
        while number:
            number, remainder = divmod(number, 2)
            bits.insert(0, remainder)
        return bits
    else:
        return [0]

number_to_bits(6)

然後對應的 stderr 就有滿滿的資訊可以看:

Starting var:.. number = 6
21:14:32.099769 call         3 @pysnooper.snoop()
21:14:32.099769 line         5     if number:
21:14:32.099769 line         6         bits = []
New var:....... bits = []
21:14:32.099769 line         7         while number:
21:14:32.099769 line         8             number, remainder = divmod(number, 2)
New var:....... remainder = 0
Modified var:.. number = 3
21:14:32.099769 line         9             bits.insert(0, remainder)
Modified var:.. bits = [0]
21:14:32.099769 line         7         while number:
21:14:32.099769 line         8             number, remainder = divmod(number, 2)
Modified var:.. number = 1
Modified var:.. remainder = 1
21:14:32.099769 line         9             bits.insert(0, remainder)
Modified var:.. bits = [1, 0]
21:14:32.099769 line         7         while number:
21:14:32.099769 line         8             number, remainder = divmod(number, 2)
Modified var:.. number = 0
21:14:32.099769 line         9             bits.insert(0, remainder)
Modified var:.. bits = [1, 1, 0]
21:14:32.099769 line         7         while number:
21:14:32.099769 line        10         return bits
21:14:32.099769 return      10         return bits

另外還可以寫到檔案裡、允許的深度,或是值接指定要哪些變數,另外輸出時也可以指定 prefix 避免混淆 (通常會用在 stderr 不只有 pysnooper 在輸出時)。

印 "#" 比印 "B" 來的快的問題

這篇是兩年前在 StackOverflow 上的問題:「Why is printing “B” dramatically slower than printing “#”?」。

問問題的人這段程式跑了 8.52 秒:

Random r = new Random();
for (int i = 0; i < 1000; i++) {
    for (int j = 0; j < 1000; j++) {
        if(r.nextInt(4) == 0) {
            System.out.print("O");
        } else {
            System.out.print("#");
        }
    }

   System.out.println("");
 }

而把上面的 # 換成 B 就變成 259.152 秒。

答案是與 word-wrapping 有關:

Pure speculation is that you're using a terminal that attempts to do word-wrapping rather than character-wrapping, and treats B as a word character but # as a non-word character. So when it reaches the end of a line and searches for a place to break the line, it sees a # almost immediately and happily breaks there; whereas with the B, it has to keep searching for longer, and may have more text to wrap (which may be expensive on some terminals, e.g., outputting backspaces, then outputting spaces to overwrite the letters being wrapped).

But that's pure speculation.

這真是細節 XDDD