If you've looked into how compilers handle the many intermediate steps they perform, it can be obvious. By "can" I mean you wouldn't ever think of it, unless the compiler explicitly tells you "blocks nested too deeply" or similar, something that isn't actually in your code directly, forcing you to actually think about what the compiler sees, like here.
consider that you don't need {} if there's only a single statement. well, an if/else is only a single statement. so, else if requires no additional grammar.
I never thought of this, always considering else if as a separate keyword containing a space character (save for Python's elif), but it makes disturbingly too much sense that it's all just an artifact of brace-less if-else.
i should add that this may not be true in some newer languages, like rust for example. in rust, you CANNOT omit {} for a single statement, but else if is still possible (in the ast, each "if" node may have a corresponding else, which is either another if node (for else if) or a normal block (for else))
another cursed fact: the "omit {}" thing applies to switch (in C/C++, atleast. i didn't check, but it probably doesn't work in java or C#). this is completely legal (and works as you'd expect):
Its not true in lua for example, if, else and else if are only 2 keywords, but that will make you need to write a chain of end end end end end end at the end, so the proper keyword is elseif. I wonder if Lua interpreters handle it "better"?
I did not even know such a limit existed. I probably never encountered it because I'm not insane enough to write code like this. Even if the OP is just meming.
Though I suppose the parse tree would eventually fill up all the memory if you kept doing shit like that.
There's a bunch of really funny limits if you ever want to try to reach them. Some examples include: parameter limits (C standard goes up to 127 I think? 65k (16 bits) in C#), generic type depth limits (65k (16 bits) in C# for example), and some others that are escaping my mind. Gotta remember the compiler is just another piece of code, its gotta also run on your machine
It's not really intuitive because blocks only really exist in two senses: scope, where the else block doesn't meaningfully exist, and where the unconditional branch in the if block goes, where the else block still doesn't meaningfully exist
Fun fact: According to the C99 standard (ISO/IEC 9899:1999) §5.2.4.1 "Translation limits", a correct C compiler only has to support 127 levels of nesting
Well, at least you can write the correct output for all values up to 1984 and for half the values larger than this (up to [2³²/2]-1, I suppose). So, even if it is close to 50% (naive randomness), you can argue that you have an edge above it (by impressive 35*10-8 % !)
I've played with some transpilation that produced a lot of {} and ran into this with clang. Ended up doing some work to reduce the number of {} generated. Thankfully gcc didn't seem to have such arbitrary limits. Computing is better when there's no arbitrary limits. If I've got the RAM for it, let me have as many braces as I want.
15
u/anatomiska_kretsar Sep 18 '26
sigma ibm vga fallback font
41
u/Major-MacZongo Sep 18 '26
Why?
5
u/amsylum Sep 18 '26
Is that Fixedsys? Niceh
165
u/StranglerOfHorses Sep 18 '26
Literally 1984
162
u/Rigamortus2005 Sep 18 '26
Imagine the compiler calling your code too dogshit to compile
12
u/PQP_The_Dev Sep 18 '26
it's over. They got you
7
u/UselessGuy23 Sep 18 '26
Are we not going to talk about the output statements?!
4
u/SteroidSandwich Sep 18 '26
Damn even the compiler had enough
4
u/yuehuang Sep 18 '26
640 nested block ought to be enough for anybody.
4
u/mrheosuper Sep 19 '26
Bro is limited by current technology 😭
1
u/Certain-Flow-0 Sep 18 '26
So, where’s the python code that generates this “monstrosity”?
1
u/KaleidoscopePlusPlus Sep 19 '26
what font is this daddy
3
u/Certain_Time6419 Sep 19 '26
Well, at least you can write the correct output for all values up to 1984 and for half the values larger than this (up to [2³²/2]-1, I suppose). So, even if it is close to 50% (naive randomness), you can argue that you have an edge above it (by impressive 35*10-8 % !)
1
u/DistearRoyl Sep 19 '26
We need to use a compiler with deeper limits.
1
u/questionabl3_dude Sep 21 '26
Someone bless this man with the knowledge of “% 2”
1
u/Kadabrium Sep 21 '26
Apparently its an interview question that when will a compiler get a stackoverflow. Idk if this is one of them
1
u/pskocik Sep 29 '26
I've played with some transpilation that produced a lot of {} and ran into this with clang. Ended up doing some work to reduce the number of {} generated. Thankfully gcc didn't seem to have such arbitrary limits. Computing is better when there's no arbitrary limits. If I've got the RAM for it, let me have as many braces as I want.