Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: What can lead to misleading names of functions?
3 points by JZN666 on Nov 25, 2021 | hide | past | favorite | 5 comments
1) parse_str in PHP, which extracts query parameters from request URL. This can have simple explanation: this is old relict which was designed at earliest versions of PHP. And PHP back then was designed as web templating language, not general programming one. So this name wasn't much confusing in this context;

2) What about functions like getOurCityTimezone() ? This functions seems to be returning timezone of our city but what it really does is checking if current time is before certain deadline (determined by specific business rules). I can't give simple explanation to this. This looks like: * Programmer who wrote this function, is not fluent in English. Even with this statement the name is too divergent from real meaning of function to be just lexical mistake. And the programmer could translate it roughly with Google Translate; * This function would be initially called as "isBeforeOurCityTimezone", but as programmer wasn't such fluent in English, this was called "getOurCityTimezone". AND it really determined if current time is before 00:00 (next day) in local time. And it was used to calculate date gap. But then business decided to shift border from 00:00 to earlier time like 23:00 . And for the sake of backwards compatibility, avoiding copypasta and not "wasting" time for refactoring only the body of function was changed. The name remained the same;

What are common reasons to misleading names of functions?




Not caring enough to try to come up with good names.

I see tons of functions named update_data and get_state and add_items in the business logic sections, which should be named for the specific things they touch. But laziness leads to using meaningless generic terms.

The other two are lack of English knowledge (both in native and non-native speakers), and when the function used to do something else but the name wasn't updated.


> I see tons of functions named update_data and get_state and add_items in the business logic sections

Maybe they're bounded by some clear context like class or module which serves specific set of tasks? Writing in well designed context MyPartOfSystem things like MyPartOfSystemUpdateData is another smellish side of naming I think. Or writing just long names that are used only in very short context (ex. variable "drivingLicenseCard" instead of "e", "entry" in "drivingLicenseCards.every((drivingLicenseCard) => drivingLicenseCard && checkSomehow(drivingLicenseCard))").

If they're not bound, then we have another source of spaghetti monster.


No, they are not bounded.


The real reason for PHP's bad function names is that early in the language's history, the hash function used to map function names to their actual code was the length of the string, so you couldn't have two function with a name of the same length, thus the intentionally inconsistent naming convention.


But this gives very short set of possible function names (up to 20 characters length (?), more is not adequate for development). And even with this parse_str could be named something like "url_parse_query_params_from_str(str)".




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: