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.
partnershiphub – Very practical, strategies for professional teamwork are straightforward to use.
RapidShopOnline – Smooth checkout experience, everything feels convenient and user-friendly.
skill growth resources – Helpful advice, site makes professional growth easier to plan.
Idea Discovery Lab – Clear and actionable insights, perfect for applying in real-world situations.
globaldigitalshoppingmarket – Smooth interface, site offers a good overview of digital marketplaces worldwide.
SmartBuyOnline – Clear and practical, online shopping feels quick and effortless.
value-oriented alliances – Focuses on partnerships that create measurable, lasting benefits for all stakeholders.
userfriendlyshopplatform – Very approachable, seems ideal for beginners wanting a smooth ecommerce setup.
future-focused resource – Highlights ways to plan strategically for long-term benefits.
purchasehubonline – Checkout is simple and secure, making shopping convenient.
trustpath – Valuable resource, explains how to develop trustworthy market relationships effectively.
ValueCartOnline – Designed to make online shopping practical and budget-friendly.
InsightfulCareersHub – Provides relevant professional knowledge applicable to everyday work challenges.
ClickForProfessionalInsights – Easy-to-digest lessons that make expert strategies accessible.
engineer your progress – Friendly and natural, illustrating how thoughtful planning creates forward momentum.
browse plavo – Light design and responsive pages, navigation felt effortless
]enterpriseinsights – Informative and easy to understand, the platform breaks down alliance structures effectively.
Product Browsing Hub – Finding and viewing products feels fluid and well-organized.
modern purchase hub – Product categories are clear and easy to move through.
unity partnerships hub – Emphasizes collaboration over rivalry, presenting a clear message of partnership.
ModernRetailBuyingHub – Enjoyed browsing here, ideas are fresh and well explained clearly.
SkillBuilderBusiness – Actionable tips, makes understanding business concepts easy and effective.
safe shopping center – Very trustworthy, ordering feels straightforward and worry-free.
online professional skills – Shows how digital learning makes business education more approachable.
scalinginsights – Guides you with clear, reliable steps for business expansion.
professional knowledge guide – Practical tips for advancing expertise in a digital learning environment.
LongTermBizNetwork – Professional and structured, forming business relationships is straightforward.
clearchoicesguide – Very helpful insights to approach decisions logically and efficiently.
QuickBuyOnline – Prioritizes fast and effortless purchasing in the digital marketplace.
go to site – Clean design, easy navigation, information is straightforward
innovation hub site – Inspires creative thinking and exploration of better solutions.
strategicallianceguide – Clear and concise, long-term alliances are explained in a practical manner.
Worth Checking Out – Stumbled across this and appreciated the tidy design
GlobalTrustRelationshipNetwork – Clean layout and thoughtful content make this site enjoyable today.
NextGen Digital Market – Helps discover products faster while streamlining purchases.
take the first step – Content sparks motivation and lowers the barrier to action.
BudgetDealsCenter – Designed to appeal to shoppers seeking value and affordability online.
corporate partnership space – Designed with shared success and teamwork in mind.
corporateunity – Step-by-step advice for building cohesive, growth-oriented enterprises.
OnlineValueMart – Prices are fair and product descriptions are clear and helpful.
ecofriendlybuyinghub – Focused on sustainability, making online purchasing more responsible and informed.
alliancesprotips – Clear and professional, alliance strategies are easy to implement safely.
MetroShopCorner – Urban emphasis is distinct, highlighting city-focused shopping trends.
reliableonlinecommerce – Safe and reliable, buying products online feels simple and secure today.
EnterpriseGuideOnline – Easy-to-follow content, frameworks are detailed and clearly outlined.
ClearBizSolutions – Very useful tips that helped me focus on the most important areas.
BuyersChoiceOnline – Detailed guidance, made decision-making simple and efficient.
professional relationships made simple – Lessons are concise, networking strategies are practical.
official site – Fast response times, clear sections, and easy to understand layout
strategic alternatives portal – Encourages evaluating different approaches to improve outcomes.