M
Mortoray
mortoray.com · Personal blog · on HN since 2012
Mortoray writes about programming language design, covering strings, parsers, exceptions, and the author's own language, Leaf.
What HN saysHN links it for the string type essays and the follow-ups. Commenters mostly cite those posts and discuss boolean parameters in code.
48HN people shared it
12linked it in comments
131stories submitted
2.3Kstory points
10 months agolast shared
2012people per year2026
Most-shared posts
- 1The string type is broken5 people · 321 points · first shared 2013 · 222 comments on HN
- 2Why I don't use a parser generator4 people · 78 points · first shared 2012 · 48 comments on HN
- 3Invented here syndrome3 people · 249 points · first shared 2015 · 51 comments on HN
- 4Nobody cares about your code3 people · 11 points · first shared 2015 · 1 comments on HN
- 5Can a Language be Safe? (2012)3 people · 6 points · first shared 2012 · 5 comments on HN
- 6The Necessity of Exceptions3 people · 5 points · first shared 2012 · discussion on HN
- 7Sadly, I must say goodbye to Leaf, my programming language2 people · 186 points · first shared 2018 · 127 comments on HN
- 8Get rid of those boolean function parameters (2015)2 people · 114 points · first shared 2015 · 114 comments on HN
- 9Wait-free queueing and ultra-low latency logging2 people · 83 points · first shared 2014 · 55 comments on HN
- 10I don’t know how to create a website2 people · 48 points · first shared 2018 · 68 comments on HN
- 11Essential facts about floating point calculations2 people · 46 points · first shared 2015 · 45 comments on HN
- 12We don't need a string type (2013)2 people · 35 points · first shared 2013 · 68 comments on HN
- 13Rejuvenating the ternary conditional with optionals2 people · 9 points · first shared 2013 · discussion on HN
- 14The Internet Lottery for Content Creators2 people · 6 points · first shared 2019 · discussion on HN
- 15Why I’m not a fan of pair programming2 people · 4 points · first shared 2017 · discussion on HN
What HN people wrote when they linked it
BlueTemplar · 2021-02-11
The author has these followup blogposts :
2013 : https://mortoray.com/2013/11/27/the-string-type-is-broken/
2014 : https://mortoray.com/2014/03/17/strings-and-text-are-not-the-same/
(See also : https://thehardcorecoder.com/2014/04/15/data-text-and-strings-oh-my/ )
2016 : https://mortoray.com/2016/04/28/what-is-the-length-of-a-string-a-trick…
infogulch · 2016-02-19
What are you talking about? How is unused imports related to library versioning? And how is focusing on improving build times orthogonal to "building"? The concern with build times is to make building while developing faster [0], how is that related to "releasing"?
Your points are tangential at best, and nonsensical otherwise.
[0]: http://mortoray.com/2015/05/06/fast-build-turnaround-time-is-essential…
mortoray · 2014-03-25
This is a followup to my article "The string type is broken"
http://mortoray.com/2013/11/27/the-string-type-is-broken/
nivertech · 2023-05-15
Mainly, there are 3-4 reasons for considering alternatives to using booleans:
1. Booleans are primitive types without rich domain-specific information or context. When using true/false, it can be more beneficial to employ more descriptive options such as AnsweredYes/AnsweredNo, PositiveResult/NegativeResult, LightsOn/LightsOff, or UserOnline/UserOffline. Mixing and matching booleans of different domain types can lead to errors that the compiler may not catch. For instance:
bool isLightsOn = true;
bool isUserOnline = false;
bool isAdmin = true;
if(isLightsOn && !isUserOnline && !isAdmin)
{
...
}
compare with Elixir:
case
{lights_status, connection_status, user_role} do
{:lights_on, :user_offline, :unprivileged_role} -> ...
...
end
The example above is basically a Decision Table [1].
While booleans can still be used in system code or libraries, it is advisable to avoid them in application code.
2. Preemptive pluralization [2] makes it easier to refactor code. Going from two options to three is simpler than transitioning from one option to two. Consider the following examples:
bool isLightsOn;
or
type LightsStatus = Bool
vs
type LightsStatus = LightsOn | LightsOff
Suppose there is a new requirement to support dimmed lights. In the former case, significant code refactoring is necessary. In the latter case, adding a new option to the sum type is straightforward, and the compiler assists in handling the…
saurik · 2014-03-23
Writing tac in C++ is trivial: std::deque<std::string> lines; for (std::string line; std::getline(std::cin, line); ) lines.push_front(line); for (const auto &line : lines) std::cout << line << std::endl; // Note that I typed this quickly off the top of my head: I'm willing to believe there is a trivial typo the compiler would catch, but the overall implementation should be fine ;P.
As for ohce, you have defined a very very hard problem, one that it does not seem you realize is quite as hard as it actually is: if you have a sequence of Unicode codepoints and reverse their order you do not end up with a string of reversed characters, not in the general case, and not even for some reasonable encodings of seemingly-simple cases like an accented letter e.
Like, I challenge you to provide a working version of ohce in Python (2 or 3: your choice). Virtually no language actually provides a string type that makes this problem reasonable. It simply isn't fair to pick on C++ in this regard when no language "gets this right": at least C++ is being honest about the lack of guarantees it is making about string manipulation.
For more information, I recommend reading this article:
http://mortoray.com/2013/11/27/the-string-type-is-broken/
manx · 2025-09-13
This pre-AI article makes a very similar argument: https://mortoray.com/programming-wont-be-automated-or-it-already-has-b…
Once we realize that what we actually want is turning specifications into software, I think that English will become the base for a new, high level specification language.
leecommamichael · 2024-07-21
Some historic articles on software rendering (the original Bill Atkinson stuff) https://www.folklore.org/Round_Rects_Are_Everywhere.html http://wg20.criticalcodestudies.com/index.php?p=/discussion/80/code-cr…
A modern 3D accelerated article (using SDF as another commenter suspected) https://mortoray.com/quickly-drawing-a-rounded-rectangle-with-a-gl-sha…
Cloudef · 2024-03-20
struct and few functions and you get there. Look at zig's std lib. "String" type is also IMO anti-pattern https://mortoray.com/the-string-type-is-broken/
People often complain about null terminated "strings" in C, but I don't really see them as a problem. It rarely is performance bottleneck, and when it is you can opt for your own "string type". There is also bstring that's compatible with these strings but prepend header to the data which contains the length. That said I wish C had language level slicing.
raesene9 · 2018-06-04
interesting article, although unfortunately it mentions but doesn't currently cover one of the more mis-understood parts of CORS, which is the Access-Control-Allow-Credentials part.
The fact that Access-Control-Allow-Origin: * doesn't work with Access-Control-Allow-Credentials, for example, is something I've seen sites get wrong quite a lot.
there's a good post which covers it https://mortoray.com/2014/04/09/allowing-unlimited-access-with-cors/
higherpurpose · 2014-10-13
I wish COWL went as far as this proposal for domain sandboxing:
http://mortoray.com/2014/09/30/a-secure-and-private-browser-sandbox/
I know Google would never agree to do something like that - unless Mozilla, Apple (the new "privacy" company) and Microsoft (another one pretending to defend user privacy) would put pressure on Google by adopting such a system, together.
zik · 2013-06-02
Writing exception-safe code is non-trivial. There has been a lot of debate recently about whether exceptions are a mis-feature. The main worry is that if you allow exceptions sensible-looking code can lead to many non-obvious bugs. This link gives some insight:
http://stackoverflow.com/questions/1853243/c-do-you-really-write-excep…
Some more reasons why exceptions are problematic:
http://mortoray.com/2012/04/02/everything-wrong-with-exceptions/
Go's choice I think is very well considered. If reliability is important to you then I believe handling errors explicitly leads to clearer, more correct code.
willvarfar · 2016-05-16
In a compiler's intermediate representation, exceptions are typically modeled as multiple returns. E.g. in LLVM the `invoke` op specifies a label to go to if an exception is returned http://llvm.org/docs/LangRef.html#invoke-instruction
By the time this reaches the backend, the exception handling is usually converted into "zero cost" exceptions where raising an exception calls a handler which uses a lookup table to work out how to unwind the stack and what destructors to run etc. Here's a really good explanation I found https://mortoray.com/2013/09/12/the-true-cost-of-zero-cost-exceptions/
This "zero cost" exception handling has no performance penalty on normal CPUs in normal execution as exceptions are exceptional so the conditional call to the handler easy on the branch predicter and the clutter of unwinding doesn't fill the caches.
(Zero cost execption handling appeared first iirc in Metrowerks compilers, but quickly became the standard way on most modern platforms and is now in the ABIs.)
The multiple-return approach may well be much better for total program size.
Whether you can use the multiple-return approach on bare ARM - when the ARM ABI specifies zero cost exception handling - is nothing I know about.