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.

2,901 thoughts on “Stringly Typed Booleans

  1. Maar het zou natuurlijk geen Stakelogic Live spel zijn als er niet enkele unieke aanpassingen zijn! Wat het spel uniek maakt zijn de multipliers. Achter de roulettetafel zie je een groot scherm waar bij elke draai geheel willekeurig enkele cijfers worden geloot. Er zal minimaal één getal verschijnen en maximaal vijf. Online Casino Nederland > Live casino > Stakelogic Live > Runner Runner Roulette 5000x Casino Middelkerke beschuldigd van Sociale Fraude door ex-werkneemster De beste strategieën om meer te verdienen in Arena of Gold. Pre stake opties in Arena of Gold deze drie documenten worden beschouwd als een van de meest betrouwbare en respectabele in de gokindustrie, Britse ponden. Het belangrijkste voordeel voor het spelen van slots online is het feit dat je kunt spelen op elk gewenst moment en waar u maar wilt, zoals blackjack. Iedereen wil een online casino bonus, roulette en poker.
    https://ojol168.net/review-van-wisdom-of-athena-de-griekse-godin-in-een-spannend-online-slots-avontuur/
    Een van de meest voorkomende zorgen voor spelers die gratis bonussen claimen van goksites zoals Mega Rush Casino is of ze daadwerkelijk echt geld kunnen winnen. Voor spelers is het begrijpelijk, vooral nieuwkomers op het gebied van online gokken, om aan te nemen dat gratis chips, contant geld, of spins kunnen alleen voor de lol worden gebruikt en niet voor winst. Gelukkig, dat is niet het geval bij Mega Rush Casino. Ja, Instant Casino ondersteunt stortingen met verschillende soorten cryptomunten. Kies bijvoorbeeld om in het casino te storten met Ethereum, Ripple, Bitcoin, Tron en Cardano. Het Tumbling mechanisme van het Sugar Rush spel stelt spelers in staat om opeenvolgende winnende clusters te vormen vanuit slechts één enkele cluster. Sugar Casino heeft geen aparte applicatie voor uw mobiele telefoon. De website is namelijk zo ingericht dat u ook op uw smartphone moeiteloos alle spellen kunt spelen. Ook de andere functies van de website zijn heel gebruiksvriendelijk. Het grote voordeel is dat u geen games op uw telefoon hoeft te installeren, wat weer scheelt qua geheugengebruik. Gewoon inloggen in uw browser en gaan met die banaan.

  2. When combined with the Tumble Reels, it becomes clear that these multipliers are key to delivering big wins in the base game. If you land at least four Zeus Scatters, you get an instant cash prize and access to the Bonus Round.The Gates of Olympus slot RTP is set at a pretty solid 96.5%. It’s a high-variance slot so you best be mindful of your bets. When it comes to the maximum payout, you can win up to 5,000x your stake. Forget about paylines and the need for symbols to appear from left to right to activate a win, it gets confusing and frustrating, especially when you’re so close to claiming that big win. The innovative design and unique concept introduces winning combinations anywhere as symbols don’t have to appear consecutively either. Sounds brilliant, right? Let’s explain how it works in our Gates of Olympus slot review. 
    http://www.chinayda.cn/?p=6331
    Impressive animations accompany each bonus feature, with Zeus flying around the game to help you the big prizes. Winning symbols vanish and those above drop down to fill the gaps. This tumbling reels feature carries on as long as new wins are formed. You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page. Gates of Olympus game settings also allow some useful controls such as turning on and off Quick Spin, Battery Saver, Ambient Music, Sound FX, and Intro Screen. Within the settings window, you’ll also have a chance to adjust the total bet and view Game History. But the latter isn’t available when you play the game in demo mode. Gates of Olympus Super Scatter is set up in the clouds, in Zeus’s personal temple, so of course he appears in person. He stands front and center on the grid, while the backdrop is a stormy sky, and Zeus’s palatial home.

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>