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.
explore group site – Well-structured pages with content that’s easy to understand at a glance.
zaviroline online – Straightforward design, fast response times, and helpful info.
krixa network – Clear pages, intuitive navigation and information is well-structured.
this ravioncapital site – Simple and neat, pages load fast and information is well-presented.
zylvo portal – Minimalist design, browsing is straightforward and content is readable.
explore navirobond site – Clear pages and structured navigation make finding information easy.
check this out – Content is easy to follow, and the site has a trustworthy appearance.
this ravioncore hub – Straightforward navigation, content is clear and site feels professional.
visit mavro – Simple interface, content is easy to locate and site feels well-organized.
zavirolinecore link – Smooth experience with content that’s clear and direct.
mivarotrustline network – Layout feels professional, browsing is straightforward and information is accessible.
rixaroholdings resource – Simple, clean design allows quick access to all necessary details.
main nolaroview page – Professional look, simple structure, and easy-to-read sections.
zexarobonding online – Focus is on the information itself thanks to a clean and uncluttered design.
qunix link – Browsed quickly, navigation works well and information is presented clearly.
quvexatrustgroup hub – Site is easy to navigate and gives a professional, trustworthy impression.
vixaroshop storefront – Pleasant experience, products are displayed clearly and browsing is smooth.
kryvoxtrustco experience – Layout is clear, site feels organized and reading information is easy.
check this platform – Quick browse showed a simple structure that’s easy to understand.
capital resource – Quick-loading pages with a fluid interface make the site feel refined.
discover rixva – Minimal design, pages load quickly and browsing is straightforward.
check lixor – Well-organized design and intuitive navigation make everything accessible.
check this out – Clear layout keeps content easy to read and understand immediately.
orvix hub – Stumbled upon this site, pages are intuitive and simple to browse.
pexra hub – Layout is neat, browsing is simple and content is easy to access.
official capital page – Browsed this by chance, but the information was presented in a way that kept me engaged.
core resource – Nothing feels cluttered and navigation works smoothly.
Quixo style – Sleek and minimalistic design keeps everything clear.
Shop Aurora – The site has a fresh vibe with plenty of interesting finds.
Top quality shop – Smooth navigation and a variety of premium items.
BrightBargain – Fantastic deals, I find amazing products every time I visit.
charmcartel.shop – Unique designs and fast navigation, love shopping here every time.
coffeecourtyard.shop – Great selection of coffee beans and accessories, always a fun find.
crispcollective.shop – A well-curated collection of modern products with a streamlined shopping experience.
driftden.shop – Love the easy-going atmosphere and the variety of products.
charmchoice.shop – Fun and creative collection of charms, it’s hard to leave without buying something!
firfinesse.shop – An amazing collection of luxurious products, with an elegant touch that’s hard to beat.
explore plorix hub – Navigation is simple, pages load fast and important information is easy to locate.
glintaro.shop – Always something new and exciting to discover here, love browsing through the collection.
this holdings site – Pages are well-structured, and the information reads smoothly.
zavirobondgroup access – Pleasant design, content is readable and pages are easy to move through.
Birch Bounty collection – Natural and fresh products, easy to explore and shop.
Aurora deals – Wide selection of items and effortless browsing.
Cool shop link – Nicely laid out with plenty of unique items to check out.
BrightBargain picks – Incredible bargains, I’m always impressed by the selection.
zexaroline – Found this through a link, stayed longer because layout works.
charmcartel.shop – Gorgeous accessories and great site design, very simple to shop.
collarcove.shop – Great variety of stylish collars, easy and fun shopping experience.
crispcrate.shop – Great variety of high-quality products, and the site is very user-friendly.
fixforge.shop – Your go-to shop for DIY projects, offering an excellent selection of tools and equipment.