[ / / / / / / / / / / / / / ] [ dir / animu / asmr / rel / strek / sw / travis2k / vore / zoo ][Options][ watchlist ]

/tech/ - Technology

You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
Password (Randomized for file and post deletion; you may also set your own.)
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

[–]

 No.892562>>892573 >>892589 >>892629 >>892633 >>892665 [Watch Thread][Show All Posts]

What is correct way of putting comments into code for C/C++? It often makes me really annoyed because I use comments often as separators for larger chunks of code and it all gets messy. Simply writing //Something is terrible way of commenting something and so is multiline comment describing every little obvious bullshit.

Are you happy about how comments work in C/C++? Is it sufficient enough for you? Doesn't your code get ugly and messy? Any advice for me how to comment like white person and not MIT nigger?

If you would pick best syntax/style to write comments from any language, which one it would be?

 No.892564

The proper thing to do is to handwrite a 1:1 copy of your code in a notebook, and put your comments on that, that way you can reference it, but any faggot that steals your code will be forced to come to /tech/ and make a thread bitching about how people don't document their code.


 No.892573>>892582

>>892562 (OP)

>another bikeshedding topic

sage


 No.892582

>>892573

>"Oh no, somebody created thread I don't like on my slow board, oh what I'm going to do"


 No.892589

>>892562 (OP)

>spergs out over commenting (nevermind he complains "how comments work in c/c++" why apparently really being confused about what is too much and what is too little commenting)

>his example has no indentation whatsoever

hmmm


 No.892613


/* This program is illustrating a preferred comment etiquette
* and style.
* This is public domain
*/

/* Import C library */
#include <stdio.h>

main( )
{
/* This will produce the phrase "Hello World" which will
* be followed by a new line. This exits cleanly.
*/
printf("hello, world\n");
}

It's not that hard


 No.892619

/////////////////////////////////////////////////////////////
/loooooooooooooooooooooooooooooooool/
/////////////////////////////////////////////////////////////


 No.892620>>892626

File (hide): 73b5c1d5e787ef0⋯.png (205.25 KB, 624x200, 78:25, .png) (h) (u)

>void main()


 No.892626>>892636

>>892620

#include <stdio.h>
void *main(void)
{
puts("\x6b\x65\x6b\x6b\x69\x74\x79\x20\x6b\x65\x6b\x0a");
return NULL;
}


 No.892629>>893158

>>892562 (OP)

You're fine.

Just note:

//This is a C++ style comment. It should work on most modern C utilities and compilers, but many older C utils and compilers can't process them.

[code]/* This is a C style comment. All C compilers and utilities will support this no matter the age.[/spoiler]


 No.892633>>892643

>>892562 (OP)

>not using the 1337 w@yZ


/*

▒███▒ ███ █▓██ ░███░ █▒██▒ ░███░ █████ ███ █▒██▒
█▒ ░█ ▓▓ ▒█ █▓ ▓█ █▒ ▒█ ██ █ █▒ ▒█ █ █▓ ▓█ ██ █
█▒░ █ █ █ █ █ █ █ █ █ █ █
░███▒ █████ █ █ ▒████ █ ▒████ █ █ █ █
▒█ █ █ █ █▒ █ █ █▒ █ █ █ █ █
█░ ▒█ ▓▓ █ █▓ ▓█ █░ ▓█ █ █░ ▓█ █░ █▓ ▓█ █
▒███▒ ███▒ █▓██ ▒██▒█ █ ▒██▒█ ▒██ ███ █



*/


 No.892636

>>892626

>\x6b\x65\x6b\x6b\x69\x74\x79\x20\x6b\x65\x6b\x0a

>kekkity kek

\x6b\x65\x6b\


 No.892643>>892766 >>893159

>>892633

It's not guaranteed how characters beyond 0x7f are going to be displayed (.nfo style shit generally relies on plain old codepage 437, use anything else and it'll look like random crap).


 No.892645>>892665 >>892676

File (hide): 7c99cad7f46835c⋯.png (34.22 KB, 621x942, 207:314, hurr_fizzbuzz.png) (h) (u)

Pic related is a great example of self-documenting code where comments arent' necessary in the first place.


 No.892665

>>892562 (OP)

Typically in the header file, I'll document each of the functions, there arguments, any restrictions, and return value. In the source file, functions are only commented if they have a complicated procedure to follow. Inside of functions comment things that aren't obvious in what you are doing. Finally, I like to break some functions up with an abstract description of what is trying to be done in the following code.

In addition to these comments, you should be writing "self documenting code."

>>892645

>func1

>func2

That's not self documenting.


 No.892674

You put quotation marks around it to turn it into a no-op string literal.

That doesn't work if you already use string literals in your code but real programmers don't work with text anyway.


 No.892676>>892910

File (hide): e749637d5a9551a⋯.jpg (76.21 KB, 750x562, 375:281, 15104322882630.jpg) (h) (u)

>>892645

That's fucking perfect. You are hired. Welcome to the team


 No.892766

>>892643

It was more of a LARP tbh, though it can be done in UTF8 as well as CP437.

It is simple to convert between codepages, either in the terminal display or file format itself.


 No.892779

File (hide): a077e479089b28b⋯.jpg (18.7 KB, 500x335, 100:67, stop.jpg) (h) (u)

>A delicate matter, requiring taste and judgement. I tend to err on the side of eliminating comments, for several reasons. First, if the code is clear, and uses good type names and variable names, it should explain itself. Second, comments aren't checked by the compiler, so there is no guarantee they're right, especially after the code is modified. A misleading comment can be very confusing. Third, the issue of typography: comments clutter code.

>But I do comment sometimes. Almost exclusively, I use them as an introduction to what follows. Examples: explaining the use of global variables and types (the one thing I always comment in large programs); as an introduction to an unusual or critical procedure; or to mark off sections of a large computation.

>Avoid cute typography in comments, avoid big blocks of comments except perhaps before vital sections like the declaration of the central data structure (comments on data are usually much more helpful than on algorithms); basically, avoid comments. If your code needs a comment to be understood, it would be better to rewrite it so it's easier to understand.


 No.892910

>>892676

what's the candy it looks really good but im allergic to peanuts


 No.893158

>>892629

It's also a standard C99 comment. If your C compiler doesn't support a 19-year old language standard revision, you should seriously get a fucking new compiler.


 No.893159

>>892643

>not using glorious unicode in comments

how do you even use nigger emojis then




[Return][Go to top][Catalog][Screencap][Nerve Center][Cancer][Update] ( Scroll to new posts) ( Auto) 5
21 replies | 4 images | Page ?
[Post a Reply]
[ / / / / / / / / / / / / / ] [ dir / animu / asmr / rel / strek / sw / travis2k / vore / zoo ][ watchlist ]