MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/skfqjk/my_code_from_2_years_ago_when_i_first_started/
r/badcode • u/[deleted] • Feb 04 '22
27 comments sorted by
11
As you were writing these out, did you not see a pattern lol?
20 u/[deleted] Feb 05 '22 2 years ago, was when I only just started programming, back then I didn’t know about for loops or using variables as the index 6 u/[deleted] Feb 05 '22 Gotcha, my code from when I started looked worse
20
2 years ago, was when I only just started programming, back then I didn’t know about for loops or using variables as the index
6 u/[deleted] Feb 05 '22 Gotcha, my code from when I started looked worse
6
Gotcha, my code from when I started looked worse
2
So asking for a friend why is this bad and what is better than this
1 u/[deleted] Feb 13 '22 It takes up more IDE space and CPU cycles than necessary, using turn as the index of the array would be better 2 u/[deleted] Feb 13 '22 How do you write it to be simpler 3 u/taichouk Feb 13 '22 Make it one line by replacing those numbers with turn as the index 2 u/ExceedingChunk Feb 19 '22 navMeshAgent.destination = endDestinations[turn].transform.position;This does the same thing as OP's entire code. 1 u/[deleted] Feb 22 '22 Thank you
1
It takes up more IDE space and CPU cycles than necessary, using turn as the index of the array would be better
2 u/[deleted] Feb 13 '22 How do you write it to be simpler 3 u/taichouk Feb 13 '22 Make it one line by replacing those numbers with turn as the index 2 u/ExceedingChunk Feb 19 '22 navMeshAgent.destination = endDestinations[turn].transform.position;This does the same thing as OP's entire code. 1 u/[deleted] Feb 22 '22 Thank you
How do you write it to be simpler
3 u/taichouk Feb 13 '22 Make it one line by replacing those numbers with turn as the index 2 u/ExceedingChunk Feb 19 '22 navMeshAgent.destination = endDestinations[turn].transform.position;This does the same thing as OP's entire code. 1 u/[deleted] Feb 22 '22 Thank you
3
Make it one line by replacing those numbers with turn as the index
navMeshAgent.destination = endDestinations[turn].transform.position;
This does the same thing as OP's entire code.
1 u/[deleted] Feb 22 '22 Thank you
Thank you
80
I actually hope the C# compiler optimized this
5 u/6Maxence Feb 05 '22 We need an image retranscription of a human volunteer, and I'll test if it optimized it on GodBOLT. 4 u/Darkcr_ Feb 05 '22 a human volunteer did it, now its your turn to test it 13 u/6Maxence Feb 05 '22 I tested it, the compiler doesn't optimize it at all.btw, I am the human volunteer lol 2 u/luxjosh1996 Feb 05 '22 Damn I thought I was lazy 12 u/6Maxence Feb 05 '22 if (turn == 0) { navMeshAgent.destination = endDestinations[0].transform.position; } if (turn == 1) { navMeshAgent.destination = endDestinations[1].transform.position; } if (turn == 2) { navMeshAgent.destination = endDestinations[2].transform.position; } if (turn == 3) { navMeshAgent.destination = endDestinations[3].transform.position; } if (turn == 4) { navMeshAgent.destination = endDestinations[4].transform.position; } if (turn == 5) { navMeshAgent.destination = endDestinations[5].transform.position; } if (turn == 6) { navMeshAgent.destination = endDestinations[6].transform.position; } if (turn == 7) { navMeshAgent.destination = endDestinations[7].transform.position; } if (turn == 8) { navMeshAgent.destination = endDestinations[8].transform.position; } if (turn == 9) { navMeshAgent.destination = endDestinations[9].transform.position; } Fine, I did it. 4 u/luxjosh1996 Feb 05 '22 Well done you redeemed yourselfTo be clear, I would've done it if I wasn't on mobile, mastered copy-pasting all my life
5
We need an image retranscription of a human volunteer, and I'll test if it optimized it on GodBOLT.
4 u/Darkcr_ Feb 05 '22 a human volunteer did it, now its your turn to test it 13 u/6Maxence Feb 05 '22 I tested it, the compiler doesn't optimize it at all.btw, I am the human volunteer lol 2 u/luxjosh1996 Feb 05 '22 Damn I thought I was lazy 12 u/6Maxence Feb 05 '22 if (turn == 0) { navMeshAgent.destination = endDestinations[0].transform.position; } if (turn == 1) { navMeshAgent.destination = endDestinations[1].transform.position; } if (turn == 2) { navMeshAgent.destination = endDestinations[2].transform.position; } if (turn == 3) { navMeshAgent.destination = endDestinations[3].transform.position; } if (turn == 4) { navMeshAgent.destination = endDestinations[4].transform.position; } if (turn == 5) { navMeshAgent.destination = endDestinations[5].transform.position; } if (turn == 6) { navMeshAgent.destination = endDestinations[6].transform.position; } if (turn == 7) { navMeshAgent.destination = endDestinations[7].transform.position; } if (turn == 8) { navMeshAgent.destination = endDestinations[8].transform.position; } if (turn == 9) { navMeshAgent.destination = endDestinations[9].transform.position; } Fine, I did it. 4 u/luxjosh1996 Feb 05 '22 Well done you redeemed yourselfTo be clear, I would've done it if I wasn't on mobile, mastered copy-pasting all my life
4
a human volunteer did it, now its your turn to test it
13 u/6Maxence Feb 05 '22 I tested it, the compiler doesn't optimize it at all.btw, I am the human volunteer lol
13
I tested it, the compiler doesn't optimize it at all.
btw, I am the human volunteer lol
Damn I thought I was lazy
12 u/6Maxence Feb 05 '22 if (turn == 0) { navMeshAgent.destination = endDestinations[0].transform.position; } if (turn == 1) { navMeshAgent.destination = endDestinations[1].transform.position; } if (turn == 2) { navMeshAgent.destination = endDestinations[2].transform.position; } if (turn == 3) { navMeshAgent.destination = endDestinations[3].transform.position; } if (turn == 4) { navMeshAgent.destination = endDestinations[4].transform.position; } if (turn == 5) { navMeshAgent.destination = endDestinations[5].transform.position; } if (turn == 6) { navMeshAgent.destination = endDestinations[6].transform.position; } if (turn == 7) { navMeshAgent.destination = endDestinations[7].transform.position; } if (turn == 8) { navMeshAgent.destination = endDestinations[8].transform.position; } if (turn == 9) { navMeshAgent.destination = endDestinations[9].transform.position; } Fine, I did it. 4 u/luxjosh1996 Feb 05 '22 Well done you redeemed yourselfTo be clear, I would've done it if I wasn't on mobile, mastered copy-pasting all my life
12
if (turn == 0) { navMeshAgent.destination = endDestinations[0].transform.position; } if (turn == 1) { navMeshAgent.destination = endDestinations[1].transform.position; } if (turn == 2) { navMeshAgent.destination = endDestinations[2].transform.position; } if (turn == 3) { navMeshAgent.destination = endDestinations[3].transform.position; } if (turn == 4) { navMeshAgent.destination = endDestinations[4].transform.position; } if (turn == 5) { navMeshAgent.destination = endDestinations[5].transform.position; } if (turn == 6) { navMeshAgent.destination = endDestinations[6].transform.position; } if (turn == 7) { navMeshAgent.destination = endDestinations[7].transform.position; } if (turn == 8) { navMeshAgent.destination = endDestinations[8].transform.position; } if (turn == 9) { navMeshAgent.destination = endDestinations[9].transform.position; }
Fine, I did it.
4 u/luxjosh1996 Feb 05 '22 Well done you redeemed yourselfTo be clear, I would've done it if I wasn't on mobile, mastered copy-pasting all my life
Well done you redeemed yourself
To be clear, I would've done it if I wasn't on mobile, mastered copy-pasting all my life
42
What a terrible day to have eyes
22
Switch me off please
8 u/KlaireOverwood Feb 05 '22 You're saying OP should have used a switch statement? Fully agree. 4 u/Fluxriflex Feb 11 '22 Not sure if you're joking or not but navMeshAgent.destination = endDestinations[turn].transform.position; is one line. 4 u/KlaireOverwood Feb 11 '22 Not sure if you're joking or notTake a guess
8
You're saying OP should have used a switch statement? Fully agree.
4 u/Fluxriflex Feb 11 '22 Not sure if you're joking or not but navMeshAgent.destination = endDestinations[turn].transform.position; is one line. 4 u/KlaireOverwood Feb 11 '22 Not sure if you're joking or notTake a guess
Not sure if you're joking or not but navMeshAgent.destination = endDestinations[turn].transform.position; is one line.
4 u/KlaireOverwood Feb 11 '22 Not sure if you're joking or notTake a guess
Not sure if you're joking or not
Take a guess
You were n00b but playing with navmeshes. Cool.
I remember doing something VERY similar in one of my early programs. I looked at it years later and fixed it.
Wow, you could have if else and saved how many instructions per iteration at x instrs per second== 0ms.
Shall see mine when I first started, I can go up to 15
11
u/[deleted] Feb 05 '22
As you were writing these out, did you not see a pattern lol?
2
u/[deleted] Feb 13 '22
So asking for a friend why is this bad and what is better than this
80
u/Quentincestino Feb 04 '22
I actually hope the C# compiler optimized this
42
u/[deleted] Feb 04 '22
What a terrible day to have eyes
22
u/[deleted] Feb 04 '22
Switch me off please
8
u/[deleted] Feb 05 '22
You were n00b but playing with navmeshes. Cool.
3
u/havens1515 Feb 10 '22
I remember doing something VERY similar in one of my early programs. I looked at it years later and fixed it.
5
u/timNinjaMillion2 Feb 05 '22
Wow, you could have if else and saved how many instructions per iteration at x instrs per second== 0ms.
2
u/harrrrrrplllz Feb 05 '22
Shall see mine when I first started, I can go up to 15