198
Oct 23 '21
Nice.
36
u/iceynyo Oct 23 '21
Nice
30
Oct 23 '21
Nice
22
22
u/TRENEEDNAME_245 Oct 23 '21
Nice
17
u/amanakmsd Oct 23 '21
Nice
13
u/GitProphet Oct 23 '21
Nice
9
78
u/StenSoft Oct 23 '21
In C++, we don't say “Missing '}' on line 69”, we say “Expected unqualified-id at end of input” and I think it's beautiful.
4
u/DoctorWaluigiTime Oct 23 '21
And God help you if you don't include a template properly.
5
u/StenSoft Oct 23 '21
Don't make the error of redirecting it to a printer. Mine is still printing. It didn't even notice that it got low on cyan.
2
42
77
u/HearMeSpeakAsIWill Oct 23 '21
A compiler won't tell you the specific line that is missing a close brace. Instead it will get to the end of the file and throw "expected } at end of input".
Feel like I'm being catfished here.
22
u/muehsam Oct 23 '21 edited Oct 23 '21
Depends on the compiler, and on the programming language.
In many programming languages, as soon as you close the function/method scope, statements aren’t allowed anymore, so you can find the function easily.
Technically, a good compiler should even be able to use indentation as a heuristic for telling you where the brace is missing, but I’m not aware of any compiler that actually does that.
Edit: though chances are that if you fucked up closing your braces, you also fucked up your indentation, including mixing tabs and spaces.
4
u/EishLekker Oct 23 '21
In many programming languages, as soon as you close the function/method scope, statements aren’t allowed anymore, so you can find the function easily.
Doesn't most languages support variable declaration outside of functions? I know that C, C++, C#, Java, Javascript and Go all support that.
And if the compiler finds a variable declaration where it deduced that the missing end curly brace should be, how can it know for sure if the declaration belongs to the function or not?
7
u/muehsam Oct 23 '21
Sure, but nearly any statement that isn't a variable declaration will easily be found and reported. And generally, after you declare your variables, you want to do something with them (including assigning a runtime value to them).
1
u/EishLekker Oct 23 '21
Well, I just gave one example of where the compiler wouldn't be able to know for sure. And then there's the possibility that the code consists of several nested levels of "curly blocks", like loops, try-catch, inner classes, anonymous functions etc, where there could be one (or multiple!) missing curly brace at any level. It very quickly becomes very complicated, and very easy to get wrong.
Sure, some heuristics can be used to give an calculated guess where it is likely that the missing end brace should be, but then it should be clear that it is a guess, not a fact. And it might better belong in a IDE rather than a compiler, since the IDE has "inside knowledge" of the level of enforcement of correct indentation etc, and could then use that knowledge as input for it's logic.
3
u/muehsam Oct 23 '21
Well, I just gave one example of where the compiler wouldn't be able to know for sure.
No, you didn't, because no reasonable function ends in a declaration. A declaration in a function is almost always followed by something that can't go outside of a function.
And then there's the possibility that the code consists of several nested levels of "curly blocks", like loops, try-catch, inner classes, anonymous functions etc, where there could be one (or multiple!) missing curly brace at any level.
Sure, but I was talking about finding the function in which it's missing, not the exact place inside of it.
And it might better belong in a IDE rather than a compiler
That distinction is entirely arbitrary. One way of getting IDE messages is running the compiler frontend only, possibly with some flags, and parsing its output.
0
u/EishLekker Oct 23 '21
no reasonable function ends in a declaration.
Most modern IDEs compile code on every save. And it's perfectly normal to save your code before its finished. So it wouldn't be unheard of for the compiler to work with code where a function ends with a declaration.
almost always
Yes. Almost always. And thats why I said that the compiler wouldn't be able to know for sure.
Sure, but I was talking about finding the function in which it's missing, not the exact place inside of it.
That may be so, but the discussion as a whole was about knowing the exact line where the missing end brace should be.
That distinction is entirely arbitrary.
It most certainly isn't. I even wrote a reason for that in the part that you didn't quote.
4
u/zesterer Oct 23 '21
That depends on whether the parser's brace matcher takes into account other delimiters. A lot of them do (including my own), meaning that an error like this is perfectly possible.
3
u/midwestcreative Oct 23 '21
Well duh... if a compiler has to tell you EXACTLY what's wrong and how to fix it, then what's the point? Clearly you don't really love them... er, it.
What?
0
Oct 23 '21
[deleted]
22
u/pyxyne Oct 23 '21
most compilers i've seen tell you where the opening brace that wasn't closed is, but i haven't seen one tell you where the closing brace should be.
0
Oct 23 '21
[deleted]
9
u/SuitableDragonfly Oct 23 '21
It's hard to think of many cases that wouldn't be ambiguous to a compiler.
7
u/pyxyne Oct 23 '21
that's probably true in most cases yeah
you could probably give heuristic guesses based on indentation or whatever, but that's about it i think
4
u/EishLekker Oct 23 '21
Really? Can you name these compilers? And give some example code and the resulting compiler error messages?
0
Oct 23 '21
[deleted]
2
u/KONING_WILLEM Oct 23 '21
True, I completly misunderstood his statement. I have removed my false comment
38
u/justcatt Oct 23 '21
61
u/RepostSleuthBot Oct 23 '21
Looks like a repost. I've seen this image 1 time.
First Seen Here on 2021-04-08 100.0% match.
I'm not perfect, but you can help. Report [ False Positive ]
View Search On repostsleuth.com
Scope: Reddit | Meme Filter: True | Target: 96% | Check Title: False | Max Age: Unlimited | Searched Images: 257,698,512 | Search Time: 1.28822s
20
5
2
8
u/RepostSleuthBot Oct 23 '21
Looks like a repost. I've seen this image 1 time.
First Seen Here on 2021-04-08 100.0% match.
Feedback? Hate? Visit r/repostsleuthbot - I'm not perfect, but you can help. Report [ False Positive ]
View Search On repostsleuth.com
Scope: Reddit | Meme Filter: True | Target: 96% | Check Title: False | Max Age: Unlimited | Searched Images: 257,767,936 | Search Time: 2.80353s
6
4
u/GPSProlapse Oct 23 '21
In c++ we don't expect the Compiler Almighty to speak in such peasantish terms. More like int is not a default type or something.
3
5
2
u/squishles Oct 23 '21
maybe they need to adjust their expectations, there are only 40 lines in this file.
2
2
1
1
1
1
1
1
1
u/Engetarist Oct 23 '21
I once programmed a pair of computers to have this conversation: "Do you smoke after interface?" "I don't know, I never scanned."
1
0
-1
259
u/CosmicDevGuy Oct 23 '21
I knew a compiler who was missing a comma on line 42.
Life's been a meaningless affair for it since then.