N
Nephi Immortal
I ask you for your opinion what chained function name look like. I do not need to post class definition since you know what I am talking about.
Let’s say for example I have 'A' class.
A a( 1 ), b( 2 ), c( 3 );
int data = a.get_value();
a.set_value( 2 );
What if I am going to write like this below?
a.set_value( b.get_value() + c.get_value() );
They can be to include operator=, operator+, and operator cast. It looksvery readable than getter and setter.
a = b + c;
What if I choose to use chained function name?
a.value() = b.value() + c.value();
Is that readable?
If I name value1() and value2(), I may not want to place them in the main class. I rather prefer to place them in the nested class.
a.Inner().value1() = b.Inner().value1() + c.Inner().value2();
What if I don’t like “Inner()”? It should be removed and operator()() is used.
a().value1() = b().value1() + c().value2();
Do chained function name sound good?
Let’s give some ideas.
int data1, data2, data3;
data1 = a.Get().Bytes();
data2 = b.Get().Kilobytes();
data3 = c.Get().Megabytes();
a.Set().Bytes( 1 );
b.Set().Kilobytes( 2 );
c.Set().Megabytes( 3 );
data1 = a().Bytes();
data2 = b().Kilobytes();
data3 = c().Megabytes();
a().Bytes() = 1;
b().Kilobytes() = 2;
c().Megabytes() = 3;
a().Bytes() = b().Kilobytes() + c().Megabytes();
Please comment if my code looks readable.
Let’s say for example I have 'A' class.
A a( 1 ), b( 2 ), c( 3 );
int data = a.get_value();
a.set_value( 2 );
What if I am going to write like this below?
a.set_value( b.get_value() + c.get_value() );
They can be to include operator=, operator+, and operator cast. It looksvery readable than getter and setter.
a = b + c;
What if I choose to use chained function name?
a.value() = b.value() + c.value();
Is that readable?
If I name value1() and value2(), I may not want to place them in the main class. I rather prefer to place them in the nested class.
a.Inner().value1() = b.Inner().value1() + c.Inner().value2();
What if I don’t like “Inner()”? It should be removed and operator()() is used.
a().value1() = b().value1() + c().value2();
Do chained function name sound good?
Let’s give some ideas.
int data1, data2, data3;
data1 = a.Get().Bytes();
data2 = b.Get().Kilobytes();
data3 = c.Get().Megabytes();
a.Set().Bytes( 1 );
b.Set().Kilobytes( 2 );
c.Set().Megabytes( 3 );
data1 = a().Bytes();
data2 = b().Kilobytes();
data3 = c().Megabytes();
a().Bytes() = 1;
b().Kilobytes() = 2;
c().Megabytes() = 3;
a().Bytes() = b().Kilobytes() + c().Megabytes();
Please comment if my code looks readable.