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.
PathNetwork – Smooth guidance and structured layout make exploring strategies fast.
FirstGuide – Organized design, site makes planning and navigation fast.
CreateFlow – Smooth interface and helpful guidance, exploring concepts feels effortless.
CapitalHub – Smooth layout and helpful guides, exploring resources feels easy and quick.
FocusFlow – Information is laid out clearly, moving around feels effortless.
strategic bonding entry point – The content delivers value without feeling dense.
CorePath – Organized content and actionable guidance keep projects advancing smoothly.
GrowthFlow – Organized content with easy-to-follow instructions makes learning quick.
CreativeAxis – Friendly layout, exploring guides feels quick and intuitive.
AnchorFocus – Well-structured design and helpful hints, learning strategies feels straightforward.
InnovationHub – Friendly tools and clear guides, navigating concepts is simple and fast.
WealthPath – Clear instructions and smooth navigation simplify learning.
VisionPilotPro – Practical guides with intuitive navigation make understanding concepts quick.
IgnitionEdge – Friendly layout, discovering guides is simple and effortless.
BrandFlow – Very practical layout, steps for launching are intuitive and fast.
SecureUnity – User-friendly guides help visitors follow concepts without hassle.
PathFlow – Clear content, site helps users grasp ideas efficiently.
BridgeLine – Clean interface with helpful hints, understanding concepts feels natural today.
TrendMap – Well-structured pages and clear instructions, understanding global trends is straightforward.
PathwayHub – Great collection of content, navigation feels natural and easy.
AnchorSystems – Smooth layout and actionable tips, staying on top of growth tasks is easy.
TrustBridge – Well-laid-out guides help users navigate ideas smoothly.
BrainZone – Well-organized content, site makes learning strategies easy today.
MapVisionPro – Practical guides with clear instructions make understanding effortless.
Vision Organizer – Clean sections help ideas come together quickly.
StrategyNest – Organized content and smooth interface make learning new approaches easy.
CoreAnchor – Well-laid pages with clear tips, navigating resources is fast and easy today.
SecureCore – Well-organized content makes learning strategies easy and intuitive.
capital bond network – Branding aligns well throughout and the content reads smoothly.
ActionFlow – Informative content, site makes completing tasks straightforward and quick.
GridVision – Very easy to use, with tools and guidance that make sense right away.
StrategyNest – Smooth navigation, applying tips and steps feels effortless and quick.
BondHub – Friendly interface with helpful tips, following content is straightforward.
AlignFlow – Balanced design with clear steps, planning and acting is straightforward.
ExecutionBridge – Well-laid menus and clear instructions, applying ideas is smooth and easy.
FocusReference – Clear tips and explanations, very useful overall.
MomentumWave – Easy navigation, understanding concepts and strategies is effortless.
CapitalAxis – Clean design and practical content, learning strategies is fast and simple.
VisionNavigator – Well-structured content, browsing and understanding concepts is effortless.
Progress Path – Clear guides and a tidy structure make learning feel straightforward.
ClarityHub – Clear and practical guides, navigating the site is easy and natural.
MotionSphere – Clear instructions with structured layout simplify finding information.
WealthSynergy – Clear steps and organized design make understanding ideas fast.
MoneyPath – Practical guidance and clear layout make understanding simple.
TrustKeep – Organized interface and helpful tips, navigating content is fast and smooth.
ProgressCompass – Well-structured content, navigating guides feels intuitive and smooth.
MotionAnchor – Clear examples and structured content help understand ideas quickly.
ClarityTrail – Helpful resources, following instructions is effortless and straightforward.
NexusTrack – Well-laid pages and clear instructions, exploring ideas is quick and smooth.
StrategyTrack – Practical content with a layout that makes strategy planning quick.