Which naming convention for conversions is standard across most languages?
convert_from_typea_to_typeb(arg)
or
convert_to_typeb_from_typea(arg)
Or is there another standard?
Which naming convention for conversions is standard across most languages?
convert_from_typea_to_typeb(arg)
or
convert_to_typeb_from_typea(arg)
Or is there another standard?
I guess in C(++) you would do it with cast operators, so none of these names would fit.
In Objective-C I've seen something like NSPointFromCGPoint(...), or you would give the old type simply in the constructor.
The only thing that I've seen very rarely are those functions with convert_x_to_y :-)
My answer, and purely subjective, would be the one that flows logically with source to destination.
ConvertStringToInt()
or
ConvertVisitorToCustomer()
There is no cross-language standard for this kind of thing. Most languages either provide a built-in way to do this (C/C++) or encourage you to find another way around it (Java/C#).
In most object-oriented languages you shouldn't need this sort of functionality. You should try to restructure your program so that you do not need to do any explicit conversions.
However, if you really need to do this, I'd say drop the "convert" at the beginning and do <source>_to_<target>
. Examples: string_to_int
, int_to_float
, foo_to_bar
, etc. (Of course, write these in whatever case your language prefers. For example, in C#: StringToInt
; in JavaScript: stringToInt
.)