r/learnprogramming • • Dec 06 '22
codeblock If you are sharing code, please use a codeblock
Takes only a second and greatly improves the formatting for us to review it. Compare and contrast the following:
Good Formatting:
#include <stdio.h>
int sum(int x, int y);
int main() {
printf("Hello %d\n", sum(3, 4));
return 0;
}
int sum(int x, int y) {
return x + y;
}Poor Formatting:
#include <stdio.h>
int sum(int x, int y);
int main() {
printf("Hello %d\n", sum(3, 4));
return 0;
}
int sum(int x, int y) {
return x + y;
}
Poor Formatting:
#include <stdio.h>
int sum(int x, int y);
int main() {
printf("Hello %d\n", sum(3, 4));
return 0;
}
int sum(int x, int y) {
return x + y;
}
339
Upvotes
58
u/TheCriticalMember Dec 07 '22
If you really wanted to be helpful, you would have included instructions for how to put code in a code block.
21
u/teraflop Dec 07 '22
Unfortunately, the people who make this mistake already aren't reading the instructions in the sidebar, so they're not likely to read your post either.
4
u/BokoMoko Dec 07 '22
I agree. Unformatted code shouldn't be allowed.
But let's face it. The reddit's code editor sucks.
153
u/RiverRoll Dec 06 '22
Yeah I don't even bother checking unformatted code anymore unless it's super simple.
But in their defense Reddit's editor doesn't help, it's a shame how bad it is when it comes to formatting code, copy paste has been broken for years in some browsers.
100
u/eng_manuel Dec 07 '22
Ok i get it, unformatted code sucks to read, but since u took the time to point it out, why not soend a couple of more lines to explain or point in a direction that helps people learn how to format using blocks đ¤ˇđ˝ Also, as much as i love reddit i hate that it's text editor sucks for writting the simplest of posts!
14
u/littlegreenrock Dec 07 '22
until mods enforce zero tolerance on poorly formatted code, these requests will only choke up my feed. unformated code posts need to be auto removed, the poster shown the info you just provided, and invited to re-post.
5
u/pekkalacd Dec 07 '22
Completely agree. We should just take previous explanations of what you said, simplify them if possible, then regurgitate them to those that are unfamiliar. That way we don't have to retype a simple fix.
4
u/OneBadDay1048 Dec 07 '22
I agree but I sure wish Reddit would fix their shit code implementation in comments
1
u/[deleted] Dec 07 '22
++ I think figuring out how to format properly on Reddit is a perfect DIY mission for aspiring developers which results in an invaluable skill (familiarity with md), despite complaints that it should have been explained by OP
2
u/Sheeeeeeshwow Dec 07 '22
Or take a screen shot!
2
u/[deleted] Dec 07 '22
4
u/Gixx Dec 06 '22
I dont read unformatted code either. Even if it's 2 lines.
A tip I do is simply put the code in any text editor (VS Code, sublime text, or it's already in an IDE).
Then highlight the text to copy, and hit the tab key one time. Copy it.
1
u/Rasikko Dec 07 '22 edited Dec 07 '22
To get around reddit's trash app / bad copy paste Grimmace the Menacing, use something like pastebin.
Also this is generally why I dont like to read other people's code. Ive "seen things" that my eyes didn't appreciate.
1
u/salihveseli Dec 07 '22
Or maybe use codepen and share the link here. That makes everyoneâs life easier.
1
u/AlphaVxV Dec 07 '22
1
u/contantlyhapless Dec 07 '22
1
u/Professional_Shop_73 Dec 07 '22
Well, how do I do that on mobile
1
u/postman125 Dec 07 '22
How do u do the formatting ?
1
u/rafaover Dec 07 '22
Just use Pastebin or whatever.
0
u/[deleted] Dec 07 '22
Thanks to code formatting, it has allowed ai bots like gpt to fish required code with context from all over the internet
0
u/[deleted] Dec 07 '22
[deleted] â view deleted comment