pawn-map
pawn-map copied to clipboard
Better function names.
About
This is just an appraisal, stumbled across this plugin and I felt like the function names isn't precise and confusing to new users (I was confused as well until I looked at test.pwn
and the source code, having redundant names such as arr_arr
, str_str
, val_val
.
Solution:
#define new_name old_name
Transition
old name -> new name
MAP_insert_val_val -> Map_InsertValue
MAP_insert_val_arr -> Map_InsertValueArray
MAP_insert_arr_val -> Map_InsertArrayValue
MAP_insert_arr_arr -> Map_InsertArray
MAP_insert_str_str -> Map_InsertString
MAP_insert_str_val -> Map_InsertStringValue
MAP_insert_val_str -> Map_InsertValueString
MAP_insert_arr_str -> Map_InsertValueArray
MAP_insert_str_arr -> Map_InsertStringArray
MAP_get_ptr_val -> Map_GetPointerValue
MAP_get_ptr_arr -> Map_GetPointerArray
MAP_get_ptr_str -> Map_GetPointerString
MAP_contains_val -> Map_ContainsValue
MAP_contains_arr -> Map_ContainsArray
MAP_contains_str -> Map_ContainsString
MAP_get_val_val -> Map_GetValue
MAP_get_val_arr -> Map_GetValueArray
MAP_get_arr_val -> Map_GetArrayValue
MAP_get_arr_arr -> Map_GetArray
MAP_get_str_val -> Map_GetStringValue
MAP_get_str_arr -> Map_GetStringArray
MAP_remove_val -> Map_RemoveValue
MAP_remove_arr -> Map_RemoveArray
MAP_remove_str -> Map_RemoveString
MAP_count -> Map_Count
MAP_clear -> Map_Clear
MAP_iter_get -> Map_IterGet
MAP_iter_next -> Map_IterNext
I agree to change the names to from LIBRARY_function
to Library_Function
convention.
*val_val
means key is array and value is array. I would for example rename MAP_insert_arr_arr
to Map_InsertArrayArray
instead of Map_InsertArray
, because "insert array" doesn't really specify what kind of tuple the insert operation expects. It could be (value, array), (array, array), (string, array), (array, value) or (array, string).
A new param could be introduced as I completely disagree with having redundant name.
Addition
enum E_MAP_TYPES {
MAP_STRING,
MAP_VALUE,
MAP_ARRAY
}
New Function
MAP_InsertString(&Map:map, type, const key[], const value[])
// etc..
New Usage
new
Map:map, arr[10] = { 100, ... };
MAP_InsertString(map, MAP_STRING, "key", "value");
MAP_InsertString(map, MAP_VALUE, "key", 100);
MAP_InsertString(map, MAP_ARRAY, "key", arr, sizeof(arr));
MAP_InsertString(&Map:map, type, const key[], const value[])
MAP_InsertString(map, MAP_VALUE, "key", 100 /* here */);
How should that work?
Again looking at the name *_InsertString
does it mean that a string is expected at the first entry of a tuple (key) or is a string expected at the second entry of a tuple (value)?
An example is if you have to provide your full name and you just either specify only your first or last name. Same for converting a 2D vector to a 3D vector. This operation is not defined without a transformation function.