private
C++系のクラス型OOPLの全般に言えることだけど、同じクラスのオブジェクトならばprivateであっても自由に触れるというのは厄介な仕様だ。ここを区別している点はRubyの長所なのでRubystはもっと宣伝しても良いと思う*1。
C++の場合。
#include <stdio.h> class Test { private: int i; public: Test(int i) :i(i) { } void read(const Test& other) { printf("%d\n", other.i); } }; int main() { Test t0(0), t1(1); t0.read(t1); return 0; }
Rubyの場合。
#!/usr/bin/ruby class Test def initialize(i) @i = i end def read(other) #print(other.i, "\n")#error end end t0 = Test.new(0) t1 = Test.new(1) t0.read(t1)
これによらず歴史的な理由により保存されている怪しい仕様は沢山ある。そういう怪しい仕様を捨てるためにはschemeのように機能の素因だけを言語仕様に含め、実質的な機能は外部ライブラリに置くのが良いのではないか。