Hi Peter,
55 \todo Should we prefer to return a reference or should we prefer to return
56 a pointer to the internally stored PacketBase object? Currently there is an
57 issue with the Driver generation. Functions returning references are parsed
58 as void functions (moc.cpp:418). The problem is twofold:
59 - Should we use CalitkoMocks to test value objects? Value Objects are just
60 data and should not have behavior which we could write expectations for?
61 - Should we agree on a convention where reference objects are passed
62 around using pointers and value objects are passed around using
63 references?
I think that it depens on what are we going to do with the object (either returned by a function or passed as a function parameter).
I usually use references in these situations:
- to ensure that a user will pass some object to the function and not just a NULL pointer (public interface)
- to ensure that a user won’t delete returned object (well, he can do this anyway by using & operator, but then it’s obvious that he knows what’s he doing)
- when I want to handle exceptions using
dynamic_cast<>rather than test the return value - basicly I use them over pointers whenever it’s possible (less error prone)
I usually use pointers in these situations:
- when it’s possible that a user will pass a NULL pointer instead of an object (public interface)
- when the returned object should be deleted by an user (passing ownership) - I prefer “smart pointers”, though
- when the returned pointer could be a NULL pointer (to signalize an arror)
- when I need to pass a pointer-to-pointer (I can’t use a reference-to-reference)
- when I don’t want to handle exceptions using
dynamic_cast<>(for example in the Torrent parser class) - basicly I use them over references only when it’s more appropriate
55 Should we prefer to return a reference or should we prefer to return
56 a pointer to the internally stored PacketBase object?
If we’re going to do downcasts a lot and don’t want to handle exceptions then we should return a pointer, otherwise a reference. But maybe there is some detail I’m not aware of now - hope I haven’t read it out of context.
59 - Should we use CalitkoMocks to test value objects? Value Objects are just
60 data and should not have behavior which we could write expectations for?
I think that state-based testing is more appropriate there - as you’ve written, I’d use mocks when we need to test behavior (for example to test network communication) and classic unit tests elsewhere.
61 - Should we agree on a convention where reference objects are passed
62 around using pointers and value objects are passed around using
63 references?
As I’ve written, from my point of view it depens on the situation, so I’d prefer to let programmers to decide which variant they should use. But I think that it’s a good idea to unite it between related modules!
Petr
