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.

3,105 thoughts on “Stringly Typed Booleans

  1. Aw, this was a really nice post. In idea I would like to put in writing like this additionally ? taking time and precise effort to make a very good article? but what can I say? I procrastinate alot and by no means appear to get one thing done.

  2. Это помогает читателям получить полное представление о сложности и многогранности обсуждаемой темы.

  3. Эта статья – настоящая находка! Она не только содержит обширную информацию, но и организована в простой и логичной структуре. Я благодарен автору за его усилия в создании такого интересного и полезного материала.

  4. Cool blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple tweeks would really make my blog shine. Please let me know where you got your theme. Bless you

  5. Can I just say what a reduction to find someone who actually is aware of what theyre talking about on the internet. You undoubtedly know methods to bring an issue to light and make it important. Extra individuals have to read this and understand this facet of the story. I cant imagine youre not more fashionable because you undoubtedly have the gift.

  6. This article is a refreshing change! The author’s distinctive perspective and perceptive analysis have made this a truly captivating read. I’m appreciative for the effort he has put into creating such an enlightening and thought-provoking piece. Thank you, author, for providing your wisdom and igniting meaningful discussions through your exceptional writing!

  7. Good post. I learn something more challenging on different blogs everyday. It’ll all the time be stimulating to learn content from other writers and practice just a little something from their store. I?d favor to use some with the content on my blog whether you don?t mind. Natually I?ll give you a hyperlink in your internet blog. Thanks for sharing.

  8. Animation Desk is a good alternative to Animate for Android and iOS. This animation app lets you draw on your tablet and convert these drawings into frame animation.  Toon Boom Ember, introduced as a beta test in early spring, is now available as an add-on to users of Storyboard Pro 25 and Harmony 25. These opt-in AI tools allow professional teams to work with fewer interruptions, iterate faster and focus on the creative process. Rather than attempt to replicate the work which artists and animators contribute to a project, Ember’s purpose is to assist. 21 day free trial with Harmony 25. When getting started with this compositing and visual effects software, you’re greeted with a very complex user interface that has many different options and layouts for video creators. Thankfully, everything doesn’t have to be visible and you can navigate through the effects and tools that are necessary for the project.
    https://www.infinitled.com/balloon-by-smartsoft-a-fresh-review-for-indian-players/
    Discover the ultimate destination for timeless fun at The House of Classic Games! Gates of Olympus provides entertaining gameplay spiced up by the bonus rounds, as well as the fiery Zeus hurling thunderbolts at the reels. Just don’t depend on the fickle favour of the gods, and never bet with money you can’t afford to lose. Good Luck! What’s the point? Well, Gates of Olympus free play gives you the chance to try it out before you spend cash. If you’ve never played it before, it can be handy to get some practice. The reel setup here is unconventional, so free-play mode could be a good way to get accustomed to it. Plus, there are a bunch of in-game bonuses that might be useful to practice. What’s the point? Well, Gates of Olympus free play gives you the chance to try it out before you spend cash. If you’ve never played it before, it can be handy to get some practice. The reel setup here is unconventional, so free-play mode could be a good way to get accustomed to it. Plus, there are a bunch of in-game bonuses that might be useful to practice.

  9. It’s a pity you don’t have a donate button! I’d certainly donate to this superb blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this blog with my Facebook group. Talk soon!

  10. Many thanks for this article. I will also like to state that it can be hard when you’re in school and just starting out to establish a long credit ranking. There are many students who are only trying to make it and have a protracted or positive credit history is often a difficult point to have.

  11. I have 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 info So i?m happy to convey that I have an incredibly good uncanny feeling I discovered just what I needed. I most certainly will make sure to don?t forget this site and give it a glance regularly.

  12. Автор статьи представляет разнообразные точки зрения и аргументы, оставляя решение оценки информации читателям.

  13. Thanks for your post. Another point is that to be a photographer consists of not only problems in taking award-winning photographs but also hardships in getting the best photographic camera suited to your requirements and most especially situations in maintaining the standard of your camera. It is very genuine and visible for those photography fans that are in capturing a nature’s exciting scenes : the mountains, the forests, the actual wild or perhaps the seas. Visiting these exciting places absolutely requires a digicam that can surpass the wild’s nasty area.

  14. Thank you for every other informative web site. The place else may I get that kind of info written in such an ideal approach? I’ve a mission that I’m just now operating on, and I’ve been on the look out for such information.

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

  16. I?m not sure where you are getting your information, but great topic. I needs to spend some time learning much more or understanding more. Thanks for wonderful info I was looking for this info for my mission.

  17. Статья предлагает всесторонний обзор фактов и событий, оставляя читателям свободу интерпретации.

  18. There may be noticeably a bundle to find out about this. I assume you made sure nice points in options also.

  19. Thanks for your article. One other thing is that often individual states have their particular laws of which affect property owners, which makes it quite difficult for the our elected representatives to come up with a fresh set of guidelines concerning foreclosure on property owners. The problem is that each state features own laws and regulations which may have impact in an adverse manner with regards to foreclosure guidelines.

  20. I discovered more a new challenge on this weight loss issue. One issue is that good nutrition is very vital while dieting. A huge reduction in bad foods, sugary foodstuff, fried foods, sugary foods, red meat, and whitened flour products could be necessary. Having wastes harmful bacteria, and toxins may prevent ambitions for losing belly fat. While specific drugs for the short term solve the situation, the unpleasant side effects are usually not worth it, and they never offer you more than a temporary solution. It is a known idea that 95 of dietary fads fail. Many thanks for sharing your notions on this weblog.

  21. I would love to add that when you do not currently have an insurance policy otherwise you do not participate in any group insurance, you might well reap the benefits of seeking aid from a health insurance broker. Self-employed or people with medical conditions commonly seek the help of one health insurance specialist. Thanks for your writing.

  22. Hi, i think that i saw you visited my blog so i came to ?return the favor?.I’m attempting to find things to enhance my web site!I suppose its ok to use a few of your ideas!!

  23. I like the helpful info you supply to your articles. I will bookmark your blog and take a look at again right here regularly. I’m slightly sure I will be told many new stuff proper here! Best of luck for the following!

  24. Hi I am so happy I found your blog page, I really found you by error, while I was looking on Yahoo for something else, Anyhow I am here now and would just like to say thank you for a marvelous post and a all round exciting blog (I also love the theme/design), I don’t have time to read through it all at the moment but I have bookmarked it and also included your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the awesome work.

  25. Based on my study, after a foreclosed home is sold at a bidding, it is common to the borrower to still have the remaining balance on the mortgage. There are many loan merchants who try to have all expenses and liens cleared by the following buyer. Nonetheless, depending on a number of programs, restrictions, and state legislation there may be several loans that are not easily resolved through the transfer of financial products. Therefore, the obligation still rests on the debtor that has received his or her property foreclosed on. Thank you for sharing your ideas on this weblog.

  26. Thanks for the posting. My spouse and i have continually observed that most people are eager to lose weight when they wish to show up slim and also attractive. On the other hand, they do not generally realize that there are more benefits so that you can losing weight additionally. Doctors assert that obese people are afflicted by a variety of health conditions that can be instantly attributed to the excess weight. The good thing is that people that are overweight in addition to suffering from different diseases can reduce the severity of the illnesses by way of losing weight. It is possible to see a steady but identifiable improvement with health whenever even a negligible amount of losing weight is attained.

  27. Надеюсь, что эти комментарии добавят ещё больше положительных настроений к информационной статье! Это сообщение отправлено с сайта GoToTop.ee

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>