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.
FutureStarter – Simple design helps users focus on taking their first steps.
kids support foundation – Wonderful to see, the dedication to children’s needs is inspiring.
MomentumGuide – Well-structured pages provide motivational content and easy-to-follow guidance.
ProgressPath – Motivational and structured layout makes understanding steps simple and effective.
thinking made clear – Information is presented in a clean and steady way.
Idea Compass – Clear structure and practical explanations make understanding straightforward.
Forward Path – Simple structure with practical guidance makes navigation intuitive.
vote for hagins – Clear navigation, website offers transparent campaign information for voters.
mcc theater hub – Polished presentation, project looks meaningful and well-supported.
NuPurple Subscription Plans – Well organized, site makes it simple to understand pricing tiers.
Growth Hub – Structured layout allows readers to quickly grasp and use the ideas.
practical insight hub – Simple, direct information that reinforces staying focused on priorities.
IntentionalGrowth – Thoughtful ideas presented through clean and smooth navigation.
ct campaign portal – Clear and inspiring content, perfect for exploring ideas and initiatives.
PowerUpServices – Concise and accessible pages highlight community opportunities clearly.
Go For It – Keeps the focus on achievable goals and consistent effort.
MomentumTrack – Engaging layout with information explained efficiently.
Momentum Hub – Well-organized content guides visitors toward productive thinking quickly.
n3rd shopping site – Fun to explore, product categories are clear and selection is interesting.
Guided Progress – Structured layout and clear explanations help readers implement concepts quickly.
ideas forward click – Clear structure and fresh insights make this easy to absorb.
astoria together news – Bright and approachable, providing quick updates for everyone in the community.
Ulay Jasa Explore – Clear design, pages load quickly and the content is simple to digest.
Stepwise Progress – Simple navigation and clear layout make ideas easy to grasp.
ActionVision – Professional design with organized content that motivates readers.
transition support hub – Thoughtful content with useful tools for anyone going through a transition.
Step Up – Easy-to-follow design makes learning and browsing simple.
ExecuteIdeas – Motivational and clear, site layout makes inspiration easy to access.
energynear resources – Simple navigation, energy topics are easy to understand.
FocusedGrowth – Organized pages with practical advice for smooth user experience.
Progress Hub – Clean layout and organized content make it easy to follow.
intentional progress – Thoughtful insights shared here, it reads smoothly from start to finish.
Progress Hub – Intuitive layout and practical tips allow visitors to act on ideas efficiently.
flow starts with action – Clear explanation of how action naturally builds momentum.
Philly Saddle Club – Well structured, site presents programs clearly and visitors can explore easily.
Action Map – Clean layout supports efficient understanding of key concepts.
Remi Online – Professional design, content is clearly written and easy to follow.
wellness tour corner hub – Motivating and approachable, navigation is smooth and content is practical.
QuickActionHub – Simple design paired with clear, actionable guidance for all users.
mayce candidate hub – The site feels trustworthy, with a consistent and easy-to-follow message.
ClarityPath – Well-organized content makes learning smooth and easy to follow.
ClarityFocus – Straightforward pages deliver practical tips in an easy-to-read format.
ForwardFlow – Clean interface with concise explanations that are easy to follow.
Results Hub – Practical content and clear navigation allow visitors to apply ideas immediately.
Clarity Signals – Neat design with actionable tips supports quick understanding of key concepts.
latanya updates – Informative site, navigation is intuitive and materials are accessible.
Step Up – The site’s structure allows ideas to be absorbed naturally and easily.
energize your path forward – Practical and motivating, emphasizes taking deliberate steps.
GAP Project Overview – Well organized, site presents the initiative in a clean and accessible way.
momentum activator – Practical concept, focused effort consistently produces progress.