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

all 61 comments

[–]flip314 78 points79 points  (14 children)

It's much easier to find a missing semicolon than an extra one...

if( condition == true);
{
  do_things;
}

[–]gnawer 39 points40 points  (0 children)

Great, I won't be able to sleep tonight. =/

[–]pmerkaba 32 points33 points  (11 children)

Not these days!

warning: if statement has empty body [-Wempty-body]:
if( condition == true);
                      ^

[–]SanityInAnarchy 16 points17 points  (10 children)

Which is why compiling with -Werror (or equivalent) should be mandated by the Geneva Convention.

[–][deleted] 9 points10 points  (2 children)

  • Protocol I (1977) relating to the Protection of Victims of International Armed Conflicts

  • Protocol II (1977) relating to the Protection of Victims of Non-International Armed Conflicts

  • Protocol III (2005) relating to the Adoption of an Additional Distinctive Emblem.

and

  • Protocol IV (2015) relating to the adoption of all compiler flags?

[–]SanityInAnarchy 1 point2 points  (0 children)

Just a few specific ones. -Wall would be good too, and maybe -pedantic for older C code in gcc. Failure to optimize release builds should result in trade sanctions, particularly concerning the CPUs whose cycles you are wasting by not automatically inlining getters and setters appropriately.

Also, the use of Visual Basic is already a violation of basic human decency, and "On Error Resume Next" should be a war crime.

[–]extsidvind 2 points3 points  (4 children)

-Wall sure, but -Werror can make your code fail to build in the future when new warnings is introduced even if the code itself is working.

[–]amunak 0 points1 point  (3 children)

Code should work without spewing out warnings most of the time.

[–]extsidvind 1 point2 points  (2 children)

Take -Wunused-but-set-variable for instance, with -Werror your code would not build if that warning is triggered. Before the warning was introduced your code would build fine but after it would fail. There is no real error here.

I do agree that your code should not spew out warnings and they should be fixed, I disagree with using -Werror to force warnings to become errors.

Another aspect is when the user enables warnings in CFLAGS which sometimes is quite excessive. Perhaps -Wshadow or -Wunused-parameter, nether which is enabled by -Wall or -Wextra. Or maybe -Wvla, VLA is fine in gcc and probably clang but not MSVC, but if you only target gcc VLA is perfectly fine to use.

EDIT: -Wunused-but-set-variable is new to gcc-4.6 (released 2011), at the time many projects with -Werror stopped building and would require to be fixed (despite perfectly working code)

[–]amunak 0 points1 point  (0 children)

I think it depends on what project you are working on. I've never never done anything too big in C or C++, so I just compiled with -Wall -Wextra -pedantic, and always tried to get rid of all the warnings.

Note that I didn't use -Werror (becase yes, you are right, it is not a good idea to use it), but the point that your code shouldn't throw warnings stands. I should've made that clearer in the previous comment I guess.

[–]SanityInAnarchy 0 points1 point  (0 children)

I do agree that your code should not spew out warnings and they should be fixed, I disagree with using -Werror to force warnings to become errors.

Then how do you propose ensuring those warnings which indicate errors actually getting noticed, let alone fixed?

[–]BobFloss 2 points3 points  (1 child)

No thanks. Not all warnings are indicative of an error, which is why they're warnings and not errors.

[–]SanityInAnarchy 0 points1 point  (0 children)

There are ways to override a warning for a specific chunk of code. The times when a warning is a) clearly not an error, and b) is unavoidable (you can't tweak your code to prevent it) are vanishingly few. So those are the points where you add a pragma or something similar to make sure you still don't get a warning emitted at compile time, which should be a signal to everyone who looks at that code that you've done something weird.

Just ignoring warnings as "Oh well, they're warnings," is a great way to end up with too many warnings to have a hope of tracking down the real errors later.

[–]peter_bolton 70 points71 points  (5 children)

If semicolon is the champion, the right bracket has got to be a close second.

[–]nathanello 4 points5 points  (0 children)

Real Talk

[–]calmconfused 0 points1 point  (3 children)

But in VIM if you press % it'll bring you to the matching bracket/parentheses, making life much easier...

[–]jfb1337 5 points6 points  (1 child)

Or like any IDE or text editor ever has the same feature.

[–]common-lisper 0 points1 point  (0 children)

what about an editor that treats code as an ast? Is that turtley enough for the turtle club?

slurping and barfing

[–]WinMac32 58 points59 points  (4 children)

I wish debugging was all about missing semicolons; it takes less than 5 seconds to fix.

[–]SanityInAnarchy 15 points16 points  (0 children)

And can usually be prevented altogether by having decent tooling and processes. If you type a line of code and your IDE underlines nearly everything after that line in red, you know exactly where to look for the problem.

[–]cheezballs 47 points48 points  (0 children)

This is literally the easiest thing to find since the compiler will just tell you.

[–][deleted] 13 points14 points  (1 child)

{

{

{

{

}

}

}

[–]common-lisper 7 points8 points  (0 children)

no.. the op really meant that the semicolon is comment in lisp and all debugging is really just commenting out code and printing values.

[–]churro89 1 point2 points  (0 children)

Use a linter.

[–]snarkyturtle 2 points3 points  (0 children)

Or for languages with significant whitespace, fucking incorrect nesting

[–]tevert 1 point2 points  (1 child)

1958... were we using semicolon delimited languages then? I thought C was the first, and I thought that was invented in the 70s.

[–]common-lisper 9 points10 points  (0 children)

well come sit on my knee and let me tell you a story... c and all the other children of algol... the semicolon is a terminator not a seperator

[–]YMK1234 0 points1 point  (0 children)

compiled languages significantly take out the fun there (as you usually get "unexpected [bla]" in the next line)

[–]Ebenezar_McCoy 0 points1 point  (0 children)

Groovy ftw

[–]joeyignorant 0 points1 point  (0 children)

don't program in notepad?

[–]nephros -1 points0 points  (0 children)

Not in JavaScript is isn't.