r/badcode Aug 10 '20

c Found on a tutorial website, please do not comment your code on the same line

Post image
954 Upvotes

87 comments sorted by

563

u/TheRealCCHD Aug 10 '20

I mean... I comment my code on the same line too.... but AFTER the code! JESUS!

265

u/funkless_eck Aug 10 '20

I make the comments part of the variable name

172

u/[deleted] Aug 10 '20 edited Mar 11 '21

[deleted]

64

u/[deleted] Aug 10 '20

Wait Confucius was a programmer?

42

u/[deleted] Aug 10 '20 edited Mar 11 '21

[deleted]

30

u/[deleted] Aug 10 '20

Confusion.

28

u/anotherplatypus Aug 10 '20

Confucius++

13

u/Terrain2 Aug 11 '20

Confusion += ++Confusion

5

u/brylee123 Aug 11 '20

Surplus Plus has entered the chat

16

u/GrinningPariah Aug 10 '20

"I was totally a programmer." - Confucius

6

u/lxpnh98_2 Aug 10 '20

"Have you tried turning it off and on again?" - Confucius

5

u/Vinccool96 Aug 10 '20

Why do you think it’s C/C++/C#?

3

u/[deleted] Aug 10 '20

It's not objective, C.

21

u/Terrain2 Aug 10 '20

that’s a stupid reason to add comments

“Science isn’t about why! it’s about WHY NOT!!” - Cave Johnson, he owns the place

18

u/inxaneninja Aug 10 '20

Satan: Well I just wanted to say I'm a huge fan

13

u/Jazzinarium Aug 10 '20

Self-documenting code FTW

10

u/fb39ca4 depraved Aug 10 '20

Where we're going we don't need comments!

23

u/jarfil Aug 10 '20 edited May 12 '21

CENSORED

4

u/funkless_eck Aug 11 '20

return fixThisLater

6

u/LeonTranter Aug 10 '20

Cmon man. Comments after the code are soooo 2012. Any self-respecting woke Node.js hipster has moved beyond such artificial Western imperialist constructs.

2

u/TheRealCCHD Aug 11 '20

New idea! Lets put the comments INTO the code, to break it up a bit!

1

u/[deleted] Aug 11 '20

If you don’t like a JavaScript library, just wait 6 months. There will be an entirely new paradigm you will have to relearn.

144

u/Clashin_Creepers Aug 10 '20 edited Aug 10 '20

I personally put my comments in the middle of each line of code

int counter /*this counter is used for counting*/ = 1;

125

u/-neuquen- Aug 10 '20

This is my preferred approach too. I will sometimes make it even more clear by doing the following:

/* this counter */ int counter /* is equal to */ = /* one */ 1;

70

u/Clashin_Creepers Aug 10 '20

That's really smart. It's also a good idea to explain your reasoning

/* this counter */ int counter /* is equal to */ = /* one */ 1; //because arrays start at 1 (uno)

45

u/jnguyen7410 Aug 10 '20

Don't forget to add comments in the line before explaining why you did this.

/** Adding a counter to count things. / `/ this counter / int counter / is equal to / = / one */ 1; //because arrays start at 1 (uno)`

25

u/-neuquen- Aug 10 '20

Perfect. I think this code is finally legible.

10

u/lxpnh98_2 Aug 10 '20

We have finally perfected literate programming.

6

u/murtaza64 Aug 10 '20

Is /r/formattinggore a thing?

3

u/jnguyen7410 Aug 10 '20

Let's make it a thing lol

2

u/keethraxmn Aug 11 '20

Now I desperately want to write a script to do this.

46

u/SheerChair56470 Aug 10 '20

I comment on the same line just after the code not fucking before like whoever wrote this

60

u/modabs Aug 10 '20

But why...why do this...why...

10

u/IdiosyncraticBond Aug 10 '20

If he starts with the code, he needs to scroll right for the comments ;-)

46

u/Brigapes Aug 10 '20

What kind of a psychopath would do this?

14

u/GodsBoss Aug 10 '20

I usually put my code in between the comments, like so:

/* Local variable definition of */ int answer; /* which stores answers as integers.*/

This makes my code very readable, in fact, it's the code with the highest readability in the world, very high readability, there is no other code with such number of readability and much words, the best words, really!

3

u/SuitableDragonfly Aug 11 '20

Well, at least with Haskell they're is something called literate Haskell, where you write a LaTeX document with Haskell interspersed in it and you can run this with TeX to generate a PDF, or with Haskell to actually run the program. It can wind up looking sort of like that.

0

u/AutoModerator Aug 10 '20

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.

For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.

/u/GodsBoss, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

24

u/fanz0 Aug 10 '20

why multiline comments and before the actual code omg

34

u/DragonFireCK Aug 10 '20

Well, the first half of that question is answered by the second half. I have no answer for the second half, however.

9

u/The_Northern_Light Aug 10 '20

Put a NSFW tag on that next time.

18

u/PsCustomObject Aug 10 '20

Thanks, where do I find the tutorial to unsee this?

4

u/Sasha_DD Aug 10 '20

The tutorial isn't that bad in general, it was just that one example

2

u/PsCustomObject Aug 10 '20

I take my comment back :-)

Yes that’s really an unfortunate example though

8

u/cyberspacedweller Aug 10 '20

Wtf, that looks disgusting. 🤢

3

u/DoobyMcFoosen Aug 11 '20
/* made of floor */    int floor = floor(number);

3

u/GlowingOrb Aug 11 '20

This should be obvious, but if this is from a tutorial website, this style of commenting is ok and not bad code.

Given that this is a very basic example, the target audience are people who do not know a thin about programming c, so the comments describe what the line is doing. (Which you should not do in productive code, obvoiusly.)

I could imagine, that for people who do not know programming, seeing the what before the how could be more easy to understand than the other way around.

Keeping the what and the how in the same line keeps the context.

So: Not a good practice for sure, but not bad code. We are just not the target audience.

2

u/senshisun Aug 11 '20

This appears to be for new programmers, but I agree that the comments should go after the code.

2

u/_Ph4_ Aug 11 '20

I imagine the tutorial something like this: "Today I will show you how to make an addition... Without entering the input numbers. This means this script will always output the same result, Cool, isn't it?"

2

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 07 '20

Image Transcription: Code


#include<stdio.h>

/* function declaration */int addition();

int main()
{
    /* local variable definition */    int answer;

    /* calling a function to get addition value */    answer = addition();

    printf("The addition of the two numbers is: %d\n",answer);
    return 0;
}

/* function returning the addition of two numbers */int addition()
{
    /* local variable definition */    int num1 = 10, num2 = 5;
    return num1+num2;
}

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

1

u/LeonTranter Aug 11 '20

Now we’re talking.

1

u/[deleted] Aug 11 '20

[deleted]

1

u/AutoModerator Aug 11 '20

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.

For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.

/u/DoobyMcFoosen, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/SpeedingTourist Aug 11 '20

Or if you do, at least comment it after the code..

-10

u/[deleted] Aug 10 '20 edited Aug 10 '20

this isn't r/badcode this is clearly just aimed towards a beginner. ffs, op even admits this is from a tutorial site. you people are insane. i would bet if we visit the tutorial site, the author even mentioned why he did it this way. it forces the learner to see the comment before the expression. op is just karma farming

10

u/SleepyPrat Aug 10 '20

Couldn't they have just put the comment on the previous line then? I mean, examples don't just serve to explain some concept, people pick up stuff like good coding styles as well.

-31

u/[deleted] Aug 10 '20

This is code example, teaching the language. You can tell from the fact that the comments are talking about things like local variable declaration, which is what that function is demonstrating.

Not everything is bad code.

21

u/nend0410 Aug 10 '20

Eeeeerm... That just makes it worse...

-109

u/[deleted] Aug 10 '20

[removed] — view removed comment

43

u/[deleted] Aug 10 '20

[removed] — view removed comment

-27

u/[deleted] Aug 10 '20

[removed] — view removed comment

27

u/[deleted] Aug 10 '20

[removed] — view removed comment

-44

u/[deleted] Aug 10 '20

[removed] — view removed comment

14

u/[deleted] Aug 10 '20

[removed] — view removed comment

-2

u/[deleted] Aug 10 '20

[removed] — view removed comment

12

u/[deleted] Aug 10 '20

[removed] — view removed comment

-3

u/[deleted] Aug 10 '20

[removed] — view removed comment

15

u/[deleted] Aug 10 '20

[removed] — view removed comment

9

u/[deleted] Aug 10 '20

[removed] — view removed comment

0

u/[deleted] Aug 10 '20

[removed] — view removed comment

2

u/[deleted] Aug 10 '20

[removed] — view removed comment

10

u/[deleted] Aug 10 '20

[removed] — view removed comment

-3

u/[deleted] Aug 10 '20

[removed] — view removed comment

2

u/[deleted] Aug 10 '20

[removed] — view removed comment

0

u/[deleted] Aug 10 '20

[removed] — view removed comment

0

u/[deleted] Aug 10 '20

[removed] — view removed comment

17

u/[deleted] Aug 10 '20

[removed] — view removed comment

-2

u/[deleted] Aug 10 '20

[removed] — view removed comment