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.
SavvyDealsHub – Focuses on affordability and convenience for online buyers.
safe retail platform – Looks credible and professional, perfect for repeat buying.
Build Smart Lab – Insightful and practical, made evaluating options straightforward.
SecureEshopNetwork – Interface clarity makes shopping efficient and reliable.
ClickMarketTips – Content is concise, clear, and provided valuable perspectives.
TopBuyHub – Easy layout, content helps make informed purchase decisions quickly.
trusted commercial network – Emphasis on safe dealings makes collaboration feel reliable.
global bonds guide – Helpful breakdown of concepts makes enterprise bonds easy to understand.
Business Growth Reads – Useful content that broadened my understanding of possible paths.
digital buying platform – Great experience, online shopping is seamless and straightforward.
unity planning tips – Content is actionable, forming alliances feels smooth and clear.
main hub – Light layout, organized sections, very easy to navigate
valuebuyscenter – Smooth and practical, platform presents shopping deals efficiently.
SmartDiscountHub – Smooth and clear, online deals are easy to find and purchase.
ClickRetailFuture – Practical insights that make tracking retail developments easy.
explorebusinessopportunities – Insightful resources, finding business opportunities feels easy and practical here.
SafeBizConnect – Platform feels secure and dependable, ideal for online business dealings.
verifiedshoppinghub – Appears professional and safe, ideal for secure e-commerce experiences.
insightfulpros – Practical and actionable, expert content is easy to implement quickly.
learning advancement site – Practical and approachable for slowly building professional skills.
Business Opportunities Lab – Smooth browsing, helpful insights make decision-making easier.
ClickGlobalConnections – Very useful resource for connecting with professionals worldwide.
global retail portal – Feels oriented to international buying trends and preferences.
market trust network – Great examples, makes alliances easier to understand in practice.
BusinessAllianceHub – Focused on creating reliable corporate alliances and cooperative networks.
ClickForBusinessAlliance – Very practical, site makes learning about global collaboration smooth.
Business Alliance Insights – Offers advice on creating dependable partnerships and networking successfully.
ClarityForEntrepreneurs – Helped me see opportunities and plan more confidently.
featured link – Snappy load times and a simple presentation stood out
SmartSavingsCart – Highlights smart and value-focused shopping experiences.
strategic framework hub – Concepts are presented in a structured way, supporting clear understanding.
nextlevel shopping hub – Excellent flow, finding and purchasing items is hassle-free.
partnershipstrategies – Helpful and structured, corporate alliances are made easy to understand.
global partnership site – Promotes cooperative ventures for multinational enterprises.
TrustedDealsHub – Well-structured platform, buying products is easy and safe.
ValueAllianceAcademy – Useful insights, helps make alliance planning simple and actionable.
Автор использует ясные и доступные примеры, чтобы проиллюстрировать свои аргументы.
ClickToStrategize – Made planning and decision-making much simpler and effective.
next business ideas – Invites entrepreneurs to seek out innovative and profitable opportunities.
GlobalDigitalShoppingMarket – Really useful site, content feels practical and easy to navigate.
learnfrombusinessleaders – Clear and actionable, market leader insights are practical for real-world use.
corporate relationship portal – Strong tone and branding suggest reliable business connections.
CorporateGrowthLinks – Emphasizes durable corporate relationships that foster long-term opportunities.
UrbanShopZone – Very enjoyable to explore, provides product info and choices clearly.
certified buying platform – Branding conveys security and trustworthy transactions.
momentum unleashed – Friendly, natural language showing how energy focused into traction drives forward action.
business model hub – Clear layout and well-explained sections make business concepts approachable.
useful resource – Fast navigation, headings are clear and content is helpful
Consumer Buying Center – Simplifies online shopping with practical guidance and tips.
handy page – Clear pages, quick navigation, content is informative and easy to read