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.
cityshoppinghub – Easy-to-use and modern, making online shopping efficient and enjoyable.
growthhub – Very practical, the ideas are clearly explained and can be applied immediately.
Efficient Growth Paths – Found the structure helpful for turning ideas into plans.
StrategicLearningHub – Very clear guidance, makes understanding strategies simple and actionable.
BusinessKnowledgeClick – Practical and concise guidance for learning business effectively.
ProTrustConnections – Focus on trustworthy partnerships enhances professional networking effectively.
ClickPathway Steps – User-friendly site, navigation supports learning and taking next steps confidently
stepwise digital guide – Straightforward instructions, platform helps navigate digital planning smoothly.
modern online shopping – Designed for efficient product discovery and quick checkout.
ExploreStrategicOpportunities – Helpful content that supports thoughtful long-term planning.
click for fresh views – Introduces alternative perspectives that spark curiosity and reflection.
trustworthy shopping hub – The design and setup convey reliability and peace of mind.
alliancebondsolutions – Organized approach conveys professionalism and practical corporate utility.
ReliableDealsHub – Very convenient platform, finding bargains is easy and secure.
growth structure guide – Informative tips, planning growth becomes straightforward and achievable.
EverydayTipsOnline – Advice is practical and can be applied without complications.
allianceinsights – Clear and actionable, users can implement partnership frameworks effectively.
Discover Growth Lab – Informative content with actionable tips, makes strategy planning simple.
ExploreMore Click – Playful design, makes browsing enjoyable and keeps visitors curious
globalenterprisealliances – Informative platform, global alliance strategies are explained clearly and practically.
ClickEnterpriseHub – Reliable guidance with explanations that are simple and practical.
ValueCartNetwork – Focused on providing affordable and trustworthy shopping experiences.
trustedbondguide – Informative and practical, businesses can apply commercial bond advice with confidence.
expansioninsights – Clear, actionable frameworks to support sustainable growth.
Business Connections – The information shared here is valuable and helps build meaningful professional links.
grow wisely portal – Helps users evaluate options thoughtfully for steady progress.
ScaleIntelligentlyClick – Helpful content, clarifies complex growth concepts effectively.
FutureReadyNetwork – Focused on preparing users with practical strategies for upcoming challenges.
SmartDiscountClick – Smooth experience, finding bargains is simple and fast.
ClickMoment Online – Clear layout, users can access information without confusion or delay
knowledge expansion click – Insightful resources, grasping new concepts feels simple.
market alliance insights – Helpful tips, shows how alliances work in realistic settings.
corporate confidence network – Emphasizes reliable business interactions, ideal for enterprises seeking long-term alliances.
GrowthGuideClick – Easy-to-follow recommendations that helped me execute growth strategies smoothly.
Market Opportunity Finder – Practical and concise insights, very easy to digest.
value shopping network – Deals are clear, and comparing products is seamless.
ClarityInBusiness – Helps make sense of strategies and operations in a simple way.
strategic business planning site – Reminds users to focus on sustainable growth and long-term objectives.
digitalgrowthguide – Easy-to-follow insights that make executing growth strategies simple.
growthstrategist – Very informative, provides useful tips that are easy to implement.
SmartPremiumShopping – Clear layout, finding and buying products is simple and enjoyable.
focus pathways – Excellent resource, clarifies how to channel work efficiently.
learn more here – Clever setup, it encourages users to wander and explore naturally.
DealFinderClick – Useful guidance, navigation is smooth and content is dependable.
Progressive Commerce – Clear explanations that make innovation feel accessible.
BizTrustLink – Encourages dependable partnerships among corporate entities.
ShopSmartFlex – Flexible design supports personalized online shopping experiences.
SmartRetailClick – Very user-friendly, quickly explains modern online shopping patterns.
click for planning strategies – Informative articles, strategy concepts are clear and simple.
trusted market partnerships – Insightful content, makes alliance concepts relatable and practical.