darage
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Bad APIWow.. thanks all for the replies. I didn’t mean to insult anybody but i wrote the post in the most blunt manner to get the point across. the_categories() function is one example of a bad approach to an api design because it returns an unordered html list which is a clear mix between formatting and behavior. for example if i wanted to return the categories is a div list instead i have no choice but to not use the the_categories() function.. but if the function just returned a list of categories and left it for me to choose how to format the output it would’ve made it easier for me than using sql queries.
The sole function of a good api is provide reuse and hide implementation so that i don’t have to go the database and understand the data model in order to achieve what i want to do. Another principle it to facilitate reuse and flexibility which is not achieve by above function.
another thing, naming conventions are really poor. For example the_categories is a really bad name for the following reasons:
1. why prefixing it with the? it doesn’t add any information no?
2. function names should be verbs that explain what the functions do. for example get_categories() would’ve been a better function name (although im not a fan for underscores but that’s another issue).
3. it’s not obvious from the name that the function returns a formated list.. so maybe it should’ve been get_formatted_category_list(). of course it’s better that the function doesn’t return formatted output.and so on and so forth.. i didn’t even go into how the parameters are constructed.
another bad naming is prefixing things with WP, why is that? it is absolutely unnecessary and i can’t find any reason for it.
for those who argued that the api is designed for non programmers. for me who esle is going to use an api other than a programmer?