だいせんじがけだらなよさ
你好,我是无能。
最近我开始思考,如果最终要接触Go,是不是最好先学习C语言?我从过去的挫折中开始学习,回顾Go和Rust中那些不需要过多考虑的内存处理是如何运作的。突然,我在查看SCP并行处理版本mscp的源代码时,对它返回-1作为返回值的原因感到好奇。
$ grep -r 'return \-1' ./* | sort | uniq
grep: warning: stray \ before -
./libssh/doc/guided_tour.dox: return -1;
./libssh/doc/guided_tour.dox: return -1;
./libssh/doc/guided_tour.dox: return -1;
./libssh/examples/keygen.c: return -1;
./libssh/examples/knownhosts.c: return -1;
./libssh/examples/knownhosts.c: return -1;
./libssh/examples/knownhosts.c: return -1;
./libssh/examples/libssh_scp.c: return -1;
./libssh/examples/libssh_scp.c: return -1;
./libssh/examples/libssh_scp.c: return -1;
./libssh/examples/libssh_scp.c: return -1;
./libssh/examples/libssh_scp.c: return -1;
./libssh/examples/samplesftp.c: return -1;
./libssh/examples/samplesftp.c: return -1;
./libssh/examples/scp_download.c: return -1;
./libssh/examples/scp_download.c: return -1;
./libssh/examples/scp_download.c: return -1;
./libssh/examples/scp_download.c: return -1;
./libssh/examples/ssh_X11_client.c: return -1;
./libssh/examples/ssh_X11_client.c: return -1;
./libssh/examples/ssh_X11_client.c: return -1;
./libssh/examples/ssh_client.c: return -1;
./libssh/examples/ssh_client.c: return -1;
./libssh/examples/ssh_server.c: return -1;
./libssh/examples/sshd_direct-tcpip.c: return -1;
./libssh/examples/sshnetcat.c: return -1;
./libssh/examples/sshnetcat.c: return -1;
./libssh/examples/sshnetcat.c: return -1;
./libssh/src/agent.c: return -1;
./libssh/src/agent.c: return -1;
./libssh/src/agent.c: return -1;
./libssh/src/auth.c: return -1;
./libssh/src/auth.c: return -1;
./libssh/src/base64.c: if(!ptr) return -1; \
突然想到,我似乎从未见过执行结果的返回值是两位数。
我在雅虎知识袋2008年左右的一个回答中找到了关于使用-1作为原因的解释,但那并不是一个很可靠的答案。我只找到了日立公司发布的名为uCosminexus Interschema的应用程序服务器和中间件产品中提到这一点。
C语言出口函数的定义
3 -1 转换失败 传递给用户内置函数的字符串的字符编码 这是在传递给用户内置函数的字符串末尾附加了NULL终止符的结果。
然后,如果在最后给出return -1并检查返回值,它会变成255。
alleycat:[haturatu]:~/git/cmem$ ./a
格納した文字列 : Hi, My sweet hearts
alleycat:[haturatu]:~/git/cmem$ echo $?
255
Go语言的情况
这在Go语言中,即使给出os.Exit(-1)也是一样的,但有时会出现254的情况,这让我感到疑惑。
难道说,除了0、1、2之外,所有其他情况都返回-1,并通过-1动态返回错误代码,从而将其作为一种不会影响其他操作的异常错误来处理吗?
这类信息相对较少。如果说Go语言中有什么技术是积极领先开发的,那我认为是Go-Ethereum,但仔细一看,它也...
:~/git/go-ethereum$ grep -r "return \-1"
grep: warning: stray \ before -
crypto/secp256k1/libsecp256k1/src/java/org/bitcoin/Secp256k1Context.java: if(!enabled) return -1; //sanity check
crypto/secp256k1/libsecp256k1/src/num_gmp_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/field_10x26_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/ecdsa_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/ecdsa_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/ecdsa_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/ecdsa_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/ecdsa_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/ecdsa_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/ecdsa_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/ecdsa_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/field_5x52_impl.h: return -1;
crypto/secp256k1/libsecp256k1/src/gen_context.c: return -1;
crypto/signify/signify_fuzz.go: return -1
trie/iterator.go: return -1
trie/iterator.go: return -1
event/event.go: return -1
event/feed.go: return -1
common/prque/lazyqueue.go: return -1
triedb/pathdb/database_test.go: return -1
cmd/devp2p/nodesetcmd.go: return -1, errors.New(" -limit requires an argument")
cmd/devp2p/nodesetcmd.go: return -1, fmt.Errorf("invalid -limit %q", args[i+1])
cmp/devp2p/nodeset.go: return -1
cmd/devp2p/dns_route53.go: return -1
accounts/abi/bind/bind.go: return -1
core/state/snapshot/iterator_fast.go: return -1
core/state/snapshot/iterator_fast.go: return -1
p2p/protocol.go: return -1
p2p/enode/node.go: return -1
仔细观察,大部分都是在库中调用的,在庞大的代码库中只有这些。这感觉像是从某个地方引入的公钥加密实现源代码,所以实际上可能不是Go-Ethereum的代码。
另一个从很早以前就开始开发的项目是Hugo。
:~/git/hugo$ grep -r "return \-1"
grep: warning: stray \ before -
compare/compare_strings.go: return -1
htesting/test_helpers.go: return -1
htesting/test_helpers.go: return -1
hugolib/filesystems/basefs_test.go: return -1, nil, err
common/hreflect/helpers.go: return -1
common/herrors/error_locator_test.go: return -1
common/herrors/error_locator_test.go: return -1
common/herrors/error_locator_test.go: return -1
common/herrors/error_locator_test.go: return -1
common/herrors/error_locator.go: return -1
common/herrors/error_locator.go: return -1
common/herrors/error_locator.go: return -1
common/herrors/file_error.go: return -1
common/herrors/file_error.go: return -1, ""
common/herrors/file_error.go: return -1, -1
common/hugo/version.go: return -1
common/hugo/version.go: return -1
common/hugo/version.go: return -1
common/hugo/version.go: return -1
common/hugo/version.go: return -1
common/hugo/version.go: return -1
common/hugo/version.go: return -1
common/paths/pathparser.go: return -1
identity/finder.go: return -1
resources/page/permalinks.go: return -1
resources/page/pages_sort.go: return -1, -1
resources/page/pages_sort.go: return -1, -1
resources/page/pages_sort.go: return -1, -1
resources/page/pages_sort.go: return -1, -1
resources/page/pages_sort_search.go: return -1
resources/page/pages_sort_search.go: return -1
resources/page/pagination.go: return -1, errors.New("too many arguments, 'pager size' is currently the only option")
resources/page/pagination.go: return -1, errors.New(("'pager size' must be a positive integer"))
resources/images/image.go: return -1
tpl/collections/where.go: return -1, errors.New("unable to convert value to float")
tpl/collections/where.go: return -1, errors.New("unable to convert value to int")
tpl/transform/transform.go: return -1
tpl/internal/go_templates/htmltemplate/transition.go: return -1
tpl/internal/go_templates/htmltemplate/transition.go: return -1, errorf(ErrBadHTML, nil, 0, "%q in attribute name: %.32q", s[j:j+1], s)
tpl/internal/go_templates/fmtsort/sort.go: return -1 // No good answer possible, but don't return 0: they're not equal.
tpl/internal/go_templates/fmtsort/sort.go: return -1
tpl/internal/go_templates/fmtsort/sort.go: return -1, true
tpl/tplimpl/template.go: return -1
tpl/tplimpl/template.go: return -1
tpl/tplimpl/shortcodes.go: return -1
parser/pageparser/pagelexer.go: return -1
parser/pageparser/pagelexer.go: return -1
parser/pageparser/pagelexer.go: return -1
parser/pageparser/pagelexer.go: return -1
parser/pageparser/pagelexer.go: return -1
parser/pageparser/pagelexer.go: return -1
来看看用C语言编写的bash的情况
而且,bash会返回除了0、1等之外的返回值,所以我们来看看bash的源代码。
alleycat:[haturatu]:~/git/bash$ echo $?
130
alleycat:[haturatu]:~/git/bash$ a
bash: a: 命令が見つかりません
alleycat:[haturatu]:~/git/bash$ echo $?
127
这样看来,似乎会有return 130之类的,但是...
alleycat:[haturatu]:~/git/bash$ grep -r "return [0-9]" | awk '{print $2" " $3}' | sort | uniq | grep ^r
grep: .git/objects/pack/pack-715759b749131276aa4809bba44f79c13feb23ec.pack: binary file matches
return 0
return 0,
return 0.
return 0.0;
return 0;
return 0L;
return 1
return 1,
return 1-no_line_editing;
return 1.
return 10;
return 11;
return 12;
return 13;
return 14;
return 16
return 1;
return 2
return 2;
return 2;;
return 3
return 3;
return 4
return 42
return 4;
return 5
return 5;
return 6;
return 7
return 7;
return 8;
return 99999;
return 9;
alleycat:[haturatu]:~/git/bash$ grep -r "return -[0-9]" | awk '{print $2" " $3}' | sort | uniq | grep ^r
return -1
return -1.
return -1/EINVAL
return -1;
return -25
return -2;
没有找到。严格来说,使用grep -r "return " | grep -oP "return.*" | sort | uniq | grep "[0-9]" 可能会提取更多,但因为它太长了,所以请允许我使用上面的方法。
这样看来,似乎只能认为是动态生成错误代码了。
我调查这些琐碎的事情,是因为担心调试会变得非常困难,所以想提前做些研究。而且,尽管Go语言变得简单了,但似乎仍然无法摆脱C语言。
だいせんじがけだらなよさ
久违地听加藤和彦的专辑时,我对歌曲名だいせんじがけだらなよさ产生了兴趣并查了一下,发现它似乎是卡门·真希(Carmen Maki)的翻唱。
而原作者似乎是寺山修司。
《如果告别是人生》与《だいせんじがけだらなよさ》 诗:寺山修司 歌:卡门·真希 1969年
如果告别是人生 那么再次来临的春天是什么
在遥远遥远的地平线盛开的野百合是什么
如果告别是人生 那么重逢的日子是什么
温柔温柔的晚霞和两人的爱是什么
如果告别是人生 那么建造的家园是什么
在寂寞寂寞的平原上 点亮的灯火是什么
如果告别是人生 那么人生什么的 我不需要。
寺山修司 《如果告别是人生》
感到寂寞时说出口 孤单一个人的咒语
为了忘记离别之人的回忆的咒语
だいせんじがけだらなよさ だいせんじがけだらなよさ
倒过来读就成了那个人 教给我的歌
告别才是人生
告别才是人生
寺山修司 《だいせんじがけだらなよさ》
这种渺小的感觉更添一丝哀愁。
加藤和彦曾所属的The Folk Crusaders乐队,或许正是因为有了这些日本文学的滋养吧。