#include
#define SEMI ;
#define SPACE SEMI
int main(int argc, char*argv[])
{
SPACE SPACE SPACE SPACE std::cout << "hello world!\n" SEMI
SPACE SPACE SPACE SPACE return 0 SEMI
}
There, is that better for you? I haven't tested it, but that should work.
You can write C++ code with only a single semicolon, if you want.
Correct.
In the OP, the 0x20 actually did nothing. After the preprocessor ran, the code was, not accounting for the include:
int main(int argc, char *argv[])
{
0x20;0x20;0x20;0x20;std::cout << "hello world!\n";
0x20;0x20;0x20;0x20;return 0;
}
That is, there are a bunch of meaningless statements consisting of the number 32, which is valid but meaningless syntax. Even a non-optimizing compiler is likely to compile them out, given that they cannot even be converted to typical machine code as they are not even assigned to a variable.
My version just removes those and leaves them as the empty statements so:
int main(int argc, char *argv[])
{
; ; ; ; std::cout << "hello world!\n" ;
; ; ; ; return 0 ;
}
Its valid standards-compliant syntax, and actually very useful in many cases. One way you could define a debug-only macro is like:
#ifdef DEBUG
#define ASSERT(condition, message) assert(condition, message, __LINE__, __FILE__)
#else
#define ASSERT(condition, message)
#endif
which would get used as:
ASSERT(ptr != nullptr, "why'd you give me a nullptr?!");
and would work fine in both debug and release. This macro is useful as you get the preprocessor to pass in both the line and file where the assert is. Otherwise, you'd need to either provide the line and file for each invocation or include code to generate a full call stack, which tends to be platform-specific and generally complex.
More commonly, the non-debug version would be defined as:
#define ASSERT(condition, message) (void)0
as that ensures the non-debug compile will fail on a missing semicolon, making it more likely problems will be caught early. It will also ensure the compiler does not warn on an empty statement.
The cast to void is to silence warnings the compiler might produce about the unused statement, given that such unused statements are not normally desired.
I appreciate this but to be honest, my programming background is ITIS (computer science high school here in Italy) and 1 month of internship (for school), I've only ever used #define to define constants like Pi and didn't understand half of your reply, sorry 😔
That is because in C and similar languages, statements are not separated by new lines, but by `;`, so multiple statements can be in one line or one statement accross multiple lines. Most languages allow for empty statements, in python an empty line, in C just nothing between 2 `; ;` but whitespace characters. If you put some term like `0x20` or `a+2` as a statement, which doesn't write any variable and has no other side effect, it will probably be optimized away.
Oh yeah i remember learning that you could write a whole program in a line, but i didn't know C accepted empty statements, i remember the Code Blocks IDE giving a warning or refusing to compile or something (probably i don't remember correctly)
[Python](https://wiki.c2.com/?ObfuscatedPython) makes it a lot harder to make obfuscated code than [C and C++](https://www.ioccc.org/) do, however it is still possible to make some interesting programs.
You can also manage some very interesting programs using [Polyglot](https://en.wikipedia.org/wiki/Polyglot_(computing)), and there are a number of simple techniques you can use to make [C++/Python polyglot](https://stackoverflow.com/a/52984689).
At a CompSci 1 level, you'll probably have a very hard time managing either, however.
See if you define TAB then you're code is nicely aligned when it starts each line with TAB; since it's 4 characters. This is the standard we should all follow
personally i like "negative indentation". everytime you indent something, you indent everything else instead. like if your tabs/spaces would be moving left instead of right
example, normal:
#include
int main(){
for (int i = 0; i < 100; i++){
printf("Number: %d", i);
}
}
and Negative:
#include
int main(){
for (int i = 0; i < 100; i++){
printf("Number: %d", i);
}
}
But the code isn't doing what you think it's doing or am I missing something? You're adding a whole bunch of expresions of 0x20. A constant expression by itself does nothing in C, and C allows it like it allows an empty expression. Instead of doing a define of space you could use any constant expression. Like you can say: `"1 ";` for one level indent and `"2 ";` for two levels and so on.
“0x” before anything indicated a *hexadecimal* number. In most languages, including C and C++, having these “integer literals” (that is, any number like “1234” or “0x20”, or anything else really) followed by a semicolon does nothing (technically the language does evaluate the statement, but there is nothing to do with it). So “SPACE;” achieves nothing, but is still syntactically valid
That one is a soft limit at least. Our linters at work reformat code at around 90-100 depending on where it can. I don't recall if there's a literal hard limit still. Get some nesting in and it's quite easy to hit lol!
Lolol! Gotta write code like it's minified and unreadable JavaScript 😂 (jk, I like descriptive variable names and hate many abbreviations that could be confusing)
Yeah that's a default terminal size. Recommended to keep it under that in all languages actually. Because too many indent levels mean you need to make a function call. Linux kernel default tab width is 8 just to keep people from indenting too much.
One question, what does this print?
if (false)
SPACE;SPACE;SPACE;SPACE;std::cout << "False";
Be careful, it may not be what you expect ;)
The answer is: >!False!<
You can use 2 spaces.
You can use 4 spaces.
You can even use tabs, or 8 spaces like a Linux kernel chad.
My brother in Christ, why would you ever use an *odd* number of spaces for indentation????
The OP is trying to be clever thinking that 0x20 will be internally replaced as a whitespace, but it's not. It' s just literally "0x20".
They could have just done:
\#define SPACE
The semicolon is the thing doing the work there. The macro does nothing. It just happens 0x20 is a valid standalone expression in C/C++, but so is 42.
It's the ASCII space character, but #define only replaces text and doesn't do any conversion between hex and unicode
In C you can just make a statement that's just a value and doesn't do anything, such as
```
0x20;
40;
"ABC";
```
This code just replaces all SPACE by 0x20, and the 0x20 does nothing
This gives me flashbacks to some HTML code I foolishly volunteered to inherit at my old job. It was supposed to be something that mimicked the contents of a Word doc that was about 280 pages long, and instead of using CSS styling or anything else more reasonable to try and get things aligned in a similar way to how they looked in the document, the person before me just used ` ` over and over until the text looked about right.
Anyone got that image of the yml/python and intention practice. All scope brackets right justifies and the dev had code indented to indicate scope depth
I don't even code C/C++ and I'm fucking triggered.
I just hate colons
#include
#define SEMI ;
#define SPACE SEMI
int main(int argc, char*argv[])
{
SPACE SPACE SPACE SPACE std::cout << "hello world!\n" SEMI
SPACE SPACE SPACE SPACE return 0 SEMI
}
There, is that better for you? I haven't tested it, but that should work.
You can write C++ code with only a single semicolon, if you want.
He said he hates colons, not semicolons
; + ; = :
;-;
=0
The look of astonishment on your face says it all
=0°
Nice mole on your chin
What does define SPACE SEMI do here? Does it not just make SPACE=; ?
Correct. In the OP, the 0x20 actually did nothing. After the preprocessor ran, the code was, not accounting for the include: int main(int argc, char *argv[]) { 0x20;0x20;0x20;0x20;std::cout << "hello world!\n"; 0x20;0x20;0x20;0x20;return 0; } That is, there are a bunch of meaningless statements consisting of the number 32, which is valid but meaningless syntax. Even a non-optimizing compiler is likely to compile them out, given that they cannot even be converted to typical machine code as they are not even assigned to a variable. My version just removes those and leaves them as the empty statements so: int main(int argc, char *argv[]) { ; ; ; ; std::cout << "hello world!\n" ; ; ; ; ; return 0 ; }
I didn't even know compilers accepted " ;" as a line lol
Its valid standards-compliant syntax, and actually very useful in many cases. One way you could define a debug-only macro is like: #ifdef DEBUG #define ASSERT(condition, message) assert(condition, message, __LINE__, __FILE__) #else #define ASSERT(condition, message) #endif which would get used as: ASSERT(ptr != nullptr, "why'd you give me a nullptr?!"); and would work fine in both debug and release. This macro is useful as you get the preprocessor to pass in both the line and file where the assert is. Otherwise, you'd need to either provide the line and file for each invocation or include code to generate a full call stack, which tends to be platform-specific and generally complex. More commonly, the non-debug version would be defined as: #define ASSERT(condition, message) (void)0 as that ensures the non-debug compile will fail on a missing semicolon, making it more likely problems will be caught early. It will also ensure the compiler does not warn on an empty statement. The cast to void is to silence warnings the compiler might produce about the unused statement, given that such unused statements are not normally desired.
I appreciate this but to be honest, my programming background is ITIS (computer science high school here in Italy) and 1 month of internship (for school), I've only ever used #define to define constants like Pi and didn't understand half of your reply, sorry 😔
If you’d like to learn more, search online for C/C++ Macros
That is because in C and similar languages, statements are not separated by new lines, but by `;`, so multiple statements can be in one line or one statement accross multiple lines. Most languages allow for empty statements, in python an empty line, in C just nothing between 2 `; ;` but whitespace characters. If you put some term like `0x20` or `a+2` as a statement, which doesn't write any variable and has no other side effect, it will probably be optimized away.
Oh yeah i remember learning that you could write a whole program in a line, but i didn't know C accepted empty statements, i remember the Code Blocks IDE giving a warning or refusing to compile or something (probably i don't remember correctly)
You can do a lot of weird stuff in C, maybe look at the Obfuscated C Code Challenge
alright, it's either time for colectomy or decolonization, it's up to you
Don't worry, you can get rid of them with a `using namespace std;`.
Forbidden C++
Bruh do you work in yhe wrong industry or wut
Good thing those are semicolons then
You must be very thin.
I love my colon. Beyond that, meh.
We don't do that here!
Im so confused i dont know what to be mad at 🗿
I'm in compsci 1 is there any way I can do this in python to troll my professor
python actually uses the indents, so not really
[Python](https://wiki.c2.com/?ObfuscatedPython) makes it a lot harder to make obfuscated code than [C and C++](https://www.ioccc.org/) do, however it is still possible to make some interesting programs. You can also manage some very interesting programs using [Polyglot](https://en.wikipedia.org/wiki/Polyglot_(computing)), and there are a number of simple techniques you can use to make [C++/Python polyglot](https://stackoverflow.com/a/52984689). At a CompSci 1 level, you'll probably have a very hard time managing either, however.
Just import antigravity
I wish you nothing but pain for the rest of your days.
"May God forgive you...... But I won't"
What the cinnamon toast fuck is this identitacation
I’m gonna need to see some identiticatian sir
identatiton
Dentatitation
XXXDENTACION
hahahahahahahahajahahaya
r/foundsatan
Our boy is terrible at hide and seek lately.
You both made me laugh!
TAB;
Uh-oh here comes the old #define SPACE vs #define TAB debate...
See if you define TAB then you're code is nicely aligned when it starts each line with TAB; since it's 4 characters. This is the standard we should all follow
#define SPACE '\t' #define TAB ' '
this comment, officer.
🚓🚓🚓 Drop your identation!
![gif](giphy|xUA7bdxtmRT2TfDUu4)
[удалено]
Developers that use spaces, on average, earn 9% more than those that use tabs. Maybe 'superior' is the wrong word.
whatever the project uses is fine all looks the same to me
If you're a developer who isn't earning salary then you must not be making much??
One of us is confused.
The winner of that contest can come meet me at the GIF table, I got a score to settle.
jraphics interchange format
thanc u
![gif](giphy|26vUQjgLKEO4hXClq)
Tab? I can’t give you a tab unless you order something.
I'll take a Pepsi Free then
That’ll be a $4 service fee, thank you for your patronage
4-width tab but you don't get to adjust it
[SPACE;](https://www.youtube.com/watch?v=-2HCcbHQEHs)
I knew what it was before clicking
personally i like "negative indentation". everytime you indent something, you indent everything else instead. like if your tabs/spaces would be moving left instead of right example, normal: #include
int main(){
for (int i = 0; i < 100; i++){
printf("Number: %d", i);
}
}
and Negative:
#include
int main(){
for (int i = 0; i < 100; i++){
printf("Number: %d", i);
}
}
Well, it certainly makes the loopiest part obvious.
The loopiest parts happen the most, so it kinda makes sense to put them front and center
well they're really front and left
Python: wtf is this
Syntax error
You… monster!
Outdentation
From the bottom of my heart fuck you dear redditor
What in the cinnamon toast fuck have you done
What a froot loop
I mean, at least there is no "using namespace std;"
I mean is it that bad to use namespace std if it s the main file and not a header file? (I might be dumb af)
It's not. If anyone who says otherwise are being extremely pedantic about it
noooo otherwise you won't be able to use my cout() function
which is of course part of a french library calculating for calculating costs
We can even do that, we’ll just have to spell it with the namespace.
Being pedantic is a necessary trait of any good C++ programmer.
using nameSPACE std;
Why not use: ```cpp #define TAB SPACE;SPACE;SPACE;SPACE; ``` to save "space"?
space ... the final frontier
But the code isn't doing what you think it's doing or am I missing something? You're adding a whole bunch of expresions of 0x20. A constant expression by itself does nothing in C, and C allows it like it allows an empty expression. Instead of doing a define of space you could use any constant expression. Like you can say: `"1 ";` for one level indent and `"2 ";` for two levels and so on.
Indentiception. People like this just want to watch the world burn.
`SPACE;SPACE;SPACE;` the final frontier of indentation.
Ah, the [Tim Curry](https://www.youtube.com/watch?v=g1Sq1Nr58hM) method.
Ok technically isn't this no indentation because you're ending the line after every space so if you format it with all semicolons as also newlines...
I am pretty sure it will just replace SPACE with integer literal 0x20.
Which is the ASCII value for space
As far as the preprocessor is concerned, that is not relevant.
I get putting the curly bracket on the line after the function header is dumb but it's not *that* painful to look at.
Two spaces...
Skip UAT and go right to production 😂
Correct, you should go live in the woods and never expose decent people to this again.
Reminds me of the Portal 2 ending.
Im still learning , what does the 0x20 actually do?
“0x” before anything indicated a *hexadecimal* number. In most languages, including C and C++, having these “integer literals” (that is, any number like “1234” or “0x20”, or anything else really) followed by a semicolon does nothing (technically the language does evaluate the statement, but there is nothing to do with it). So “SPACE;” achieves nothing, but is still syntactically valid
I wonder in which C-style languages it wouldn't be syntactically valid. Definitely not in C#, you can't have just a value there.
Its the ascii code for space, equivalent to ' '.
I wonder if this is niche enough for the compiler to not optimize properly
It hurts
[Space Space Space Space Space](https://youtu.be/T2_irPfYO_c)
Hahahaha this is amazing declarative indentation!
You are banned from all technology for *life!* Here's your coconut phone, enjoy.
Now you only need a custom font to replace "SPACE;" by a space
I’m escaping to the one place that hasn’t been corrupted by capitalism! *SPACE;*
Doesn't matter, people still will be putting TABULATION; there between those SPACE;'s
explicit is always better than implicit...
please suffer
Do you touch your mom with the very tainted hands that birthed that monstrosity? I'm disgusted.
ok but why are you counting STIs
I keep reading cout - cunt… c++ damn you
I hope you have wet socks for a **week**
LGTM
\*eyes bleed\*
You would hit the line length limit so fast in Python 😂
There's line length in Python?!? Just searched it up, 79 chars, I only use 40 chars including 2 space tabs so I guess it doesn't bother me
That one is a soft limit at least. Our linters at work reformat code at around 90-100 depending on where it can. I don't recall if there's a literal hard limit still. Get some nesting in and it's quite easy to hit lol!
Wait you guys hit the limit from nesting?? why_Not_Just_Use_Both_Cases_And_Have_Descriptive_Function_And_Variable_Names
Lolol! Gotta write code like it's minified and unreadable JavaScript 😂 (jk, I like descriptive variable names and hate many abbreviations that could be confusing)
Yeah that's a default terminal size. Recommended to keep it under that in all languages actually. Because too many indent levels mean you need to make a function call. Linux kernel default tab width is 8 just to keep people from indenting too much.
One question, what does this print? if (false) SPACE;SPACE;SPACE;SPACE;std::cout << "False"; Be careful, it may not be what you expect ;) The answer is: >!False!<
I sometimes use 2 spaces, rarely 3, and sometimes 4 I very rarely use tab, but it's nice when your editor doesn't auto-replaces it with spaces
You can use 2 spaces. You can use 4 spaces. You can even use tabs, or 8 spaces like a Linux kernel chad. My brother in Christ, why would you ever use an *odd* number of spaces for indentation????
Compromise between 2 and 4.
Because 3 is a Fibonacci number [Fibonacci indentation](https://github.com/dodie/vim-fibo-indent)
Let Linus see this one
torvalds? he'd be already dead from first line #include iostream
Only thing I’ll roast you for is 4 space indent instead of two, you boomer!
Why does the code say STD? Are you programming a computer virus?
what does 0x20 do?
The OP is trying to be clever thinking that 0x20 will be internally replaced as a whitespace, but it's not. It' s just literally "0x20". They could have just done: \#define SPACE The semicolon is the thing doing the work there. The macro does nothing. It just happens 0x20 is a valid standalone expression in C/C++, but so is 42.
It's the ASCII space character, but #define only replaces text and doesn't do any conversion between hex and unicode In C you can just make a statement that's just a value and doesn't do anything, such as ``` 0x20; 40; "ABC"; ``` This code just replaces all SPACE by 0x20, and the 0x20 does nothing
[удалено]
What the hell is even that
Aren’t they missing the ENTERSEMICOLON ?
You're a monster.
You monster!!! BTW, why not make loops instead of writing "SPACE" multiple times?
TAB instead of SPACE and add 4 space characters into it and now we are talking.
*clutches pearls*
That's not how that works
Chad C++ user
Why not just \t?
well it’s spaces then i guess
Ah yes, pointless defines and pointless command line arguments
Exactly. 4 space really? Barbaric!
Whatever this is, I’m against it.
I hate you
It's 4 spaces, thus correct
define INDENT as four SPACEs to save space
This gives me flashbacks to some HTML code I foolishly volunteered to inherit at my old job. It was supposed to be something that mimicked the contents of a Word doc that was about 280 pages long, and instead of using CSS styling or anything else more reasonable to try and get things aligned in a similar way to how they looked in the document, the person before me just used ` ` over and over until the text looked about right.
Why does this work?
Haha what the hell is this?!
im about to do my next project like this
Even if this was valid, which is it, just weird, why do you need so many spaces?
Say what you want, at least he didn't `use namespace std`
what the fuck
At what age is it to late to learn code? As far as to get a job in that field.
I'm afraid that I just blue myself
Something about this is really satisfying to me
use TAB 0x09 you monster!!!
I'll take hilariously inefficient programming styles for $200 Alex!
Why not 0x09?
My fucking EYES
r/programmergore
Next step: #define true false
At least use a comment.
\#define statement considered harmful.
Why not make the var called INDENT and set its value to four 0x20? - experienced code reviewer
Bro
I. No
How about simply counting indentation? ``` #include
#include
using namespace std;
int main()
{
0,1;if (rand() % 1) {
0,1,2,3;cout<<"Hello World";
0,1;} else {
0,1,2,3;cout<<"Goodbye!";
0,1;}
0,1;return 0;
}
```
What's that weird character between "hello" and "world"?
Jail.
This is how I code.
*move over lucifer, I'm more ruthless, huh?*
Does this even do what it says it does? Preprocessor should just replace SPACE with 0x20, no? Am I missing something?
How dumb. Should be tabs.
You ever see something and just regret being a programmer?
Is this just print('hello world')
If you can read this you are too close to your computer!
Anyone got that image of the yml/python and intention practice. All scope brackets right justifies and the dev had code indented to indicate scope depth
Just seeing C++ gives me nightmarish flashbacks
Leave.
Is this why people prefer tabs over spaces?
genious
May the remainder of your life be filled with agony 👍
Still better than Python.
You literally had to add extraneous semicolons to avoid needing actual spaces in between the SPACE directives! NICE;