Re: [PATCH 2/6] core: changed type of date keys to GDateTime



On 28/06/2011 09:08, Juan A. Suarez Romero wrote:
> On Wed, 2011-06-22 at 19:07 +0200, Guillaume Emont wrote:
>> +grl_media_set_date (GrlMedia *media, const GDateTime *date)
> 
> I would drop the 'const' prefix from that parameter.
> 
> I've been looking at other functions that use a constant GDateTime
> (mainly, the GDateTime functions themselves), and none of them is
> prefixing the parameter with a 'const', even when the parameter is never
> modified.
> 
> I only see the use of const for string parameters.
As a general policy, I prefer to take a const as parameter when we don't
modify the value, since functions with a const parameter accept
everything (const and non-const) whereas functions with a non-const
parameter only accept non-const.
Moreover, I see a use for it here:
The getter returns the value owned by the media, and therefore it
returns a const value to say that it cannot be modified.
This mean we can be handling const GDateTime * values. And the only safe
things to do with a const GDateTime * are:
 - copy it
 - pass it to a function that accepts a const
In that context, our functions that don't modify the value should take a
const as parameter.

Guij


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]