GNOME Bugzilla – Bug 566847
Signal connect syntax
Last modified: 2009-06-11 16:01:51 UTC
We should consider replacing the syntax used to connect signal handlers. += is not an appropriate operator as a signal should not be considered to be a list, even if there is a list of signal handlers internally. A possible replacement is button.clicked.connect (on_connect); The current syntax should continue to be supported for the foreseeable future to not break existing code. Any comments?
commit b08ab373e57021de2623b827afbf42ad5498aaa3 Author: Jürg Billeter <j@bitron.ch> Date: Wed Apr 15 00:15:29 2009 +0200 Introduce new signal connect/disconnect syntax foo.clicked.connect (handler); Fixes bug 566847.
I disagree with this fix. Quoting some comments from IRC: (11:12:23 AM) vadi2: will the signal += callback be removed? (11:14:52 AM) Jury: probably yes... at least I read something about replacing with connect/disconnect... (11:15:21 AM) vadi2: Those are in 0.7.1. This was rather nice syntatic sugar, however... (11:15:25 AM) Tak: yeah, supposedly it's deprecated (11:16:02 AM) Jury: it's C# syntax, by the way... but connect/disconnect makes more sense for signals... (11:16:08 AM) Tak: the reasoning being iirc that += wasn't an intuitive operator use for a signal (11:16:31 AM) vadi2: I'm thinking exactly the opposite. Oh well. (11:17:47 AM) Jury: I'm more worried about further differentiation from C#... it just makes it steeper for new developers... (11:18:28 AM) vadi2: C person here, came for the nice syntax (11:19:19 AM) Tak: eh...I don't think c# should be the gold standard (11:19:53 AM) Tak: borrow where it's warranted, diverge where it isn't (11:20:01 AM) Jury: me neither, but why change something with such questionable benefit? (11:20:03 AM) Tak: and prune practices that should properly be prohibited! (11:20:20 AM) ***Tak shrug (11:20:47 AM) ***knocte agrees with Jury (11:21:45 AM) Jury: +=/-= may be a bit unintuitive, but at least once you learn it, it's very intuitive to use... and it looks good, too... when connecting and disconnecting looks like a method, it just makes navigation in the code more difficult... (11:22:20 AM) Tak: but it actually is a method (11:22:45 AM) vadi2: http://bugzilla.gnome.org/show_bug.cgi?id=566847 (11:23:04 AM) vadi2: Maybe that can be weighted on :-/ (11:24:07 AM) Jury: maybe so, but treating signal as an object doesn't seem like a right idea to me... (11:25:13 AM) Jury: that was response for Tak...
Well. += may be not ideal, but methods don't feel right either, as I said on IRC (Jury). Maybe we can settle on some other syntax? I thing following would be nice: connect [callback] to [signal]; disconnect [callback] from [signal]; A bit verbose, but very clear.
I don't think we want a completely separate syntax that doesn't fit with anything else, this wouldn't improve the situation at all. In my opinion, methods on a signal to connect/disconnect are quite sensible, but I guess it's matter of taste. While it's recommended to use the new connect() syntax, the += syntax will remain supported for Vala 1.0 to avoid unnecessary incompatibilities. I discourage using += for new code, though, as different syntax for the same functionality hurts code readability.
(In reply to comment #4) > I don't think we want a completely separate syntax that doesn't fit with > anything else, this wouldn't improve the situation at all. In my opinion, > methods on a signal to connect/disconnect are quite sensible, but I guess it's > matter of taste. > Yeah, you are right. > While it's recommended to use the new connect() syntax, the += syntax will > remain supported for Vala 1.0 to avoid unnecessary incompatibilities. I > discourage using += for new code, though, as different syntax for the same > functionality hurts code readability. > That's the thing. Maybe it's just that I'm not used to it, but the method syntax doesn't seem very readable to me. Anyway, as long as += is supported, there is no need to bother with it. We can just wait and see what other people think once it's used a bit more.