[HOME] [DOWNLOAD] [DOCS] [NEWS] [SUPPORT] [TIPS] [ISSUES] [DONATE]

Stylistic question about function names

Wondering about function names. What’s more descriptive?

“Sentence style”?

Or “what it’s mainly about front, details at the end style”?

One of the benefits of the latter type is…

With multiple related functions (or variables), they can be visually and alphabetically structured to “go together”.

Going from broad/common to specific/unique terms/attributes in the naming format.

[hr]

Similar to the reason for formatting dates like this (descending order example):

YYYY-MM-DD:

2015-02-02
2014-10-23
2014-10-22
2014-10-21
2013-09-23
2013-09-22
2013-09-21
2012-01-01

vs.

DD-MM-YYYY:

23-10-2014
23-09-2013
22-10-2014
22-09-2013
21-10-2014
21-09-2013
02-02-2015
01-01-2012

[hr]

Functions example:

Hierarchical category namespacing:

date_getter_year_odd()
date_getter_year_even()
date_getter_month_odd()
date_getter_month_even()
date_setter_year_odd()
date_setter_year_even()
date_setter_month_odd()
date_setter_month_even()
name_getter_person_teacher()
name_getter_person_student()
name_getter_course_math()
name_getter_course_science()
name_setter_person_teacher()
name_setter_person_student()
name_setter_course_math()
name_setter_course_science()

vs.

More like sentence style verbage:

get_odd_year_date()
get_teacher_person_name()
get_odd_month_date()
get_math_course_name()
get_even_year_date()
get_student_person_name()
get_even_month_date()
get_science_course_name()
set_odd_year_date()
set_teacher_person_name()
set_odd_month_date()
set_math_course_name()
set_even_year_date()
set_student_person_name()
set_even_month_date()
set_science_course_name()

[hr]

One can more easily recognize related functions (or variables) by building in a common “namespace hierarchy” into the frontend of the function name when structured this way.

The latter is also more object-like.

Take a python function we have been using lately:

if os.path.exists("file_name")

All in all, it looks (and sounds) more standard.

Agreed. I’ll keep that in mind for new developments. But I won’t refactor the hell out of the existing code. (Patches still welcome, though.) See this as a long term effort. When refactoring existing code, I’ll keep the better naming schema in mind.

[Imprint] [Privacy Policy] [Cookie Policy] [Terms of Use] [E-Sign Consent] [DMCA] [Investors] [Priority Support] [Professional Support]