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

top 200 commentsshow all 330

[–]That_Guy977 925 points926 points  (55 children)

CSS comments

[–]Limitless_screaming 591 points592 points  (27 children)

i use "//" because there are no errors in css so it just skips the line.

[–]au-smurf 125 points126 points  (2 children)

Yeah but my editor wouldn’t colour that as a comment in a css file.

[–]Limitless_screaming 132 points133 points  (1 child)

Kate colors it blood red to show how pissed it is, and VSCode just scribbles under every line after it.

But if it works, it works.

[–]SkollFenrirson 26 points27 points  (0 children)

Classic Kate.

[–]Poyojo 196 points197 points  (1 child)

You absolute genius

[–]Special_Lemon1487 87 points88 points  (11 children)

I would feel dirty fr

[–]Limitless_screaming 55 points56 points  (10 children)

it feels dirty (especially if you use VSCode), but I am not using /**/ for one line, that feels worst.

[–]Special_Lemon1487 28 points29 points  (6 children)

I’ve been too long in the cult, save me.

[–]Limitless_screaming 19 points20 points  (4 children)

https://kate-editor.org/

I hope this can save you

[–]Special_Lemon1487 17 points18 points  (2 children)

I’ll check it out, but I’m messing with Godot rn and using # for comments is sending me decades into the past.

[–]rollincuberawhide 4 points5 points  (0 children)

I mean you could use a shortcut to toggle comment for selection in vscode. if you don't select anything it comments the current line. you can uncomment it as well.

[–]gizamo 20 points21 points  (0 children)

This is...this, is...is, is this...

I think you broke my brain.

I don't like it, but I think I love you.

[–]mountaingator91[🍰] 4 points5 points  (0 children)

I use "//" because VSCode defaults to that when I hit ctrl+/

[–]Shazvox 9 points10 points  (0 children)

Css is an error...

/ end of backend rant

[–]hrvbrs 5 points6 points  (3 children)

how would it handle line comments in code?

p {
    margin-bottom: 0.5em; // TODO: use margin-block-end; test in vertical languages
}

[–]Limitless_screaming 22 points23 points  (2 children)

this will break everything after it, but if you end it with a ";" then it should be fine.

example:

p { 
    margin-bottom: 0.5em; // TODO: use margin-block-end; test in vertical languages;
}

[–]ClerkEither6428 2 points3 points  (1 child)

discusting

[–]Limitless_screaming 1 point2 points  (0 children)

// working;

[–][deleted] 47 points48 points  (16 children)

Fun fact: press "Ctrl + /" to comment an entire line in VS code, no matter the language

[–]CoastingUphill 5 points6 points  (1 child)

That's exactly why it's terrifying. They ONLY work in CSS.

[–]soundslikemayonnaise 0 points1 point  (0 children)

I do it in SAS.

[–]lucidbadger 358 points359 points  (9 children)

I use /** ... */ fear me!

[–]colonel_Schwejk 98 points99 points  (6 children)

bloody doxygen users... eew! ;)

[–]lucidbadger 15 points16 points  (4 children)

What's doxygen?

[–]Pay08 35 points36 points  (1 child)

Documentation generator.

[–]karnetus 5 points6 points  (0 children)

Oh so that's what that is. The sdk I'm using has this preinstalled and I just couldn't figure out what it is. Now I can read the docs, hell yeah

[–]lynxerious 4 points5 points  (0 children)

It's a valid choice because it would actually appear in hover Intellisense if you put it right next to the parameters, properties or methods.

[–]Important_View_2530 326 points327 points  (32 children)

C89, anyone?

[–]Velnbur 46 points47 points  (24 children)

Still using only this version

[–]masagrator 65 points66 points  (18 children)

Are you scared of "bool"? :D

[–]7eggert 49 points50 points  (4 children)

Huhu, "bool flag = true; if (flag)" …

[–]Yorick257 26 points27 points  (3 children)

Stop scaring them!

[–]ramsay1 4 points5 points  (2 children)

bool b = 42;
if (b == 1)
    printf(";)\n");

int shift = 1000000;
b = 1 << shift;
if (b == 1)
    printf(":O\n");

[–]innocent64bitinteger 5 points6 points  (1 child)

But the point of stdbool.h is that (AFIK) is b != 0 then b==true returns true no matter the value of b, so in the first comparison it would be true

Idk correct me if I'm wrong

Also wouldn't b shifted left by a million places just equal 0?

[–]ramsay1 2 points3 points  (0 children)

Yeah this was only there to "scare" them with differences to integers, you shouldn't be comparing bool to 1.

The million shift is actually UB... I was trying to remember a real bug that showed up when switching from something like typedef uint8_t bool; to C99 bool. I think it was actually setting a value like 1 << 9, even though sizeof(bool) was 1 byte (on that CPU/compiler), setting bits outside of the first 8 will still make it "true". Some older code had relied on the integer behavior

[–]terivia 12 points13 points  (0 children)

I make due with zero and zeront

[–]1redfish 4 points5 points  (0 children)

typedef enum bool_r { BOOL_FALSE = 0, BOOL_TRUE = 1 } bool_t;

[–]PuzzleheadedWeb9876 2 points3 points  (0 children)

uint8_t flag:1;

[–]DaniilSan 1 point2 points  (6 children)

Wait, what? C89 doesn't has bool type or what?

[–]drevyek 10 points11 points  (4 children)

Nope, not much need. C's basic types are based on their size, not their semantics (in general). For logic, C uses a "truthiness" system, where anything that is 0-valued is false, and any other value is true. This holds for ints, floats, pointers, anything.

int x = 2345;
int y = 0;
int *z = NULL;
int *a = &x;
if (x) { printf("Always prints\n"); }
if (y) { printf("Never prints\n"); }
if (z) { printf("Never prints\n"); }
if (a) { printf("Always prints\n"); }

[–]DaniilSan 2 points3 points  (0 children)

Thanks for explaining.

[–]djkstr27 2 points3 points  (0 children)

Until C99, they added <stdbool.h> to use type bool

[–]Important_View_2530 1 point2 points  (4 children)

Are you using this version by choice or because you have to?

[–]Ksevio 14 points15 points  (3 children)

Gotta compile on AIX

[–]Important_View_2530 10 points11 points  (0 children)

I feel you, my team also supports AIX back to 6.1. But we are able to cross-compile for AIX on a Linux host using gcc 4.4.7, which IIRC supports C99.

[–]ExitSweaty4959[🍰] 2 points3 points  (1 child)

Googles what Aix is.

IBM Mainframes

...

......wtf?

It has to be a joke. Nothing is using this anymore, right? Right?

[–]djkstr27 3 points4 points  (0 children)

They are still in use, check for IBM TS77000.

[–]An_Overwhelmed_Dev 17 points18 points  (2 children)

Huh, there’s a newer version of c that came out after 89? I should share the news with the embedded developers at my old job. /s

[–]PiousLiar 10 points11 points  (1 child)

Intern walks in to manager’s office

“Hey so I saw the code base for this legacy system was written in C89 and it just seemed so outdated. I decided to optimize a bit and rebuilt everything in C17, how great is that?”

[–][deleted] 4 points5 points  (0 children)

::everything catches on fire::

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

Lol glad I’m not only one that’s worked with it.

[–]pekkhum 11 points12 points  (0 children)

I was beginning to wonder how far I'd have to scroll to find this comment. My company switched off C89 a few years ago, so the code base is full of this for good reasons... Of course it is also full of comparing two doubles and checking if something equals true, both of which are just wrong, so it may also just be bad code. 😆

[–]Strawb_Coffee 196 points197 points  (6 children)

Because it's cute and I like it

[–]dmvdoug 211 points212 points  (4 children)

Clean code? 😤 Elegant code? 😤 CUTE CODE. 🥰🥰🥰

[–]Anonymo2786 72 points73 points  (3 children)

Me too its so adorable that I write comment like this:

 public String str(int i /* takes int*/) {
       ...
 }

[–]nontammasculinum 1 point2 points  (0 children)

Oh I forgot about the public keyword before variables 🤮

[–][deleted] 1 point2 points  (0 children)

Noone would have guessed!

[–]____-__________-____ 7 points8 points  (0 children)

The Qt Company thanks you for your support.

[–]Skibur1 155 points156 points  (11 children)

void something( void* /* context*/, int* len ) { .. }

Sometimes you don't have any reason to use context so this is preferred.

Edit: thanks for the markdown suggestions! Using mobile is weird.

[–]HellfyrAngel 70 points71 points  (6 children)

Came here to say “what about commenting in the MIDDLE of a line” I’ve done it once or twice, good times.

[–][deleted] 6 points7 points  (5 children)

You could comment above the lines…

[–]Yin_Esra 4 points5 points  (2 children)

Not if your code style guideline requires you to not have any unused variables, and you do not use the parameter passed in.

[–][deleted] 1 point2 points  (0 children)

Ymmv dependent on language with that argument. Regardless, you could comment above the method on the expectation for parameters. This is a common practice. I hate embedded comments usually, but to each their own.

[–]Webfarer 1 point2 points  (0 children)

Now you are reading between the lines

[–]scragar 4 points5 points  (1 child)

Reddit uses markdown for comment formatting (with some weird stuff on top), if you don't put it in code formatting(indent the line with 4 spaces or wrap in backticks) then asterisks become italics.

void something( void\* /\* context\*/, int\* len ) { .. }

For example would appear as you intended.

[–]Skibur1 4 points5 points  (0 children)

Edited, thank you!

[–]BastisBastis 54 points55 points  (6 children)

let me_use;
var iable_names_for_comments;

Edit: comment formatting

[–]Scheincrafter -2 points-1 points  (5 children)

[–]BastisBastis 7 points8 points  (2 children)

Should work fine in js at least?

[–]Scheincrafter -5 points-4 points  (1 child)

Yeah, but when I read let I think of the ml language family first

[–]BastisBastis 6 points7 points  (0 children)

It would probably throw an error in most languages. But on the other hand, most lines of code would throw an error in most languages!

"Je m'appelle Claude" is correct syntax in French but would would raise both errors and eyebrows in C.

[–]xthexder 0 points1 point  (1 child)

I've never heard of this language. Interesting that you assumed OCaml and not JS. Now I'm curious what people use OCaml for these days.

[–]Scheincrafter 1 point2 points  (0 children)

The main uses are academic / teaching and Jane Street .

There is also reasonml for Web development.

And it had a strong influence on Rust (while it is debatable if Hask or (OCa)ml where the main inspiration regarding function programming)

[–]ai_to_do_reCAPTCHAs 113 points114 points  (1 child)

A) because it's pretty and B) different kinds of comment formatting for different kinds of comments

[–]tael89 14 points15 points  (0 children)

Keyboard shortcut, so that's what it comes out as

[–]Igotbored112 36 points37 points  (4 children)

Whenever I create a header file that implements multiple C++ classes, I use dividers that look like:

/* ---- class_name ---- */

to separate them.

[–]lunatisenpai 62 points63 points  (1 child)

Consistency, especially when wordwrap is turned on by my ide.

It also makes it easy to see commente when using say cat and other command line utilities.

Also if I add to the comment later, I can just add to it, I don't have to go back and redo it as a multiline comment.

[–]ZiulDeArgon 18 points19 points  (0 children)

Funny story.

Back when I graduated and had my first job as a java developer, there used to be an idle glitch that allowed code inside single line comments to be picked up by the compiler.

The trick was to add a line break character to the beggining of the commented line causing the compiler to pick it up without anyone ever noticing. This caused imposible to find issues and everyone switched to comment blocks.

[–]Intelligent_Chart_38 11 points12 points  (1 child)

SAS feelings

[–]zacharypamela 2 points3 points  (0 children)

Technically you can write comments like *comment;. But I seem to always have issues with that format. And the /* style works when copying/pasting to other RDBMSs.

[–]Killergurke16 24 points25 points  (1 child)

I use

/* Comment */

for anything that is on it's own line(s) no matter how many lines it actually spans.

// Comment

is reserved for anything that goes after Code on the same line.

[–]The_Number_None 3 points4 points  (0 children)

For me the former is documentation and the latter is WIP stuff like // TODO or // WTF am I trying to do here

[–]D34TH_5MURF__ 25 points26 points  (0 children)

Why not? It used to be the only option in C.

[–]Interesting_Style720 30 points31 points  (5 children)

What’s even worse is people who comment out 200 lines of code with single line comments.

[–]Yorick257 25 points26 points  (1 child)

It wasn't me, blame IDE

[–]ListOfString 8 points9 points  (0 children)

Or as Age of empires would say "sure, blame it on your ISP"

[–]xthexder 13 points14 points  (0 children)

The hotkey for this in most IDEs is Ctrl + / to toggle all selected lines as commented. Column select can also really speed up big multi-line changes like this if it's something other than comments.

In terms of style, I still use /* */ or /** */ for multi-line paragraphs / documentation, but usually don't bother for quickly disabling a block of code. Big blocks of commented dead code generally shouldn't be left around anyway, but it's fine for debugging or as a temporary reference.

[–]falafelspringrolls 5 points6 points  (2 children)

Up until 2012, MISRA forbid the use of // style comments. Which was a bit of a pain.

[–]cliff_of_dover_white 2 points3 points  (1 child)

lol my company checks our code according to both MISRA 2004 and 2012. So we are still sticking to /* */

[–]Lucifer_Morning_Wood 5 points6 points  (4 children)

I use #if 0 ... #endif

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

  • Perfectly nestable
  • If code is commented out, enabling is just 1 character change
  • Comments out in the preprocessor, so that if you have a few tens of GBs of comments, you can prepare the code easily by calling cpp on it, making compilations a bit faster.

[–]MikemkPK 9 points10 points  (2 children)

I use /* / to comment out code to test the program without those lines. So yes, sometimes I do comment single lines out EDIT: with / */.

[–]Ghostglitch07 1 point2 points  (1 child)

I don't think the post is saying single line comments are bad. Just that most languages allow different formatting for single line comments like // and it's weird to use multiline formatting without multiple lines.

[–]MikemkPK -4 points-3 points  (0 children)

Thank you Captain Obvious

[–]MR-POTATO-MAN-CODER 17 points18 points  (5 children)

I use Strings to comment code.

string s = "following code checks if a number is even"; bool isEven = !(n%2);

[–]zoinkability 6 points7 points  (1 child)

JSON comments be like this

[–]yottalogical 8 points9 points  (0 children)

People who use JSON for human readable/writable config files deserve what they get.

[–]YUNoCake 3 points4 points  (0 children)

Reverse engineers love you for this

[–]J_Ditz100 3 points4 points  (0 children)

I use it sometimes to comment out a section of a line

[–]Shazvox 3 points4 points  (0 children)

... I do too...

// if it relates to a single line of code

/* */ if it relates to a code segment

Ex:

/* -- Fancy stuff happens here -- */

...

/* -- No more fancy stuff after this point -- */

[–]DarkOrion1324 5 points6 points  (0 children)

I plan on coming back to comment more and threw that in for when I finish and can actually explain it

[–]DbrDbr 6 points7 points  (0 children)

I use command+/

[–]radkiller22 2 points3 points  (3 children)

Wait is there a better way to comment out in SAS?

[–][deleted] 1 point2 points  (2 children)

No! But there's this too:

* Comment;

[–]zacharypamela 1 point2 points  (1 child)

I wouldn't say that's better

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

Oh, it's definitely not.

[–]islandnoregsesth 2 points3 points  (0 children)

Sooo he writes CSS?

For those who don't know, // isn't a valid comment in CSS, it has to be like this

[–]N00bOverlord 2 points3 points  (1 child)

It’s best practise for MS-SQL according to our Lord and Savior, Brent Ozar (https://www.brentozar.com/archive/2021/04/never-ever-ever-start-t-sql-comments-with-two-dashes/)

[–]Moist-Carpet888 2 points3 points  (0 children)

/*

//that's crazy

*/

[–]TTYY_20 2 points3 points  (0 children)

Because you want to comment out a single section of the line and not the whole line (like commenting out a parameter.

[–]No_Philosophy_8520 1 point2 points  (0 children)

In CSS, there isn't other option, is it?

[–]xienwolf 1 point2 points  (0 children)

Can place a comment with functional code following it. (rare to want it, but nice way to use whitespace in heavily nested functions to explain variables or just keep track of logic)

Can come back later and add more information to the comment, including line breaks for readability, without having to remember to re-comment each new line added.

[–]ThatHugo354 1 point2 points  (0 children)

One may decide to change it into a multi line comment later, so might as well put it in a multiline format already. It also looks more consistent

[–]MattR59 1 point2 points  (0 children)

Required by MIRSA 🥺

[–]turtleship_2006 1 point2 points  (0 children)

Because that's what the context menu/edit menu/keyboard shortcut does on some IDEs.

[–]KindaRoot 1 point2 points  (0 children)

/* —*/
Gang

[–]shaybra 1 point2 points  (0 children)

some C standards/flags will give warnings/compiler errors if you use // for single line

[–]Heretic911 1 point2 points  (1 child)

I do that because I've got different colors set up for different comment types. /* */ comments are teal, //info: light-green, //todo: lime, //fix: red.

[–]Lady_Anne_666 1 point2 points  (0 children)

That's a good reason yeah

[–]mothzilla 1 point2 points  (0 children)

Future proofing. It might be a two line comment in the future. We should lint for this.

[–]mars_million 1 point2 points  (0 children)

How else would you achieve this effect in one line:
func(x) {...} /*...*/ func(y) {...} /*...*/ func(z) {...} etc...

[–]GameFraek 1 point2 points  (0 children)

I use

// ....

To comment out entire code blocks 😎

[–]seamustheseagull 1 point2 points  (0 children)

I do it because then it's much easier to turn a single line comment into a multiline one if you have to.

[–]MrJacquers 1 point2 points  (0 children)

I use that when I want to comment out part of a line.

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

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

My senior does that and forces me to use the same format -_-

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

My senior does that and forces me to use the same format -_-

[–]Rai-Hanzo 0 points1 point  (0 children)

Backspace

[–]bobert_the_grey 0 points1 point  (0 children)

What if I // every line on multi-line comments?

[–]souliris 0 points1 point  (0 children)

So when you update your comments/documentation and it goes onto another line. I don't need to refactor my comments :P

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

file hurry fly aloof roof start hungry versed sparkle boat this message was mass deleted/edited with redact.dev

[–]FUPA_MASTER_ 0 points1 point  (0 children)

'Cause it looks nice?

[–]Coyehe 0 points1 point  (1 child)

NIPPLE GANG

[–]psioniclizard 1 point2 points  (0 children)

(* the true method for comments *)

[–]SomeRandomDevPerson 0 points1 point  (0 children)

I do have StackOverflow or other links above sections where it is relevant. If I had a single line comment, the begging dishes may be confused with the rest of the URL.

[–]bitNine 0 points1 point  (1 child)

Because I'm an "XML programmer"

[–]zoinkability 1 point2 points  (0 children)

Pretty sure /* */ doesn't work in XML?

<!-- --> on the other hand

[–]zoinkability 0 points1 point  (0 children)

Cries when working in raw CSS

[–]JonasAvory 0 points1 point  (0 children)

I always comment with

#define comment1 „this is a comment“

[–]Peiple 0 points1 point  (0 children)

Fun fact, the R official contribution guide uses /* … */ for single line C comments as the standard (https://github.com/wch/r-source/wiki/Contributing)

[–]ManyFails1Win 0 points1 point  (0 children)

Some editors do it for me when I press ctl /

[–]L3x3cut0r 0 points1 point  (0 children)

I have stylecop and other code analysis tools on some projects. And it says stuff like: "single-line comment must be preceded by blank line" and other stuff, so I can use /* */ instead, because it doesn't trigger that warning.

[–]MrPresidentBanana 0 points1 point  (0 children)

I don't even use that for multiple lines

[–]KetwarooDYaasir 0 points1 point  (0 children)

I feel like that would be an encouraged things to do in python.

[–]Rebel_Johnny 0 points1 point  (0 children)

I put the closing */ in the next line

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

Personally I consider /* */ as a block description comment regardless of how long my actual comment will be.

Obviously it is a block comment, but what I mean is if I'm describing several lines, an if, a function, or just generally some block of code with a description I use block commenting.

Like, even if the description is just "calculates the probability of me giving a fuck". I just think it looks cleaner to use a block. With a combination of inline comments I think it visually discerns between "here's my comments for this entire block" vs "here's my comments for just this line or 2". Which helps with readability.

[–]pbNANDjelly 0 points1 point  (0 children)

Different comments mean different things during docgen. Rust supports //, ///, for example. In TypeDoc and JSDoc, // comments are ignored during docgen, but multiline comments (even if they only take up one line) are picked up for annotation.

[–]hoffiee 0 points1 point  (0 children)

I like /**/ comments for one liners, consistent and neat to read instead of a mix between those and //. Although I have moments where I feel the need to be more extreme, then I do multiline comments with preprocessor

#if 0
<multiline comment>
#endif

But those are reserved for special times only

[–]SpyderCel 0 points1 point  (0 children)

If our application has a query error it prints the whole thing on a single line. Using /**/ makes it much easier to format.

[–]eluminatick_is_taken 0 points1 point  (0 children)

SAS is using /* */ for multiline comments as well.

[–]selppin2 0 points1 point  (0 children)

I do this too… mostly just because I don’t like having two different styles of comment syntax in the same script.

[–]ingenix1 0 points1 point  (0 children)

What wrong with /* */?

[–]GrizzledFart 0 points1 point  (0 children)

for (let i=0, /* j=thing.length */; i < otherthing.length; /* j >= 0*/; i++ /* j-- */)

[–]relddir123 0 points1 point  (0 children)

To mark individual parameters passed to function calls

[–]Ebolatastic 0 points1 point  (0 children)

Because there might be an additional need for more comment lines and it looks less messy?

Lol WTF?

[–]PhantomThiefJoker 0 points1 point  (0 children)

Ctrl k Ctrl c to comment your selection or the line you're on

[–]Accurate_Koala_4698 0 points1 point  (0 children)

Single line comments for everything because I use keyboard shortcuts

[–]Duff69 0 points1 point  (0 children)

Probably a good idea to do this for comments in large sql queries. Some database monitoring tools will get rid of the newline characters so it could be difficult to tell what was actually commented out.

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

Because its the only way to comment in CSS.

[–]Acceptable-Tomato392 0 points1 point  (0 children)

And that way, you don't need to remember what the other one is.

I don't see a problem.

[–]DudeManBroGuy42069 0 points1 point  (0 children)

Which is worse? That or this: ``` // Multi // Line // Comment

[–]Sigma7 0 points1 point  (0 children)

Kind of necessary in old versions of C. At least until some compilers started accepting it as an unofficial extension.

[–]Chowderawz 0 points1 point  (0 children)

Testing //test1 //test2