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.
Updates – Simple layout, smooth navigation, and information is clear and structured.
loryx source – Easy navigation, logical layout, and content flows naturally
financial investment site – Helpful content that doesn’t feel cluttered or confusing.
Bond overview hub – Clean interface, well-organized pages, and accessing content is quick and easy.
GlobalRelationshipPro – Easy to use, networking across countries is smooth and structured.
About Us – Pages are structured logically, providing useful information in a clean layout.
investment services site – Smooth browsing experience with professional presentation.
holdings platform details – Organized design makes it simple to understand the services provided.
Korva Website – Found this by accident, the layout is modern and pleasant to look at
Online bond portal – Easy to move through pages, with a trustworthy tone and clear insights.
Community – Interactive sections are structured clearly, making navigation smooth and easy.
<bond resources portal – Responsive pages, clear structure, and content is easy to scan.
bond services page – Well-organized sections and fast page loading improve usability.
About Us – Simple interface, organized pages, and browsing feels smooth and effortless.
Official site link – Easy to follow structure, clear content, and overall pleasant browsing.
Check it out – Looks like a promising setup, and the site communicates its purpose clearly.
Official xeviro core – Everything is easy to find and the information is presented clearly.
Platform overview – Clean pages, responsive layout, and details are presented clearly.
trust company site – The navigation system is straightforward and responsive.
LearnStrategicallyHub – Easy-to-digest tools, planning strategies becomes straightforward.
Blog – Posts are arranged neatly, making it simple to read and find helpful tips.
Digital trust site – Smooth layout, clear sections, and checking details is easy.
bavlo source – Well-structured content, intuitive navigation, and smooth page flow
Services – Pages load quickly, content is concise, and browsing feels seamless.
bond info hub – Simple layout, easy-to-read content, and well-labeled sections.
ulvarotrust.bond – Very useful site, with a layout that makes browsing simple and efficient.
Home – Clean design, intuitive navigation, and content is easy to understand.
Primary platform link – Smooth navigation, helpful content, and pages are easy to browse.
Financial platform – Fast performance, simple navigation, and content is helpful throughout.
Official xeviro line – Browsing this site was pleasant, and the information is well organized.
trusted bond page – A clean look combined with fast loading makes a solid impression.
BizConnectionsPro – Very structured, helps understand international business dynamics quickly.
Trusted resource – The site appears professional, with content that’s simple and reassuring.
official site – Smooth experience, minimal design, everything works flawlessly
professional bond site – Fast pages and neat structure give a positive impression.
bond investment hub – Clean presentation and strong branding immediately inspire confidence.
Check platform details – Well-laid-out content, simple navigation, and a polished site look.
bond information portal – Navigation is smooth, and information is presented in a readable way.
Official site link – Pages load fast, and information is structured for quick understanding.
professional service portal – Straightforward styling keeps focus on the services provided.
web access – Pages appear instantly, design is clean and easy on the eyes
Official site link – Clean design, content is reliable, and pages are easy to read.
investment hub – Clean design and clear information make the site feel reliable.
bond resources – Smooth experience, information is clear, and pages load quickly.
Explore this website – A smooth experience overall, supported by a neat and professional layout.
Main project page – The site structure is logical, making information easy to locate and understand.
official trust site – Looks professional and gives a trustworthy impression at first glance.
Core overview page – Information is concise, browsing is straightforward, and site feels professional.
handy page – Lightweight interface, quick-loading pages, very clear content
investment guidance site – Pages respond quickly, with organized and readable content.