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.

13,489 thoughts on “Stringly Typed Booleans

  1. I am regular reader, how are you everybody? This paragraph posted at
    this web page is actually fastidious.

  2. Polishing your resume matters but the real key is knowing where to look. On our site you can set up your application with no hassle and right away you can find see more here based on your field and your city which makes your search a whole lot faster and more accurate.

  3. free slots australia online, canada does legalized gambling increase crime (Dani) bill and jackpot pokies canada,
    or bingo uk online

  4. Thanks for the helpful posting. It is also my belief that mesothelioma cancer has an really long latency time, which means that warning signs of the disease might not exactly emerge until finally 30 to 50 years after the primary exposure to asbestos. Pleural mesothelioma, which can be the most common form and is affecting the area about the lungs, will cause shortness of breath, upper body pains, including a persistent coughing, which may lead to coughing up body.

  5. Hi mates, its wonderful piece of writing on the topic of teachingand entirely defined, keep it up all the time.

  6. Woah! I’m really loving the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between usability and visual appeal. I must say you’ve done a awesome job with this. Also, the blog loads very fast for me on Firefox. Exceptional Blog!

  7. Thanks for the ideas you have provided here. In addition, I believe usually there are some factors that will keep your auto insurance premium all the way down. One is, to think about buying vehicles that are in the good list of car insurance corporations. Cars which have been expensive are usually more at risk of being robbed. Aside from that insurance policies are also in line with the value of your car or truck, so the more expensive it is, then higher your premium you make payment for.

  8. pokies online australia reviews, casino new south wales united states and
    australian poker machine online, or best online pokies free spins
    no deposit canada

    My webpage: huge casinos (Kaley)

  9. usa free spins no money deposit, european roulette hints
    uk and online gambling united states poker, or free spins goukos quest

    My web site; how to play blackjack uno (Ara)

  10. OMT’ѕ exclusive educational program introduces fun obstacles tһat mirror test
    questions, sparking love fߋr math annd the motivation to do remarkably.

    Join ߋur smaⅼl-grߋup on-site classes in Singapore fօr personalized assistance іn a nurturing
    environment that develops strong foundational math abilities.

    Ꮤith math incorporated flawlessly іnto Singapore’s classroom settings tо benefit bߋth teachers ɑnd students, dedicated math tuition magnifies tһeѕe gains Ьy providing customized support fоr continual
    accomplishment.

    Math tuition helps primary students master PSLE ƅy enhancing tһe Singapore Math curriculum’s bar modeling strategy fоr visual analytical.

    Detеrmining and rectifying specific weak ⲣoints, ⅼike in likelihood or coordinate geometry,
    mɑkes secondary tuition indispensable fⲟr O Level quality.

    Tuition integrates pure ɑnd uѕеd mathematics effortlessly,
    preparing trainees fⲟr the interdisciplinary nature ᧐f A Level troubles.

    OMT’ѕ exclusive mathematics program complements MOE criteria
    Ƅy emphasizing conceptual mastery οver rote knowing, causing mᥙch deeper lօng-term retention.

    OMT’s ѕystem is mobile-friendly ᧐ne, so study οn the mօᴠe and see your math grades boost
    witһout missing oᥙt on ɑ beat.

    Math tuition assists Singapore pupils ɡet over usual pitfalls іn computations, causing
    ⅼess negligent mistakes in examinations.

  11. One thing I would like to say is the fact car insurance cancelling is a terrifying experience so if you’re doing the best things like a driver you may not get one. A number of people do are sent the notice that they’ve been officially dumped by the insurance company they then have to scramble to get more insurance after having a cancellation. Cheap auto insurance rates are usually hard to get from cancellation. Having the main reasons for auto insurance cancellations can help car owners prevent losing one of the most crucial privileges readily available. Thanks for the concepts shared through your blog.

  12. One other issue issue is that video games are typically serious in nature with the key focus on finding out rather than fun. Although, there is an entertainment element to keep your young ones engaged, every game is usually designed to work with a specific experience or program, such as numbers or scientific discipline. Thanks for your posting.

  13. I loved as much as you’ll receive carried out right here.
    The sketch is attractive, your authored material stylish.
    nonetheless, you command get got an edginess over that you wish
    be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly very often inside case you shield this hike.

  14. OMT’s neighborhood online forums аllow peer motivation, wһere shared
    mathematics understandings trigger love аnd collective drive fߋr
    test excellence.

    Join ߋur smаll-groᥙp on-site classes in Singapore fⲟr tailored assistance іn ɑ nurturing environment that constructs strong fundamental
    math abilities.

    Ꭺѕ mathematics underpins Singapore’ѕ reputation for quality in worldwide standards liҝe PISA,
    math tuition is essential to unlocking a child’ѕ prospective аnd protecting scholastic advantages
    іn this core subject.

    Math tuition assists primary students master PSLE ƅү
    strengthening tthe Singapore Math curriculum’s bar
    modeling technique fⲟr visual рroblem-solving.

    In-depth responses fгom tuition trainers ߋn method attempts assists secondary students gain fгom blunders, enhancing accuracy ffor tһe actual Օ Levels.

    Tuition teaches mistake evaluation methods, assisting junior college pupils аvoid common challenges in A Level estimations and proofs.

    Ԝhat collections OMT ɑpɑrt is itѕ custom curriculum tһɑt aligns with MOE while offering flexible pacing, allowing sophisticated pupils to᧐ accelerate their knowing.

    Recorded webinars provide deep dives lah, outfitting уⲟu witһ innovative skills for exceptional math marks.

    Ꮤith math Ьeing a core topic that influences ɡeneral scholastic streaming, tuition helps Singapore students secure fɑr better
    qualities аnd brighter future possibilities.

    my web-site … secondary 3 math tuition

  15. I’ve read several excellent stuff here. Certainly worth bookmarking for revisiting.
    I surprise how much effort you place to make any such great informative website.

  16. Having read this I believed it was really informative. I appreciate you taking the
    time and effort to put this content together. I once again find myself
    spending a significant amount of time both reading and posting comments.
    But so what, it was still worthwhile!

  17. Hey there this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors
    or if you have to manually code with HTML. I’m starting a
    blog soon but have no coding skills so I wanted to
    get advice from someone with experience. Any help would be greatly appreciated!

  18. Hey I know this is off topic but I was wondering
    if you knew of any widgets I could add to my blog that automatically tweet
    my newest twitter updates. I’ve been looking for a plug-in like this for quite some
    time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and I
    look forward to your new updates.

  19. KKWin là nền tảng giải trí trực tuyến đẳng
    cấp, chuyên cung cấp các dịch vụ cá cược đa dạng từ
    Thể thao, Casino trực tuyến đến Nổ hũ và Xổ số.
    Với phương châm đặt trải nghiệm khách hàng lên hàng đầu, KKWin cam kết mang đến một môi trường cá cược minh bạch, hệ thống bảo mật tuyệt đối cùng tốc độ
    nạp rút siêu tốc, khẳng định vị thế nhà cái uy
    tín hàng đầu thị trường hiện nay.

  20. I know this web page provides quality depending articles or reviews and
    extra information, is there any other web page which provides
    these data in quality?

  21. you’re really a good webmaster. The web site loading speed is incredible.
    It seems that you are doing any distinctive trick. Moreover, The contents are masterpiece.
    you have performed a magnificent task on this matter!

  22. What’s Taking place i am new to this, I stumbled upon this I’ve found It absolutely helpful and it has helped
    me out loads. I hope to contribute & aid different customers like its helped me.
    Great job.

  23. Menurut saya, bermain slots online dapat menjadi opsi kesenangan yang memikat lantaran tersedia obyek
    permainan yang berlainan. Dengan opsi game yang banyak ragam, pemain bisa nikmati pengalaman yang tak
    monoton.

  24. My spouse and I absolutely love your blog and find a lot of your post’s to be exactly what I’m looking for.
    can you offer guest writers to write content for you?
    I wouldn’t mind producing a post or elaborating
    on many of the subjects you write regarding here. Again, awesome web site!

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>