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.
Qulavo Flow Express – Fast loading, navigation effortless and shopping process clear and easy.
EasyBond – Product info comprehensive, layout clean, and picking items was effortless.
Zylavo Spot – Interface tidy, navigation logical, and finding products was quick and easy.
xavix source – Modern look, simple navigation, and content that’s easy to explore
Velro Online Market – Pages load smoothly, navigation intuitive and information easy to find.
NaviroTrack Lane Shop – Site works fine, content loads fast and navigation feels intuitive.
resource page – Clear sections, fast-loading pages, content is easy to digest
directionpowersmovement network – Pages are structured well, text is clear, and site performs reliably
retail insights hub – Design and structure align with contemporary shopping behaviors.
ClickXpress – Pages open quickly, interface neat, and browsing feels smooth.
tekvo web – Minimal clutter, structured content, and overall user-friendly experience
xaliro buy – Mobile browsing was smooth, and the categories were easy to follow.
RavionCore Express Hub – Navigation simple, content clear and site layout feels clean and organized.
Kryvox Access – Everything loaded smoothly, navigation clear and content structured well.
Xelarionix Home – Interface loads quickly, navigation simple and product info easy to understand.
xelario hub – Found this store by chance, looks trustworthy and site navigation is easy.
nolra market – Smooth browsing, clear design and easy-to-use category filters.
Leadership Learning Center – Insightful content that broadened my understanding of industry best practices.
Xelra World – Pages responsive, browsing easy and shopping flow feels natural.
Zaviro Online Hub – Pages load quickly, interface clear, and shopping experience feels smooth and reliable.
Trixo Store – Simple interface, browsing seamless and checkout process straightforward.
explore now – Smooth performance, fast pages, and content is concise and easy to read
digital retail platform – Minimalistic and practical, suited for today’s online shopping trends.
actionpowersmovement source – Organized content, minimal clutter, and navigation is easy to follow
retail page – The support team was courteous and easy to communicate with.
axory page – Simple, clean design with organized information and smooth navigation
visit olvra – Smooth navigation, pages are organized and information seems dependable
Morix Zone – Layout neat, browsing straightforward and checkout process works seamlessly.
EasyFlow – Quick access and the content seemed meaningful.
ClickMorixo – Clean interface, well-organized layout, and finding products is effortless.
Rixaro World – Pages opened fast, interface neat and buying process straightforward.
Nevironexus Online Store – Smooth site, content loads quickly and checkout steps simple.
zorivo hub online – Fast-loading pages, navigation smooth and design user-friendly.
International Partnership Space – Great resource for forming cross-border relationships in a well-arranged environment.
Kryvox Store – Pages responsive, layout clean and shopping experience felt effortless.
NevironHome – Pages loaded fast, content informative, and browsing felt smooth and reliable.
start browsing – Lightweight interface, pages open quickly, content is readable
store page – Fresh feel, decent product variety, and ordering was hassle-free.
ideasbecomeforward access – Simple and effective design, fast loading pages, and smooth navigation
Kelvo Main – Pages loaded quickly, navigation intuitive and overall shopping felt effortless.
ReliableDealSource – Smooth experience, deals are listed clearly and checkout feels safe.
NolaroView Hub – Pages opened quickly, layout clear and content easy to follow.
visit olvix – Simple interface, easy-to-read content, and a pleasant browsing experience
nexlo e-store – Pages responsive, ordering process simple and browsing enjoyable.
web shop – Product presentation is tidy, filtering sped up my search today.
Pelix Central – Fast loading, product info clear and overall shopping experience straightforward.
Visit Zylavo – Layout clean, browsing effortless and product details simple to understand.
nolix hub – Simple interface, everything is readable and immediately clear
Korla Home – Pages load quickly, layout clean and checkout process smooth with no issues.
Qulavo Center – Site loads quickly, browsing simple and information easy to find.