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.

5,100 thoughts on “Stringly Typed Booleans

  1. Thanks for your tips. One thing we’ve noticed is always that banks as well as financial institutions really know the spending behaviors of consumers and as well understand that most people max out and about their own credit cards around the holiday seasons. They sensibly take advantage of that fact and start flooding a person’s inbox along with snail-mail box using hundreds of no interest APR credit card offers shortly after the holiday season finishes. Knowing that when you are like 98 of all American open public, you’ll jump at the one opportunity to consolidate personal credit card debt and shift balances towards 0 interest rates credit cards.

  2. Hiya, I am really glad I have found this info. Nowadays bloggers publish only about gossips and net and this is really irritating. A good web site with exciting content, that’s what I need. Thank you for keeping this website, I will be visiting it. Do you do newsletters? Cant find it.

  3. Thanks for the suggestions about credit repair on this site. Things i would tell people would be to give up this mentality they will buy at this point and pay back later. As being a society we all tend to make this happen for many things. This includes getaways, furniture, and also items we’d like. However, you need to separate a person’s wants from the needs. While you are working to improve your credit score you really have to make some sacrifices. For example you can shop online to save money or you can visit second hand suppliers instead of high-priced department stores intended for clothing.

  4. Эта публикация дает возможность задействовать различные источники информации и представить их в удобной форме. Читатели смогут быстро найти нужные данные и получить ответы на интересующие их вопросы. Мы стремимся к четкости и доступности материала для всех Исследовать вопрос подробнее – https://vivod-iz-zapoya-1.ru/

  5. I have really learned some new things via your site. One other thing I’d like to say is newer computer operating systems are likely to allow far more memory for use, but they furthermore demand more memory simply to work. If someone’s computer could not handle more memory as well as the newest software requires that storage increase, it is usually the time to buy a new Laptop. Thanks

  6. I have noticed that in cameras, special sensors help to {focus|concentrate|maintain focus|target|a**** automatically. These sensors of some surveillance cameras change in in the area of contrast, while others use a beam of infra-red (IR) light, specifically in low light. Higher specification cameras from time to time use a blend of both devices and might have Face Priority AF where the camera can ‘See’ your face while keeping your focus only on that. Many thanks for sharing your notions on this blog.

  7. Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Any way I?ll be subscribing to your augment and even I achievement you access consistently quickly.

  8. 塔尔萨之王第二季高清完整官方版,海外华人可免费观看最新热播剧集。

  9. You actually make it seem so easy with your presentation but I find this matter to be actually something that I think I would never understand. It seems too complex and extremely broad for me. I’m looking forward for your next post, I?ll try to get the hang of it!

  10. Hey, I think your site might be having browser compatibility issues. When I look at your blog site in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, great blog!

  11. Howdy would you mind stating which blog platform you’re working with? I’m going to start my own blog soon but I’m having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique. P.S Sorry for being off-topic but I had to ask!

  12. Накрутка лайков ВК – 25 лучших сервисов советы и бесплатные методы в 2026 году https://vc.ru/1551047

  13. Thank you for another informative website. Where else may just I am getting that type of information written in such a perfect way? I have a project that I’m just now running on, and I have been on the look out for such info.

  14. This is very interesting, You are a very skilled blogger. I’ve joined your rss feed and look forward to seeking more of your great post. Also, I have shared your site in my social networks!

  15. Wonderful goods from you, man. I’ve bear in mind your stuff prior to and you’re just too fantastic. I actually like what you’ve obtained right here, certainly like what you’re stating and the way by which you are saying it. You’re making it enjoyable and you still take care of to stay it smart. I cant wait to learn far more from you. This is really a wonderful web site.

  16. Thank you for another informative blog. Where else could I am getting that kind of information written in such a perfect method? I’ve a mission that I’m just now working on, and I have been at the look out for such info.

  17. I was suggested this blog by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are wonderful! Thanks!

  18. квартира в сочи купить цены жк светский лес цены

  19. I really like what you guys are usually up too. This sort of clever work and coverage! Keep up the fantastic works guys I’ve included you guys to my own blogroll.

  20. fantastic submit, very informative. I’m wondering why the opposite experts of this sector don’t notice this. You must proceed your writing. I am sure, you have a huge readers’ base already!

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>