News for hackers. Stuff that matters.
Re:Exceptional Naming by ahartmetz on Saturday June 26, 2021 @09:06AM (#27641502)
In a similar spirit: I have a naming rule that I haven't read about yet because not everybody uses signals and slots. So the framework that I use most of the time, Qt, has signals and slots. Signals are emitted when certain things happen and slots can be "connected" to them to respond.

Sometimes I see signals and slots named like this:

  // signal in one class (generic name because it's a generic control)
  void valueChanged(int value);
  // slot in another class (part of "this" software package)
  void handleValueChanged(int value);
  // connection
  connect(spinbox, &SpinBox::valueChanged,
          client, &HttpClient::handleValueChanged);
I prefer to name them like this:

  // signal
  void valueChanged(int value);
  // slot
  void setServerPort(int value);
  // connection
  connect(spinbox, &SpinBox::valueChanged,
          client,  &HttpClient::setServerPort);
The bad example is a strawman, but my point is that, if the signals and slots are well named, one can see in the connect() "if X changes then Y happens". Such naming is not always possible, because sometimes, the effects of a change are extensive enough that "handle X changed" is the best reasonably short and unchanging description.
Re:Exceptional Naming by crubier on Sunday June 27, 2021 @12:17PM (#27652789)
I don’t like your technique because:

1- As you say yourself, there is some amount of subjectivity about when « handleX » is the best description (when the effect is extensive enough) and when it is not.

2- The whole point of calling handlers « handleX » is that you DO get to know what happens when the event X happen: you just have to read the content of « handleX » function.

So here is my solution: follow conventions. If your handler is a simple thing like « setServer » you’ll see that the function content is one line of code. If it’s more complex, you will see it also.

It works 100% of the time, ensures that people won’t loose their mind reading your code, and prevent useless debates about form.

Re:Exceptional Naming by ahartmetz on Sunday June 27, 2021 @08:34PM (#27656846)
The idea of signals and slots is a loose, flexible coupling, so I think that the connect() is the perfect place to read about what causes what. It seems like your expectations come from something like virtual interfaces (in the C++ sense) - these often have a limited amount of implementations on both sides that "know" each other more closely.