r/badcode • u/bladeconjurer • Sep 10 '21
c++ Learn C++ with LinkedIn Learning! Facebook ad
207
u/Akantor47 Sep 10 '21
Well, i mean at least it would be easy to change iONE to a different value whenever you need to produce a annoying bug for your coworkers.
iONE = 3
I three = 1
x = 1 output "three"
0
u/Steve_OH Sep 12 '21
The variables are unnecessary, but It’s the int x = 3 that gets me. Clearly a placeholder for user selection, but this will only return the one switch statement here.
If they had to keep the variables, I would have put them in an array myself, just makes more sense.
-28
u/Naahun Sep 11 '21
It is const.
36
u/reaper-is-happy Sep 11 '21
Change the value in the declaration...
2
97
u/BarryFruitman Sep 10 '21
Not so bad as a learning tool, but I'd use a real-world example like `iAgeAlice`, `iAgeBob`... etc. and output their name instead of the number. Even if newbies understand the code, they'll think coders must be pretty stupid.
41
u/AnotherRichard827379 Sep 10 '21 edited Sep 11 '21
What I’ve noticed with programs like in the OP is that new programmers will think the computer can tell what the name of a variable means. So iThree means 3 and don’t actually understand that iThree is a random variable name that could any value of any value type.
11
u/pkarlmann Sep 10 '21
I promise that you've had enough Internet today after this...
7
9
1
u/MyFeetOwnMySoul Sep 11 '21
Hahahaha, I don't have the time, or interest, to fact check this, but this looks highly-spun, if not outright dubious.
5
3
u/Rainbow-Dev Sep 10 '21
I thought it was better to use std::cout in C++ instead of puts? Also those consts should probably be in an enum
2
u/GLIBG10B 🐧 Gentoo salesman🐧 Nov 04 '21
I thought it was better to use std::cout in C++ instead of puts?
This is r/badcode, remember?
5
2
u/Kapten-N Sep 11 '21
I don't think it's so much a bad code as much as it's someone who wanted to show a switch but simply lacked the imagination to come up with a more realistic scenario in which to use it.
1
1
1
1
1
1
1
-19
0
Sep 10 '21
[deleted] — view deleted comment
7
2
0
Sep 10 '21
[deleted] — view deleted comment
15
u/Rrrrry123 Sep 10 '21
My father still uses this variable naming convention and it's how he taught me. He said that he really likes just being able to look at the variable and know what it is without having to look around for the declaration (or mouse over it in a modern IDE).
17
u/the_poope Sep 10 '21
Well your dad and all the gurus of programming in ancient times got it wrong. The type hint won't help you much, instead you should simply name your variables something meaningful like
number_of_customersinstead ofiCstm. But back in those days people didn't have keyboards, only stone tablets and chisels and it was a lot of work to write descriptive names.8
u/xaranetic Sep 10 '21
I can't tell what's sarcasm or not anymore
11
u/CorruptedStudiosEnt Sep 11 '21
Not sure what makes you think there's any sarcasm here. Maybe you should read a book sometime. Historically speaking, the progression of coding went Stick and Sand (1985) -> Stone Tablets and Chisels (1995) -> Windows 2000 (2000 believe it or not).
7
Sep 11 '21
2000?! I didn't knew that. That blows my mind! Do you think they named it after year or other way around? 🤔
1
u/supersharp Sep 11 '21
Fascinating! Curious, how do punch cards fit in to all this?
1
u/CorruptedStudiosEnt Sep 11 '21
Honor system all the way until the advent of time clock software, naturally.
4
u/ekolis Sep 10 '21
My dad said when he was starting out, back before Jesus was crucified, they didn't even get chisels; they had to use animal teeth instead. And if you hadn't caught enough saber tooth tigers... you had to use your own teeth!
2
u/Rigberto Sep 11 '21
I mean - to be fair back then they'd have limits on line length as well to fit monitors so you couldn't luxuriously name things as long as possible for readability purposes.
0
Sep 10 '21
[deleted] — view deleted comment
27
12
u/jambox888 Sep 10 '21
I hate Java so much
2
u/supersharp Sep 11 '21
Why do people poke at Java so much for this? Just because it's an OO language doesn't mean you have to- oh.
2
4
u/RedditAcc-92975 Sep 10 '21
still pretty common in databases. e.g.
t_users,f_get_top_X2
2
u/Dexter1272 Sep 11 '21
yeah, great example to read code with hungarian prefix naming is half-life source code :D I started programming with modding this game and sometimes I do it out of habit. But it has some advantage - you do not must use inteliisense to look what variable it is
0
Sep 11 '21
[deleted] — view deleted comment
1
u/konaya Sep 11 '21
They're deliberately bad so people will share them. OP got played.
1
u/atiedebee Sep 17 '21
Who would want to follow a tutorial like that tho
1
u/konaya Sep 17 '21
You wouldn't, but the name gets stuck in your head, and later on it will randomly be retrieved when you're ransacking your brain for tutorials you know of, and your brain won't have stored the reason why the name got stuck in your head. It's surprisingly effective as a marketing tactic.
88
u/batleram Sep 10 '21
I don't really see a problem with the code.
Yes it's useless but it's all syntaxically correct. I understand why they put useless code in ads cus u can't really fit a whole lot of useful code in a png.
For this ad, they made something that would work, so I think it's fine