Stringly Typed Booleans

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.

9,866 thoughts on “Stringly Typed Booleans

  1. One more thing. In my opinion that there are quite a few travel insurance web pages of dependable companies that allow you to enter your trip details to get you the rates. You can also purchase the international travel cover policy on the web by using your credit card. Everything you need to do will be to enter the travel specifics and you can be aware of the plans side-by-side. Merely find the package that suits your allowance and needs and then use your bank credit card to buy them. Travel insurance online is a good way to start looking for a respected company regarding international holiday insurance. Thanks for giving your ideas.

  2. My spouse and I stumbled over here from a different web address and thought I should check things out. I like what I see so i am just following you. Look forward to going over your web page yet again.

  3. Simply want to say your article is as astonishing. The clarity in your post is just cool and i can assume you are an expert on this subject. Fine with your permission allow me to grab your feed to keep updated with forthcoming post. Thanks a million and please keep up the rewarding work.

  4. Thank you for every other wonderful post. Where else may anyone get that kind of information in such an ideal way of writing? I have a presentation subsequent week, and I’m at the search for such info.

  5. Thanks for your publiction. Another element is that just being a photographer involves not only issues in capturing award-winning photographs but also hardships in acquiring the best camera suited to your needs and most especially problems in maintaining the quality of your camera. That is very true and noticeable for those photography lovers that are into capturing the nature’s exciting scenes : the mountains, the particular forests, the actual wild or maybe the seas. Visiting these daring places unquestionably requires a camera that can surpass the wild’s tough environments.

  6. 25 free spins on sign up australia, gambling revenue canada and legal age for gambling in united states, or bet365
    play united statesn roulette online uk

    Here is my web page … eddie’s fabulous 50s casino,
    Rachelle,

  7. I’m not sure why but this site is loading extremely slow for me. Is anyone else having this problem or is it a issue on my end? I’ll check back later and see if the problem still exists.

  8. I’m really inspired together with your writing skills and also with the format on your weblog. Is this a paid subject matter or did you customize it your self? Either way stay up the nice high quality writing, it is rare to see a great weblog like this one these days..

  9. Сам уже несколько месяцев использую накрутку ПФ, но статья всё равно дала новую пищу для размышлений. Особенно понравился раздел про синергию с другими каналами: накрутка снижает стоимость клика в Директе на 20–40%, увеличивает брендовый трафик на 30–100% и ускоряет классическое SEO. Автор также объясняет косвенный эффект на Google — через улучшение внутренних поведенческих факторов. Очень глубокая аналитика. Рекомендую: https://yagla.ru/blog/drugoe-o-marketinge/nakrutka-povedencheskih-faktorov-v-2026–2604u119831/

  10. I?ve learn several just right stuff here. Definitely worth bookmarking for revisiting. I wonder how so much attempt you set to create any such magnificent informative site.

  11. I?ve been exploring for a little bit for any high-quality articles or blog posts on this kind of area . Exploring in Yahoo I at last stumbled upon this web site. Reading this information So i?m happy to convey that I’ve an incredibly good uncanny feeling I discovered exactly what I needed. I most certainly will make sure to don?t forget this web site and give it a glance on a constant basis.

  12. Hey there are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and create my own. Do you require any coding knowledge to make your own blog? Any help would be really appreciated!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>