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.
BondKeystone Hub – Well-structured pages, making content easy to find and understand
BondTrusty Wealth Center – Professional feel, exploring investment tools is intuitive and quick
Effective Solutions Hub – Professional pages, provides helpful guidance for finding practical ideas
Skill Explorer – Clean interface, helps users build knowledge step by step
City Saver Shop – Smooth experience, browsing products feels organized and reliable
DealSmart Store – Well-structured pages make navigating offers smooth and intuitive
Opportunity Navigator – Informative pages, encourages exploring future paths in a structured way
Buy Simply Hub – Intuitive layout allows quick access to products
Safe Online Market – Clear paths to products and a secure checkout make browsing simple
Quick Help Hub – Simple, organized interface provides useful solutions fast
Trendsetters Online – Clear layout and simple navigation make discovering new styles fun
Effective Strategy Tips – Easy-to-read content, guides users to make better decisions quickly
read full details – Everything is structured in a straightforward way.
Exclusive Shopping Guide – Organized pages and a stylish feel for easy exploration
Professional Networking Hub – Smooth layout, helps users manage and explore business bonds efficiently
Total Shopping Hub – Well-organized layout makes finding items fast and stress-free
Zenith Bargain Spot – Smooth browsing and straightforward product listings
Metro Deals – Organized pages, navigating categories is easy and clear for everyone
TrueBond Online – Simple interface, navigation feels intuitive and easy for users
Strategic Connections Online – Informative pages, helps users navigate partnerships and business growth ideas easily
Daily Progress Guide – Encourages building momentum through simple actions
BondLegacy Directory – Pages are arranged clearly for quick understanding
Quick Picks Hub – Organized layout speeds up product selection and browsing
TrustNex Hub – Clean interface, information is presented clearly and builds user confidence
SmartBuy Portal – Informative pages make it simple to find great offers online
Sustainable Planning Portal – Clear pages, guides visitors through strategic partnership ideas effectively
Explore Ideas Online – Encourages exploring new concepts with clear and engaging content
Trust Strategy Hub – Clear interface, content is credible and browsing resources is effortless overall
Joyful Finds Online – Fun interface allows users to browse items easily and with pleasure
Smart Growth Tips – Encouraging content, supports users in making effective choices quickly
Reliable Partnerships Hub – Intuitive design makes exploring alliances smooth and informative
FastCartPlace – Makes online shopping convenient, simple, and stress-free.
Smart Purchase Center – Intuitive pages provide tips and solutions for routine shopping decisions
Trusted Connections Platform – Organized interface, visitors can explore partnerships and business insights efficiently
Worldwide Online Store – The assortment looks practical for everyday shopping
Everyday Market Hub – Clear structure, supports hassle-free browsing of everyday items
ClickIgnite World – Interactive sections encourage curiosity and keep visitors involved
Strategic Growth Paths – Motivates visitors to take practical steps toward future achievements
explore trust pathway – The site feels professional and inspires confidence quickly.
BondCrest Center – Smooth interface, users can easily navigate and understand content
ClickField Space – Well-arranged content makes learning new ideas effortless
Value Picks Hub – Organized interface allows users to browse and compare easily
Trusted Hub Click – Easy-to-use interface, product categories are clear and navigation is smooth
Info Click Center – Straightforward design makes learning engaging and easy
Future Growth Portal – Clear pages, content makes learning and advancing simple for visitors
EasyBuy Portal – Clear layout and intuitive navigation make finding deals fast and simple
Online Buying Zone – Clean pages, finding items is straightforward and convenient
DealFinder Online – Looks dependable with well-structured product pages
Innovative Retail Center – Modern layout, makes finding items and using platform features simple today
Trustworthy Business Insights – Well-structured sections, site makes learning strategies effortless