Daisenji ga Kedaranayosa
Hello, this is incompetent.
Recently, I've been thinking that if I'm going to touch Go, maybe I should learn C. So, I've started learning from past frustrations about how memory management, which you don't have to think much about in Go and Rust, actually works. Suddenly, while looking at the source code of mscp, the parallel processing version of SCP, I wondered why it returns -1 as a return value.
$ 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; \
Come to think of it, I don't recall ever seeing a two-digit return value for execution results.
I found a reason for using -1 in a Yahoo! Answers response from around 2008, but it wasn't a very reliable answer. The only other place I found information was in the documentation for Hitachi's uCosminexus Interschema, an application server and middleware product.
Definition of C language exit functions
3 -1 Conversion failed Character code of the string passed to the user-defined function This is the string passed to the user-defined function with a terminating NULL appended.
So, if you give return -1 at the end and check the return value, it becomes 255.
alleycat:[haturatu]:~/git/cmem$ ./a
格納した文字列 : Hi, My sweet hearts
alleycat:[haturatu]:~/git/cmem$ echo $?
255
In Go's case
This was the same even when os.Exit(-1) was given in Go, but there were patterns where it became 254, and I wondered why.
Perhaps, as a return value, it returns 0, 1, 2, and for everything else, it returns -1, treating it as an exceptional error that doesn't cause problems for other operations by dynamically returning an error code with -1?
Information of this kind is relatively scarce. If I were to name a technology that's aggressively leading development in Go, it would be Go-Ethereum, but if you look closely at this too...
:~/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/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])
cmd/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
Looking closely, most of these are called within libraries, and only the above appear in the vast codebase. It feels like the source code for public-key cryptography implementation was probably brought in from somewhere else, so it doesn't seem to be Go-Ethereum's code in essence.
Another project that has been under development for a long time is 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
Let's look at the case of bash written in C
And since bash returns return values other than the easily understandable 0, 1, etc., let's look at the bash source code.
alleycat:[haturatu]:~/git/bash$ echo $?
130
alleycat:[haturatu]:~/git/bash$ a
bash: a: コマンドが見つかりません
alleycat:[haturatu]:~/git/bash$ echo $?
127
In this case, it seems like return 130 or similar might exist, but...
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;
It wasn't there. Strictly speaking, grep -r "return " | grep -oP "return.*" | sort | uniq | grep "[0-9]" would extract more, but it was too long, so please bear with the above.
In that case, it still seems like error codes are being generated dynamically.
The reason I'm researching such trivial matters is to prepare in advance for debugging becoming a nightmare, and it seems that even though Go is a simpler language, there's no escaping C language.
Daisenji ga Kedaranayosa
Listening to Kazuhiko Kato's album after a long time, the song title Daisenji ga Kedaranayosa caught my attention. I looked it up and found it's a cover by Carmen Maki.
And the original source seems to be Shuji Terayama.
'If Farewell is All There Is to Life' and 'Daisenji ga Kedaranayosa' Lyrics: Shuji Terayama, Song: Carmen Maki, 1969
If farewell is all there is to life, what then is the spring that comes again?
What are the wild lilies blooming at the far, far ends of the earth?
If farewell is all there is to life, what then is the day we meet again?
What are the gentle, gentle sunset and our love?
If farewell is all there is to life, what then is the home we built?
What is the light we kindle on the lonely, lonely plain?
If farewell is all there is to life, then I don't need life at all.
Shuji Terayama, 'If Farewell is All There Is to Life'
When I feel lonely, I say it, a lonely person's charm.
A charm to forget the memories of the person I parted with.
Daisenji ga kedaranayosa, Daisenji ga kedaranayosa
Read backward, it becomes the song that person taught me.
Farewell is all there is to life.
Farewell is all there is to life.
Shuji Terayama, 'Daisenji ga Kedaranayosa'
This small, humble feeling adds to the sense of melancholy.
Perhaps Kazuhiko Kato's original band, The Folk Crusaders, existed precisely because of this Japanese literature.