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.
Sunfield Emporium – It was easy to locate items, and the product info was clear and informative.
Thunder Willow Online Store – Great photos with concise, useful descriptions enhance the shopping experience.
Rose Quartz Collection – Items are well chosen, checkout is straightforward and browsing feels simple.
bronze willow corner – Warm and inviting, items look thoughtfully arranged and the site is intuitive.
Pine Harbor Hub – Great variety here, pages load fast and everything is easy to find.
Windstone Emporium – Navigation is effortless, items are easy to locate and the interface feels friendly.
creative gift collection – Easy to browse, lots of unique ideas, and smooth navigation.
The LH Link – Pages load fast, layout is tidy, and reading content is simple.
Wild Lantern Picks – Navigating the site is simple, and everything feels professionally arranged.
Aurora Valley Curated Hub – Natural visuals, store layout makes shopping relaxed and inviting.
CapitalLink – Friendly layout and practical advice make browsing effortless.
Silk Road Online Shop – Found appealing pieces quickly with helpful info provided.
northfield handmade – Smooth browsing, I’ll check back when I need related products.
Timber Echo Emporium – The site is easy to navigate, and the checkout process is straightforward.
Sunforge Retail – Smooth performance and quick navigation make the mobile experience enjoyable.
Visit Wild Lantern Market – Smooth navigation, everything feels structured and trustworthy.
rustandpetal.shop – Easy to navigate, products are clear and descriptions informative and helpful.
Pine Veil Online – Found interesting products, navigation is straightforward and the pages load quickly.
Clarity Click – Well structured, information is easy to follow and highly practical.
bright new online – Cheerful vibe, site is easy to use and gives a welcoming impression.
LH Central – Well-laid-out pages, smooth scrolling, and information is concise.
Silver Reef Finds – The marketplace feels solid and pleasant to explore.
Wild Plum Curated – Easy-to-browse layout with carefully selected items makes shopping pleasant.
TrustLine – Smooth navigation and useful tips help users understand strategies.
Timber Echo Curated – The store is simple to explore, and placing orders is straightforward.
Sunharbor Deals – Smooth layout and dependable presentation make discovering products effortless.
Quiet Orchard Shop – Pleasant layout, items are easy to explore and feel authentic.
SableFern Treasures – Pleasant shop vibe, items seem quality made and browsing was simple.
Success Path – Clean design, reading through the content feels effortless.
The Lifeline Link – Layout looks professional, pages respond quickly, and content is easy to scan.
Wild Shore Picks – Enjoyed the product presentation, the site is smooth and inviting.
Soft Lantern Deals – The gentle layout makes shopping feel enjoyable.
dynamic ideas hub – The concept is energetic and clearly explained, pushing readers to act.
Clarity Resource – Enjoyed the layout, pages are readable and content is very accessible.
Saffron Trail Shop – Lovely selection, browsing was smooth and items are clearly displayed.
Explore Sunharbor Collective – Well-structured and dependable, it’s easy to find what you need.
Velour Valley Official – Calm aesthetic and gentle layout make browsing a pleasant experience.
MoneyFramework – Smooth navigation and easy tips simplify learning.
organized planning resource – Layout and guidance keep goals clear and planning smooth.
Lifespan Connect – Navigation feels intuitive, pages load quickly, and information is clear.
Wild Stone Hub – Simple and efficient layout, finding items is fast and easy.
Soft Lantern Marketplace – A relaxed design approach makes the store enjoyable to explore.
forward-thinking platform – Inspires clarity and action to convert ideas into concrete outcomes.
Momentum Focused – Clear and organized, pages load fast and content is straightforward.
Wild Thistle Market – Pleasant browsing, the website feels polished and items are appealing.
Wild Aura Shop – Easy navigation and tidy layout make exploring items enjoyable.
Sunmist Curated – Calm aesthetic and minimal layout create an enjoyable shopping flow.
dynamic motion hub – Clear steps and priorities make steady advancement simple.
forward drive insights – Encourages sustaining energy levels to maintain constant and effective advancement.
Longterm Hub – Pages are well-organized, navigation is smooth, and content is concise and clear.