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.
strategic commerce portal – Branding positions the site as a tool for planning intelligent commercial moves.
BusinessPartnerSolutions – Focuses on aligning organizations through strategic cooperation.
SmoothBuyOnline – Everything works smoothly with minimal effort required.
bizsuccessinsights – Helpful content, actionable business tips are easy to digest and apply.
strategic market alliances – Easy to apply examples, shows how alliances work in real-world business situations.
explore growth portal – Helpful platform, learning about options is easy and engaging.
global commerce network – Concept appears scalable for large, international e-commerce systems.
DigitalShopCenter – Navigation is intuitive and purchasing feels straightforward.
corporate growth alliances – Emphasizes partnerships professionally and makes business objectives clear.
find flexible options – Overall, the variety makes exploring the site enjoyable.
BusinessAllianceNetwork – Useful guidance that supports sustainable growth through alliances.
partnershippathway – Guidance for forming and sustaining enterprise collaborations effectively.
https://unlimboost.com/en/audi/a4/2007-2011/2-0-tdi-143-D0BBD181-3/
online value shop – Offers a reliable shopping experience with reasonably priced items.
futurebizplanner – Inspires thoughtful strategy, perfect for planning growth steps ahead.
fastpurchasecenter – User-friendly and smooth, online shopping is simple and stress-free.
SafeMarketPro – Well-organized site, buying products online feels secure and smooth.
ReliableAlliances – Insights are grounded and useful for maintaining strong partnerships.
VisionaryPlanningLab – Highlights tools for proactive strategy and future-oriented thinking.
trusted network portal – Easy to navigate, global partnership concepts are presented clearly.
guides for quick learning – Helpful and practical, understanding new material feels smooth.
trustedmarketclick – Strong security impression, makes deals feel risk-free.
securecommercialalliances – Feels safe and reliable, guidance on alliances is clear and actionable.
innovation spotlight portal – Great for exploring fresh ideas and fostering innovative thinking.
alliances resource center – Helpful guidance, simplifies understanding of market partnerships.
enterprisemodelguide – Structured and actionable content that makes enterprise frameworks easy to comprehend.
InternationalRetailHub – Smooth, safe platform for purchasing products from different regions.
SteadyBond Central – Clean design, content is easy to locate and navigation is seamless
dealspotteronline – A convenient tool for tracking and finding everyday savings easily.
Professional Growth Space – The guidance is actionable and directly relevant to daily work.
Smart E-Shopping Center – Easy to navigate and full of useful advice for online purchases.
marketrelationshippro – Clear and concise, platform presents market relationship strategies effectively.
future-oriented hub – Encourages looking ahead and considering new directions for growth.
trusted marketplace – Design feels reliable and browsing is effortless.
CustomerHubPortal – Very intuitive platform, makes browsing and buying simple and enjoyable.
ProfessionalOpportunityGuide – Highlights valuable business opportunities for forward-thinking professionals.
online daily store – Provides common necessities efficiently with easy navigation.
NextGenIdeas – Practical ideas presented clearly, perfect for immediate application.
discover growth paths – Informative content, site makes planning long-term strategies simple.
StrategicEdgeHub – Easy-to-understand guidance, strategies are actionable in real scenarios.
BondUnity Resources – Simple interface, visitors can explore content efficiently and with confidence
partnership insights platform – Very actionable, real-world examples illustrate alliance strategies well.
safebuyhub – Projects credibility, makes the experience of online shopping feel secure.
motion guidance – Clear instructions, learning clarity feels actionable and simple.
BondingKnowledgeHub – Practical advice that makes complicated topics more approachable.
ScaleWithClarity – Structured guidance, executing growth strategies is much easier and effective.
valuebuyonline – Smooth and efficient, finding deals is straightforward and convenient.
ethical business partnerships – Branding communicates accountability and sustainable practices in alliances.
BondValue Info Center – Clear pages, navigation feels smooth and content is easy to grasp
Smart Growth Lab – Practical digital growth suggestions that are clearly explained.