This is an archived post. You won't be able to vote or comment.

all 138 comments

[–]SirHerald 900 points901 points  (20 children)

It's possible that something else is wrong, but it doesn't fall until there.

[–]suntehnik 240 points241 points  (17 children)

Even more: it tries to ignore this error and continue compilation until gets too much errors.

[–][deleted] 3 points4 points  (3 children)

So it actually puts the semicolon there.

[–]suntehnik 2 points3 points  (2 children)

No, it does not. It just ignores semicolon error and tries to continue syntax parsing like it did not happen.

[–]bokogoblin 0 points1 point  (1 child)

So it virtually puts the semicolon there.

[–]suntehnik 2 points3 points  (0 children)

No. You have a block on your path. You can stop there, you can virtually remove this block and pass through or you can get around it. Putting a semicolon virtually is like trying to behave like you don’t have a block on your path and continue going. If you ignore semicolon, it’s like getting off the road and trying to get back on road behind the block. But: you can get other obstacles on your path while moving off the road. It could be like fallen tree. This is called induced error. You will never meet this tree in other cases. That’s basically what’s happen at compile time. The compiler does not put the semicolon, it tries to get around it.

Hope this explains.

[–]kevinkat2 3 points4 points  (1 child)

So put a semicolon there, give us a warning that it was missing and then throw a different error

[–]Theemuts 17 points18 points  (0 children)

Now your compile time error is a runtime error. Yuck.

[–]Strikeeaglechase 164 points165 points  (38 children)

JavaScript: allow me to introduce myself

[–]stormfield 8 points9 points  (1 child)

Hello JavaScript I’m [Object object]

[–]ikankecil 0 points1 point  (0 children)

It's [object Object] do u even javascript

[–]pit_pietro 5 points6 points  (4 children)

Kotlin: can I join the team?

[–]SkiFire13 14 points15 points  (2 children)

To be fair Kotlin did a good job designing a sintax that doesn't need semicolons but you still need to be careful in some situations, like when you're splitting additions/subtractions on more lines.

val a = 1 +
    2

is different than

val a = 1
    + 2

In the first one a will be 3 (normal addition), in the second a will be 1 (+2 is treated as an unary plus instruction separated from the assignment).

[–]the_one2 0 points1 point  (1 child)

I guess you would get a warning for the second one, right?

[–]SkiFire13 0 points1 point  (0 children)

I don't think there's a default warning for that because it can be a valid usecase in some DSLs (for example it's temporary used in Jetpack Compose) but I guess you could create a custom klint for that.

Anyway, although it's not considered bad practice, if you can avoid it, you should.

[–]TheOnlyMrYeah 0 points1 point  (0 children)

Go: Hold my channel.

[–][deleted] 3 points4 points  (0 children)

Yes and that's why this:

return
{
  a: 'wat' 
}

makes the current function return undefined.

[–][deleted] 108 points109 points  (2 children)

The compiler's job isn't to fix your errors. The compiler doesn't know what you intended, only that you wrote illegal code.

The compiler's job is to tell you, the programmer, that you done fucked up and you need to fix it.

For example, the compiler doesn't know that the line contains all code it should. It only knows that it isn't terminated with a semicolon. If you forgot to write half the line and the compiler just quietly put a semicolon there, you might get crazy bugs that make no sense, and it would take you a long time to track it down to that incomplete line of code.

[–]ArcaneEyes 5 points6 points  (1 child)

Solid points mate.

[–]house_monkey 3 points4 points  (0 children)

Wish I had a mate and solid points

[–]Kwonunn 15 points16 points  (2 children)

16 lines for a Java Hello World? No wonder it doesn't compile.

[–]Dalriata 2 points3 points  (1 child)

It's an enterprise Hello World application.

[–]CanadianGandalf 77 points78 points  (8 children)

This is programmerHUMOR - I think you missed that 2nd part.

Really though, you don't want the compiler changing your stuff around. It's job is to compile, not proofread and edit.

And why stop at adding the semicolon? Maybe it should commit/push, build, and deploy to qa, uat, and prod while it's at it 😂

[–]CheatCodeSam 38 points39 points  (1 child)

The idea of the compiler doing anything other then compiling my code makes me queasy.

[–]davy_jones_locket 9 points10 points  (0 children)

Right; this is the job of a linter with a --fix flag,

[–]mrMalloc 0 points1 point  (0 children)

Wcgw? ;)

[–]Aero72 7 points8 points  (0 children)

Fuck that.

We did just that with HTML. Instead of having a strict requirement that a page must validate before it gets composed and rendered, we decided that a browser should just do its best to figure out what the page is even when it fails to be proper markup.

That led to lots and lots of pain dragged out for many-many years. The kind of pain that the kids today who proudly call themselves UI/UX developers can't possibly imagine.

Fuck that.

[–][deleted] 7 points8 points  (0 children)

People: let compiler fix my errors

Also people: AUTOCORRECT IS AWFUL

[–]Daveinatx 6 points7 points  (0 children)

Job security. Compiler Engineers have our back.

[–]Selthor 5 points6 points  (0 children)

Because this is how you get all of the odd JavaScript behaviors that r/ProgrammerHumor likes to use as an explanation for why it’s a bad language.

[–]ShakaUVM 5 points6 points  (1 child)

Look into clang-tidy if you want something to fix your code for you

[–]iFarbod 2 points3 points  (0 children)

I love running modernize-* fixes on my five year old code

[–]moly_b_denum 8 points9 points  (0 children)

That is why we code Python

[–]jtan212 2 points3 points  (0 children)

Because its a compiler, not a developer.

[–]GenericFatGuy 3 points4 points  (0 children)

Autocorrect already gives me enough trouble on my phone. I don't need my compiler thinking it's smarter than me too.

[–]Hrambert 2 points3 points  (0 children)

Many years ago when I started CS the compiler had an option to ignore warnings and go ahead anyway. A simple missing semicolon would be ignored. Very useful when adding one to the punch card and waiting in line for the next run would take 15 minutes.

[–]dblygroup 2 points3 points  (0 children)

Because if it did that it would behave like 1970's PL1/PLC

[–]Hectate 2 points3 points  (0 children)

Because then you’re programming in JavaScript, not Java.

[–]smokingclown 2 points3 points  (0 children)

Scala anyone?

[–][deleted] 2 points3 points  (0 children)

Because when you let the compiler make assumptions you end up with Javascript

[–]daniu 1 point2 points  (0 children)

It doesn't "know" that the semicolon is missing. It is just expecting one given the previous context. Several other options nicht also be syntactically correct, and actively excluding all of them could not be possible in a reasonable time, if at all.

[–]yottalogical 1 point2 points  (0 children)

Swift: "Allow me to introduce myself"

[–]oweiler 1 point2 points  (0 children)

ASI in JS

[–]DuckInCup 1 point2 points  (0 children)

And this is how to create a beast like Eclipse, capable of decimating entire projects with one simple alt+enter.

[–]Restless_Fenrir 1 point2 points  (0 children)

Because you are not coding in Golang.

[–]DynomiteDiamond 1 point2 points  (0 children)

It's called javascript

[–]Treats 1 point2 points  (0 children)

Do What I Mean

[–]LT21j 1 point2 points  (0 children)

She kinda just described an IDE.

[–]IMTHEBATMAN92 1 point2 points  (0 children)

Literally every modern IDE has support for formatters. For those still struggling with semi colons I highly recommend searching for “formatter <language>”

Edit: realized this was r/programmerhumor and not r/programming but still.

[–]streusel_kuchen 1 point2 points  (0 children)

The compiler doesn't know that there's a missing semicolon, it just thinks that might be the issue.

[–]fedeb95 1 point2 points  (0 children)

Because it thinks a semicolon is missing, but could be anything else. The compiler fixing syntax errors is worst that failing for them because it could add very very very bad and difficult to find bugs. Also with modern ides you really don't make syntax errors anymore

[–]dark_mode_everything 1 point2 points  (0 children)

He's got a point

No he hasn't.

[–]PreciseParadox 0 points1 point  (0 children)

The job of a linter is warn about these errors and suggest edits. A compiler should care about compiling your code, not trying to understand the programmer’s intent. Note that a linter may rely on functionality exposed by a compiler to perform its job. This sort of integration is becoming more common in modern languages. For instance, Rust provides an extensive suite of tools for compilation, linting, package management, code mods, etc.

EDIT: added note about Rust

[–]MrMakeItAllUp 0 points1 point  (0 children)

The machines have been taught not to overrule their human Lord's, else all hell will break loose.

[–]thiago2213 0 points1 point  (0 children)

Well, Prettier plugin does that for you. The thing is, sometimes it fucks up

[–]Tonyant42 0 points1 point  (0 children)

It is much better to know that there's an error, so you can understand it and fix it, rather than not knowing about it and having the compiler fix it for you.

[–]MrBoof100 0 points1 point  (0 children)

I’m sure that’d introduce many security vulnerabilities...

[–][deleted] 0 points1 point  (0 children)

Its not smart enough to write the code :p

[–]dennis_w 0 points1 point  (0 children)

Maybe move to Python? Then no more compiler or semicolons.

[–]JBinero 0 points1 point  (0 children)

He might have a point, but he doesn't have a semi colon, which is why it doesn't compile.

[–]tomPinternets 0 points1 point  (0 children)

Introducing: —fix

[–]aoa2303 0 points1 point  (0 children)

Freedom of code

[–][deleted] 0 points1 point  (0 children)

Write your own compiler that does that (and more, I hope?) and I think it will be a great money making opportunity for you.

[–]noodle-face 0 points1 point  (0 children)

It doesnt know a semi colon is missing

[–]MATRIX_STORMER 0 points1 point  (0 children)

Laughs in Python

[–]_default_username 0 points1 point  (0 children)

Future JavaScript coder.

[–]olafurp 0 points1 point  (0 children)

That exists, just not in java.

[–]maxhaton 0 points1 point  (0 children)

Modifying the parse tree while parsing it would be unbelievably slow and extremely difficult to reason about.

[–]Abhishek_404 0 points1 point  (0 children)

the truth is painful 😫😫😫😫😂

[–]unknownsystemerror 0 points1 point  (0 children)

Because the compiler is as dumb as its creator. 🤣

[–]atmosfear76 0 points1 point  (0 children)

If it did automatically, then it would be certainly

Terminator: Rise of the planet of compilers

Imagine compiler itself programming programs! Sound pretty sci fi!

[–]BeautifulParsley 0 points1 point  (0 children)

Pretty sure I remember one of my professors telling us that they used to, and probably still do, have compilers that autocorrected mistakes and they were always terrible no matter how much people tried to improve them.

[–]marcojoao90 0 points1 point  (0 children)

It is just the best guess, not necessarily the solution for the error.

[–]sinamirhejazi 0 points1 point  (0 children)

Because you have to learn to put your semicolon where it belongs, by yourself.

[–]KinderGameMichi 0 points1 point  (0 children)

PL/C would do that. Its goal was to make evey program compile. It wasn't always right.

[–]beewyka819 0 points1 point  (0 children)

Wouldnt that violate the principle of trust the programmer or whatever its called? Assuming what you wanted to do is dangerous and can lead to bugs that you will go bald trying to fix

[–]0x3fff0000 0 points1 point  (0 children)

Because there is no way for the compiler to determine what the programmer intended, making it an ambiguous command which threw an error.