Boolean or Integer?
I solved a puzzle today where figured before all the `wp_list_categories()` function. When I looked at the parameters one thing attracted my mind. Look at the call from default Kubrick template in WP 2.2.
/—code php
Categories
‘); ?>
\—
This code I had before my eyes and thought about the first parameter. `show_count=1`. “What does it mean?” – I asked myself. “What’s the sense in showing the only category, why not to show all of them? But… I looks like it’s not woking through.” Then I got it, you know. `1` from `show_count` parameter means a boolean value, not a count, not a number of something. The “1″ doesn’t mean one as a number, the “1″ means “yes”, “true”.
In whiles like this, I wish PHP to be more strict in data types (although this string is going to be parsed, so it’s not the best example). I understand and in much moments I appreciate PHP’s tolerance, but as you can see, this issue has it’s dark side as well, in this case there’s before all visible **the problem of unclear meaning**. But it’s not necessary to remind the plus of such using of integer type – I think the most distinct asset is ability of making code visually tidier. So it’s not easy to say a resolution like “For boolean values, use always boolean type!” This is not a clearly answerable “question”, using integer type instead of pure boolean has it’s pros and cons both.
So I am naturally not able to pronounce the absolutely truth, the best solution of our dilemma. Perhaps better naming of variables could prevent us from such situations of misunderstanding… as usual, *it’s all about the code writer*.
Comments
No comments yet.
Add a comment