brain suddenly consumed by thoughts of "what if i restructured my entire programming paradigm around Not Having Methods"
basically using this:
class Foo
{
public:
friend auto do_thing(Foo const &foo) -> void;
Foo(int x);
private:
int my_x { 0 };
};
int main()
{
Foo foo { 5 };
do_thing(foo);
return 0;
}
instead of this:
class Foo
{
public:
auto do_thing() -> void;
Foo(int x);
private:
int my_x { 0 };
};
int main()
{
Foo foo { 5 };
foo.do_thing();
return 0;
}
reasoning: nothing super rigorous, but i kind of like the idea of aggregate (class/struct) types being just Bundles Of Stuff and writing functions that operate on them instead of having this special different kind of callable.
the thought that led me here was about how nice record types in functional languages are because of exactly this paradigm. a type in, say, Haskell, is just the material stuff that makes it up, plus a tag saying "this ball of junk is a Bingus"; then even though some functions may have privileged access to the insides of the Bingus due to whatever accessibility convention, they're still just functions. you can do all the same things with them as you can with any random function, because the notion of "privileged access" is compile-time, not run-time.
the only downsides to this that i can see are:
- more typing:
buffer.push(item)vs.crucible::core::memory::push(buffer, item) - needing to rely on the (imo) unintuitive argument-dependent lookup rules in generic contexts:
e.describe()is easier to resolve thandescribe(e), especially for humans
and of course, some functions have to be member functions, by the rules of the language (mainly constructors, destructors, and assignment/subscript/call operators), but that's not really a big problem.
curious for opinions about this! might be a terrible idea for reasons i haven't foreseen, or might be something worth experimenting with...

eggbug enjoyer