this reminded me of a python code IN OUR OFFICIAL SCHOOL BOOK the same book that had python oop in it so the book was kinda advanced. So the code’s purpose was to output wether the current minute is odd or not and the code was something like:
import someLibrary
minute = someLibrary.aFunctionToGetTheMinute()
odd = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,37,39,41,43,45,47,49,51,53,55,57,59]
if minute in odd:
print(“the current minute is odd”)
else:
print(“the current minute is even”)
This could make sense if describing the logical components and list interactions, so long as a proper caveat is given that there are objectively better methods of doing this.
It’s a good thing to distill concepts into something kinda real world.
this code was in a section about the library itself and what we can do with it, i think the library was date or something. Also we took modulo like 2 grades before that
import random
from string import ascii_lowercase, ascii_uppercase, digits
count = int(input('Enter the Number of Codes you want: '))
all_characters = ascii_uppercase + ascii_lowercase + digits
for _ in range(count):
first = random.choice(ascii_uppercase)
rest = random.choices(all_characters, k=6)
print(f'AM{first}z{rest}')
Honestly? Kind of a fair point. I think it's better to write code like this then refactor the repeated parts. What I've seen other people do is create 10 different objects based on vibes and hope that it's actually what you needed.
Maybe he's getting paid by the line of code. Or maybe it's an assignment for class and he wants it to look so complex that the teacher will never notice. I mean, we had to write an encryption/decryption program when I was in... probably C++ and Java, and some of the stuff the classmates came up with was just bonkers. One guy was like, "So, what I do is, I save the plaintext in a separate file and just put garbage on the screen and say it's encrypted." And I'm like, "You know the teacher is going to look at your code, right? And you know that he knows how to read code, right?"
no-one has ever actually got paid by line of code. This is an urban myth!
The person who wrote this is either the result of a bootcamp or someone who doesn't have a proper training in programming. I've seen data analysts and data scientists write code like this in Python.
I reviewed a code one time with 28 Boolean variables and if-else statements to check the values stored in those variables... just to flip them!
To have done that, this must be one of their first projects, and they don't know what searching means and/or never thought that there might be a better way than that.
Ok I can kinda understand digit 3 and digit 5, but why did the person making this copy paste digit 5 rather than just writing “random.choice(digit_5)” again?
Another post in the comments gave a good explanation. Another issue than the repeat arrays is that they’re inside the whole loop, so they’re getting reinitialized every time the whole loop repeats itself.
I'd just generate random numbers in the range of the ASCII values representing the characters I want. Also, definitely do not create constant arrays inside a loop, they'll be recreated every time it runs.
Just generate random ints and map them to the three buckets above & cast as char. Even in C, that function would be less than 10 LOC, and you could probably do it in 1 in Python.
254
u/HoraceGravyJug Oct 04 '22
I seriously hope this is someones demonstration of exactly how not to go about generating keys...
176
u/Motorslam99 Oct 04 '22
DRY Principle: “Ight imma head out”
98
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Oct 04 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
88
u/varsityvideogamer Oct 04 '22
73 lines for that is gnarly
44
u/almanna3i Oct 04 '22 edited Oct 04 '22
this reminded me of a python code IN OUR OFFICIAL SCHOOL BOOK the same book that had python oop in it so the book was kinda advanced. So the code’s purpose was to output wether the current minute is odd or not and the code was something like:
35
u/MyPronounIsLamp Oct 04 '22
Settle a bet for me, what's git say the commit date is?
122
u/No-Witness2349 Oct 04 '22 edited Oct 04 '22
Bruh
24
u/[deleted] Oct 04 '22
Hey, at least it’s KISS, with super strong emphasis on the last S ;)
13
u/AnotherCableGuy Oct 04 '22
Some people just want to see the world burn
8
u/Darkcr_ Oct 04 '22
if you're gonna do it like that at least use one array
8
u/molossus99 Oct 04 '22
When the boss is tracking productivity by keystroke count
6
u/Symanthec Oct 04 '22
Based
6
u/[deleted] Oct 04 '22
Is there a reason digit 4 is missed?
9
u/Flaky-Following-4352 Oct 04 '22
I'll underatand only if someone is a beginner or is being paid by line
4
u/Salty_Carpenter_2308 Oct 04 '22
Jesus Christ if i needed to check this code I'll just perform to kill my self.
(Sorry for my bad english im nederlands and portuguese so sorry if i miss spel)
3
u/shinydewott Oct 04 '22
Ok I can kinda understand digit 3 and digit 5, but why did the person making this copy paste digit 5 rather than just writing “random.choice(digit_5)” again?
3
u/keijodputt Oct 04 '22
It looks like Galaxian! I'll see myself out
3
u/MIfoodie Oct 04 '22
I’m new to coding and this is how I would do it…
What would be a more efficient way? Only using one table/array?
3
u/robin_888 Oct 05 '22
I'd like to point out that
imust be initialized even before theinput-statement.3
u/CaitaXD Oct 05 '22
Tell the python interpreter is not gonna allocate a new list every iteration please
5
u/assets_ Oct 04 '22
When you get paid by line
2
u/Dragon20C Oct 04 '22
Someone must of been sleepy lol
1
u/Double_Ad_2824 Oct 04 '22
An enigma wrapped in code, wait what.
1
u/iGotAnxiety420 Oct 04 '22
security Trust issues
1
u/[deleted] Oct 04 '22
Alright, smart guy, let's see YOU have a crack at it!
1
u/Vesondor Oct 04 '22
This is down horrendous
1
u/LivingInAnIdea Oct 04 '22
Nah no way, how does anybody even think of this. What?!
1
u/AorticMishap Oct 04 '22
...why
1
u/[deleted] Oct 04 '22
Oh no wtf
1
u/[deleted] Oct 04 '22
I hope to god that it was made as an example and not a legitimate attempt at generating keys
1
u/1NSAN3CL0WN Oct 04 '22
Digit 5,6,7,8,9,10 are all copy pasta.
So pretty much the worst was just getting one of them out.
1
u/[deleted] Oct 04 '22
At least it's consistent 😂
1
u/The_Pantless_Warrior Oct 06 '22
Regex to the rescue!
1
u/lmux Oct 14 '22
Coder must have been paid by num of lines
1
u/bravopapa99 Oct 30 '22
Um ,er, at least it's self-documenting....
1
u/Rogoreg Nov 11 '22
I see many comments being paid by line, but why would they do that? The less code, the more efishenci.
I spelled it wrong on purpose 😂
1
u/Apprehensive-Profit2 Nov 12 '22
wow i feel batter about my self
-29
u/typehyDro Oct 04 '22 edited Oct 04 '22
Looks solid to me r/lostredditors
Edit - look at all these downvotes… was a joke fellas lol