[Disclaimer: This is not syntactically correct. I just built enough to make the question clear]
Suppose I have a pair of classes:
class a{
//..
signals:
void ask_B_for_update(double);
public slots:
void update_A(double);
}
class b{
//..
signals:
void send_update_to_A(double);
public slots:
void update_B(double);
}
connect(ask_B_for_update,update_B)
connect(send_update_to_A,update_A)
class a{
//..
signals:
void ask_B_for_update(double);
public slots:
void update_A(double);
}
class b{
//..
signals:
void send_update_to_A(double);
public slots:
void update_B(double);
}
connect(ask_B_for_update,update_B)
connect(send_update_to_A,update_A)
To copy to clipboard, switch view to plain text mode
This means that to update a value (in my case a keypad) from some kind of database I'll say "Please give me a maximum value"
"I'll go get it"
"Here you go"
"Ok now I can save it"
Were I to instead do:
class a{
//..
signals:
void ask_B_for_update(&double);
}
class b{
//..
public slots:
void update_A(&double);
}
connect(ask_B_for_update,update_A)
class a{
//..
signals:
void ask_B_for_update(&double);
}
class b{
//..
public slots:
void update_A(&double);
}
connect(ask_B_for_update,update_A)
To copy to clipboard, switch view to plain text mode
This reduces code bloat and increases readability in my mind. Further, doing it as the first style one needs to save the result to a member variable instead of being able to utilize a local variable. This is wasteful and bad design in my mind. I'd note that COM, however dreadful it is to work with, tends to do the latter; and the design doesn't feel bad to use. While not important, this is also faster, less complex, etc..
Question:
It would seem from my search though that the only information I've found says that sending references by signals is bad. When doing so in the above we see that we (potentially..) halve the number of functions, we increase speed, we increase readability, we increase reliability (I think), and we reduce complexity.
What argument can stand to eliminate all of these benefits?
I'm looking for a mild debate (if you disagree with this) as I've designed initially in the first style. Now I see all of these benefits but don't wish to make a large design mistake and waste half a day (essentially) redoing work to get a worse product.
[NOTE: I should mention that I mean this primarily for simple data types (ints, doubles, etc..) ]
Thank you for your input
Bookmarks