I’m getting rather hacked off seeing boolean properties typed as strings. Stringly typed is a phrase I learnt off a post from the excellent Coding Horror blog and it describes a phenomena whereby properties that are of a specific type, e.g. Boolean, Date, int, are stored needlessly as strings.
I’m working on a website that communicates with a money laundering service to check whether an individual is “bad” or not. Individuals can pass the test, but importantly it is possible to pass the test with some warning flags raised. If any of the warning flags are raised then an email should be sent off to compliance for them to do…whatever it is they do. Fair enough right?
The warning flags are obviously booleans. There was either a warning raised or there wasn’t – there are no two ways about it (no pun intended). In the serialized response, the warning flags are encoded as “Yes” or “No”…which is understandable. Now, upon receiving the response, it is parsed and turned into an internal representation. This is where things get really weird. The programmer that coded the object that stores the response from the service has decided to encode the warnings as strings, initialised to “”. Which is totally fucking bonkers.
Why?
Well, now our boolean warnings aren’t really booleans – they have WAY more than two possible values and the meaning of these values is subjective. One may consider “”, null, “No” as false, but could conceivably also consider “false” or “0″. We get the same sort of problem with true – “Yes”, “1″, “true” and then we get a whole load of unknown values which is every other possible string in the world. Which might be considered to be true.
So how the hell can any number of programmers work on this piece of code without introducing errors because of differing definitions of truthy and falsey values? Well, they can’t. To illustrate the problem further, even loosely typed languages differ in their boolean coercion, for example JavaScript and PHP:
<script>
if("0") alert('Opposite day!');
</script>
<?php
if("0") echo 'Opposite day!';
?>
JavaScript considers “0″ true but PHP considers it false. Personally I think JavaScript is “right” here, but as I said before, it is totally subjective.
The icing on the cake is of course the extra code you have to write to check the truthy or falsey string values. Something along the lines of “if x is not null and not empty and not the word No then it is probably true…probably”, which would otherwise have been coded as “if x then true” if x was a boolean – which is orders of magnitude shorter.
Of course, there are some bat shit crazy strongly typed languages that allow you to assign null to a Boolean, but that is a different story altogether.
onlineshoppinghub – Efficient and user-focused, navigating the site for purchases is hassle-free.
SmartPurchaseCenter – Smooth and secure, checkout is simple and reliable.
progression hub – Encourages action, website layout keeps focus clear and simple.
trusted market network – Practical content, makes alliances easy to apply in actual markets.
OnlinePurchasePro – Professional layout that makes shopping feel safe.
IdeaValueCenter – Engaging and user-friendly, helps generate fresh and practical ideas.
bond strategy hub – Feels well organized, making complex ideas approachable.
Professional Guidance Hub – User-friendly design, exploring content feels effortless and reliable
goal clarity – Very informative, helps turn big goals into manageable actions.
discover growth directions – Useful information, content helps clarify decisions quickly and clearly.
relationshiplens – Offers perspective on maintaining solid business connections.
ModernMethodsGuide – Easy-to-read content that quickly teaches useful strategies.
learn knowledge wisely – Clear and structured lessons, makes understanding simple.
modernbuying – Easy to navigate, buying products online is quick and hassle-free.
Think Tank Online – Simple navigation and interactive content promote idea exploration effectively
growth partners hub – Insightful approach, site presents sustainable growth ideas clearly and effectively.
partnermanual – Informative and concise, the advice is directly applicable to real-world business.
ActionablePathways – Clear instructions make adopting better approaches easy.
market collaboration hub – Informative advice, alliances explained clearly for market applications.
explore steady progress – Offers easy-to-understand guidance on long-term success and growth planning.
partnership strategy portal – Promising design, helpful for building effective and lasting alliances.
MegaCartExpress – Smooth browsing, intuitive and modern design.
WorldwideBusinessHub – Offers clear insights into global markets, making it easy to follow trends.
KnowledgeMastery – Well-structured content, learning feels efficient and approachable.
alternative perspective center – Provides insights that help consider new angles without pressure.
realworldsolutions – Delivers advice you can use right away to improve results.
ProActiveTips – Encourages decisive moves that bring real benefits.
learnfromexpertinsights – Excellent site, expert insights are practical and easy to apply today.
corporatecollaborationzone – Platform highlights teamwork and strategic business relationships.
ShopSmartHub – User-focused layout makes shopping convenient and fun.
retailvisionary – Clear and actionable, platform presents future retail concepts in an easy-to-follow format.
click for digital learning – Friendly tutorials, guides are structured and simple.
path to career success – Informative and intuitive, helps users explore professional options clearly.
alliances for growth – Focused on fostering mutually beneficial business partnerships.
smart buying hub – The setup feels clean and user-driven, which improves the experience.
ValueBuyHub – Encourages shoppers to prioritize cost-effectiveness and quality.
digitalpurchasecenter – Very smooth experience, navigating and buying products online is simple.
SmartPartnerPlans – Concise content that supports effective collaboration.
strategic learning portal – Helps users develop intelligent approaches to learning and scaling.
StrategicSolutionsOnline – Offers clear insight for evaluating business strategies.
new growth insights – Well structured, encourages exploration and understanding effectively.
strategic growth network – Clear guidance on achieving consistent growth and future planning.
commercialbondstrategies – Offers structured insight for handling bonds reliably and effectively.
strategic alliances portal – Helps firms pursue partnerships that support long-term goals.
ChoiceProTips – Practical and approachable advice, decision-making is simplified.
leadershiphub – Very practical, strategies from market leaders are broken down in an understandable way.
growth plan – Motivating strategies, content makes moving forward intentional and achievable.
solution comparison hub – Clear guidance, platform supports understanding multiple alternatives.
SkillBoostOnline – Provides practical resources that feel easy to follow and apply.
trusted business links – Practical tips for building trust, content is clear and approachable.