Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] Re: (PR#13460) consistent names for index-to-pointer looku
Home

[Freeciv-Dev] Re: (PR#13460) consistent names for index-to-pointer looku

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#13460) consistent names for index-to-pointer lookups
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 12 Jul 2005 12:01:37 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13460 >

Marko Lindqvist wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=13460 >
> 
> Jason Short wrote:
> 
>>  struct unit_class *get_unit_class(Unit_type_id type);
>>
>>Note that get_unit_class is put at the end.  This isn't actually an
>>index-to-pointer lookup function but it has the exact same name form as
>>most of the existing index-to-pointer lookups!  This is very bad
>>(solution is to rename it and change its parameter to a struct unit_type
>>*, or just to remove it).
> 
>   unit_type_get_class()? Why pointer? Most (future) users will need 
> class for certain unit, not unit_type: unit_type_get_class(punit->type) 
> vs unit_type_get_class(index_to_unit_type(punit->type))

punit->type should be a struct unit_type *.  But as long as you allow
dereferencing the unit (punit->type) you might as well allow
dereferncing the type (punit->type->class).

In the current form it would be

  unit_type_get_class(unit_type(punit));

or

  unit_get_class(punit);

>   Which leads to another function name scheme question. If function to 
> get class for single unit is ever introduced, should it be named 
> unit_get_class()? That seems too easy to confuse with 
> unit_type_get_class(). Maybe unit_instance_get_class()?

Also punit->type->class.  All of the unit-type functions are named very
confusingly already.  Compare unit_type() versus get_unit_type().  This
should be fixed somehow but it's hard to say how.  James's suggestion
was that struct unit_type and struct unit should be merged, so a
specific unit is just a special instance of a unit type.  This would
help by removing one object type but has problems of its own.

-jason





[Prev in Thread] Current Thread [Next in Thread]