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.
growthinsightguide – Guidance provides clarity and ensures steady progress.
TrustedLeaderConnect – Clean design, content conveys focus and professionalism seamlessly.
planpilot – Properly directed motion ensures tasks are completed efficiently.
HeritageUnityHub – Well-laid-out tutorials, I found exactly the tips I was looking for.
ProfessionalUnityCircle – Clear and professional, ideas are presented effectively.
BondedStrengthCircle – Excellent explanations, I absorbed practical advice immediately.
SharedCapitalGuide – Very approachable guides, makes understanding bonds easy for beginners.
TrustPathNetwork – Helpful tutorials with practical advice, everything was easy to follow.
CoreEverResources – Well-organized articles and practical advice, grasping bonds was effortless.
I value the intuitive UI and fast transactions. This site is reliable.
BondSecureCircle – Fast-loading pages with structured content that’s simple to navigate.
GrowthBondNetwork – Logical flow, content provides clear strategies worth revisiting.
CapitalTrust Help – Easy-to-follow instructions and useful tips help users succeed.
trustedcircle – Strong positioning, relationships feel dependable and sincere.
BondedStrategyNetwork – Helpful guides and step-by-step tutorials, I absorbed several important points.
BondedValueHub – Very clear layout, guides make understanding bond strategies quick and easy.
GlobalGrowthHub – Well-organized, inspires forward momentum and ambition.
GlobalSharedBond – Minimalist and clear, content feels accessible and easy to follow.
AlliedBondNetwork – Informative guides with actionable tips, really boosted my knowledge today.
VisionPortalBonded – Crisp design, explanations are practical and simple to follow.
BondedUnity – Simple navigation and helpful tips, I could follow the lessons without confusion.
FocusedVisionHub – Practical and engaging, articles make understanding finance less intimidating.
Capital Unity Insights – Smooth interface with practical advice for everyday use.
CapitalFocus – Content is well organized, easy to follow, and highly actionable.
actionpilot – Taking steady steps helps turn concepts into reality faster.
Stability Bond Learning Hub – Stepwise guides and smooth interface make mastering topics straightforward.
CapitalInsightPortal – Very well-structured guides, I quickly understood multiple practical points.
AllianceResources – Helpful tips and insights, I always discover something valuable.
MutualBondHub – Tutorials are practical and concise, content is clear and very useful.
BusinessLinkNetwork – Simple design, messaging is clear and focused.
LongTermPartnerLinks – Quick navigation, guides me through key ideas without confusion.
NexusBondPortal – Clear layout, guides are actionable and very useful for beginners.
AllianceGlobalHub – Organized and clear, complex ideas are broken down very effectively.
ProsperityHub – Excellent guidance and tips, I quickly learned several important strategies.
UnityPrimeResources – Tutorials are direct and simple, perfect for quick reference.
bondedalliance – Well-presented concept, strategic partnerships are easy to grasp.
CollectiveTrust Insights – Concise, well-organized content made understanding concepts effortless.
PrimeCapital Learning – Logical navigation and clear content support quick understanding.
TrustedHarborResource – Helpful examples and tutorials, everything is structured logically.
PillarCore – Guides are straightforward and practical, very easy to absorb.
UnityPathLink – Easy-to-understand content, I quickly found helpful strategies.
EverTrust Guides – Well-laid-out resources with practical insights make learning fast.
GrowthCircleLink – Clean and concise, messaging comes across confidently and clearly.
Summit Trust Hub – Well-structured layout and practical guides make learning simple today.
GlobalAllianceTrust – Welcoming and organized, tips are consistently valuable.
BCPartnersHub – Well-organized resources, I discovered valuable insights in minutes.
UnityBridgeCenter – Clear and concise guidance, makes applying lessons easy.
FlowGroup Essentials – Practical resources that are friendly, informative, and easy to navigate.
bondedalliancehub.bond – Well-laid-out content makes understanding complex topics much easier.
BondSolidNetwork – Fast-loading resources with clear explanations make learning smooth.