I shit you not but one coworker I had dared call himself a data scientist and did something really similar to this. He should never have been hired. Coding in python was a requirement. I spent a good year sorting out through his spaghetti code and eventually rebuilt everything he had been working on because it was so bad that it only worked on his computer and he always pip freezes all requirements, and since he never used a virtual environment that meant we got a list of ALL packages he had installed on pip for a project. Out of those 100, only about 20 were relevant to the project.
I wish
Submitted 2 years ago by nave@lemmy.zip to [deleted]
https://i.imgur.com/31qxtlZ.png
Comments
snek@lemmy.world 2 years ago
surewhynotlem@lemmy.world 2 years ago
In prod??
Listen up folks. This is why we do code reviews. This right here.
herrvogel@lemmy.world 2 years ago
Code reviews mean fuck all when the “senior” developer doing the review is someone who implements an entire API endpoint group in one single magic function that is impossible to decipher for mere humans.
snek@lemmy.world 2 years ago
A few members of my team were reviewing codes but lots of PRs could be merged without tests passing and only about 2 people before I joined understood what cicd is, no one else believed in its importance. They thought doing otherwise would “slow down the work precess and waste time, we know what we’re doing anyway!”.
I learned a lot from having to implement best practices and introduce tests in teams that don’t give a fuck or were never required to do it. I’m amazed at the industry standards and fully understand why job ads keep listing git as a requirement.
Flax_vert@feddit.uk 2 years ago
That’s something I would do
Agent641@lemmy.world 2 years ago
Just print true all the time. Half the time it will be correct and the client will be happy, and the other half the time, they will open a ticket that will be marked as duplicate and closed.
Rouxibeau@lemmy.world 2 years ago
Reminds me of the fake thermometers being sold during the peak of COVID that weren’t actually thermometers but just displayed numbers to make people think they were.
Not_Alec_Baldwin@lemmy.world 2 years ago
I definitely have one of these.
Skyline969@lemmy.ca 2 years ago
Wow. Amateur hour over here. There’s a much easier way to write this.
A case select:
select(number){ case 1: return false; break; case 2: return true; break; }
And so on.
robotica@lemmy.world 2 years ago
Don’t forget that you can have fall-through cases, so you can simplify it even further:
switch (number) { case 1: case 2: case 3: case 4: case 5: ...
UNWILLING_PARTICIPANT@sh.itjust.works 2 years ago
Teach me
lobut@lemmy.ca 2 years ago
Just do a while loop and subtract 2 if it’s positive or plus 2 is it’s negative until it reaches 1 or 0 and that’s how you know, easy! /s
KoboldCoterie@pawb.social 2 years ago
God, it’s so obvious, you can do it in only two lines of code.
if (number == 1 || number == 3 || number == 5 || number == 7 || number == 9...) return false; else return true;
Arbiter@lemmy.world 2 years ago
Obviously you couldn’t account for every number with only two lines.
ParsnipWitch@feddit.de 2 years ago
The number of comments posting a better solution is funny and somewhat concerning.
elauso@feddit.de 2 years ago
Yeah, “just use modulo” - no shit, you must be some kind of master programmer
Enkers@sh.itjust.works 2 years ago
def is_even (num): return num in [x*2 for x in range(sys.maxsize << 1)]
goddard_guryon@sopuli.xyz 2 years ago
That won’t work tho, you need to make it sys.maxsize//2 to coerce the output into int form
robotica@lemmy.world 2 years ago
range()accepts floats, does it not?
affiliate@lemmy.world 2 years ago
amateurs
def is_even(n: int): if n ==0: return True elif n < 0: return is_even(-n) else: return not is_even(n-1)
affiliate@lemmy.world 2 years ago
here’s a constant time solution:
def is_even(n: int): import math return sum(math.floor(abs(math.cos(math.pi/2 * n/i))) for i in range(1, 2 ** 63)) > 0
spoiler
i can’t imagine how long it’ll take to run, my computer took over 3 minutes to compute one value when the upper bound was replaced with 2^30^. but hey, at least it’s O(1).
Acters@lemmy.world 2 years ago
Nice, how about bitwise & operator?
// n&1 is 1, then odd, else even return (!(n & 1));
Karyoplasma@discuss.tchncs.de 2 years ago
Don’t use recursion. Each call will need to allocate a new stack frame which leads to being slower than an iterative approach in pretty much any language.
DarkMessiah@lemmy.world 2 years ago
Just in case anyone was looking for a decent way to do it…
if (((number/2) - round(number/2)) == 0) return true; else return false;
Or whatever the rounding function is in your language of choice.
Acters@lemmy.world 2 years ago
Every bit aside for the ones bit is even, all you have to do is yet the ones bit(the far left) for it being a 1 or 0. Which is the fastest and least amount of code needed.
use bitwise &
bool isEven(int n)
{// n&1 is true, then odd, or !n&1 is true for even return (!(n & 1));
}
happyhippo@feddit.it 2 years ago
Huh?
return number % 2 == 0
That’s the only sane solution.
DarkMessiah@lemmy.world 2 years ago
Do note how I said “a decent” way, not “the best” way. Get that huh outta here.
nopt@lemmy.world 2 years ago
Or modulo %
oatscoop@midwest.social 2 years ago
private bool IsEven(int number){ return number % 2 ? false : true; }
257m@sh.itjust.works 2 years ago
number % 2 == 0 and // If integer (number & 0b1) == 0
Are the only sane ways to do this. No need to floor.
homura1650@lemmy.world 2 years ago
If you are using floats, you really do not want to have an isEven function …
UNWILLING_PARTICIPANT@sh.itjust.works 2 years ago
Take out the
elseand I’m inDarkMessiah@lemmy.world 2 years ago
Valid point.
Karyoplasma@discuss.tchncs.de 2 years ago
while (true){ if (number == 0) return true; if (number == 1) return false; number -= 2 }
SamBBMe@lemmy.world 2 years ago
return !(number % 2)
stevep@lemmy.world 2 years ago
Setting number to -1 might cause you to wait a while.
Karyoplasma@discuss.tchncs.de 2 years ago
You know, shortly after posting this I did think about whether it’s still working if I just pass the underflow that will happen at some point or if I have to fix something in that case (like subtract 1 after the underflow). I deemed it “too complicated” and would just issue a warning that my code is only tested on positive numbers.
rollerbang@sopuli.xyz 2 years ago
You have to make it easy on yourself and just use a switch with default true for evens, then gandle all the odd numbers in individual cases. There, cut your workload in half.
CancerMancer@sh.itjust.works 2 years ago
Because YandereDev is a legendary moron I can’t even tell if this is a joke or not.
mob@lemmy.world 2 years ago
How do you think even/odd detectors work? A team of coders has been working on this else if for years…
If you want to help
mbp@lemmy.sdf.org 2 years ago
I haven’t ever seen a GitHub file that big before in my life
Flax_vert@feddit.uk 2 years ago
Would be easier to make a script to write that script honestly
MolochAlter@lemmy.world 2 years ago
It’s a re-attribution of a joke tweet made by someone else.
Smacks@lemmy.world 2 years ago
Still some of YandereDev’s best code
WhiskyTangoFoxtrot@lemmy.world 2 years ago
Just do
npm install isEvenand don’t worry about it.where_am_i@sh.itjust.works 2 years ago
looks like it depends on isOdd, which is unmaintained. I have a dependency conflict, what should I do?
BeigeAgenda@lemmy.ca 2 years ago
Good job my young padawan, let me teach you about the modulo operator …
mryessir@lemmy.sdf.org 2 years ago
Actually the modulo operator is the wrong solution.
BeigeAgenda@lemmy.ca 2 years ago
No its not the wrong solution! Premature optimization is a waste of time.
Using if or case is not a solution because it is way too verbose and very easy to introduce an error.
Modulo is a solution, and using bit-wise and is another faster solution.
TheManuz@lemmy.world 2 years ago
Wrong means that it doesn’t produce the right output.
How is the modulo operator the wrong solution?
Pulsar@lemmy.world 2 years ago
realpython.com/python-modulo-operator/#how-to-che…
I just wonder why module is the wrong solution.
dwalin@lemmy.world 2 years ago
Just do a recursive funcion subtracting 2 and stoping on -1 or 0. Easy
fox_the_apprentice@lemmynsfw.com 2 years ago
dwalinIsEven(-2)
FooBarrington@lemmy.world 2 years ago
Just return
null, nobody knows whether negative numbers can be evendwalin@lemmy.world 2 years ago
Ok, thanks for the PR. I added a condition if we have an underflow we increment it instead
GoosLife@lemmy.world 2 years ago
There is absolutely no need to add a check for each individual number, just do this:
`#include #include
int main() { int number = 0; int numberToAdd = 1; int modifier = 1;
std::cout << "Is your number [p]ositive or [n]egative? (Default: positive)\n"; if (std::cin.get() == 'n') { modifier *= -1; } std::cin.ignore(std::numeric_limits::max(), '\n'); // Clear the input buffer bool isEven = true; bool running = true; while (running) { std::cout << number << " is " << (isEven ? "even" : "odd") << ".\n"; std::cout << "Continue? [y/n] (Default: yes)\n"; if (std::cin.peek() == 'n') { running = false; } number += numberToAdd * modifier; isEven = !isEven; std::cin.ignore(std::numeric_limits::max(), '\n'); } std::cout << "Your number, " << number << " was " << (isEven ? "even" : "odd") << ".\n";
}`
trashgirlfriend@lemmy.world 2 years ago
I hate this
GoosLife@lemmy.world 2 years ago
Sorry, let me try again. Here is a different attempt that uses modulo to determine if a number is odd or even:
#include #include #include #include #include #include #include #include #include #include template bool isEven(const T& number) { std::vector digits; std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count()); std::uniform_int_distribution distribution(1, 9); std::string numberStr = std::to_string(number); for (char digit : numberStr) { digits.push_back(distribution(generator)); } int sum = std::accumulate(digits.begin(), digits.end(), 0); return sum % 2 == 0; }
levi@aussie.zone 2 years ago
takeda@lemmy.world 2 years ago
And it is so light, it only requires is-odd package!
Dewded@lemmy.world 2 years ago
That one is bad, I use this one www.npmjs.com/package/is-is-is-even
Nobsi@feddit.de 2 years ago
Why even do that, just check for the opposite of www.npmjs.com/package/is-is-is-is-is-is-odd
unreachable@lemmy.world 2 years ago
left-pad PTSD intensifies
kamen@lemmy.world 2 years ago
Plot twist: it’s generated code for the purpose of the joke.
Iceman@lemmy.ca 2 years ago
OMG they can’t even!
callyral@pawb.social 2 years ago
number == 0is not handledScubus@sh.itjust.works 2 years ago
string taco = variable.ToString()[variable.ToString().Length - 1];
If (taco == “0” || taco == “2” || taco == “4” || taco == “6” || taco == “8”)
return true;
else
return false;
Im something of a coding master myself
luthis@lemmy.nz 2 years ago
Ok looks like this might be the source, and I suspect it is actually satirical. Not yanderedev, but yeah… wouldn’t put it past him.
original_reader@lemm.ee 2 years ago
Recently there was a thread trying to declare PHP obsolete.
Hard to beat this in efficiency:
function is_even($num) { return $num % 2 === 0; }
That said, this should work in most languages.
BrightHalo@lemmy.world 2 years ago
If only you could do something like…
def IsEven(number): return number % 2 == 0
Zaphod@discuss.tchncs.de 2 years ago
no way this is real
UNWILLING_PARTICIPANT@sh.itjust.works 2 years ago
We’re too swamped for that kind of thinking. Just keep typing or we’ll never make our release window
Iron_Lynx@lemmy.world 2 years ago
Even the shitposty better version has us:
- take the absolute value of the input as a variable
- while that variable is >1, subtract 2. Repeat until this is no longer true
- if it’s now 1, return true. Otherwise, return false.
kromem@lemmy.world 2 years ago
You only need to do the comparison on the last digit.
dylanTheDeveloper@lemmy.world 2 years ago
Now make it a switch case
Rentlar@lemmy.ca 2 years ago
They call me a StackOverflow expert:
nyoooom@lemmy.world 2 years ago
Rentlar@lemmy.ca 2 years ago
Damn that’s some solid optimization.
Johanno@feddit.de 2 years ago
StackoverflowException.
What do I do now?
Nvm. Got it.
if(num % 2 == 0){ int num1 = num/2 int num2 = num/2 return isEven(num1) && isEven(num2)
}
if(num % 3 == 0){ int num1 = num/3 int num2 = num/3 int num3 = num/3 return isEven(num1) && isEven(num2) && isEven(num3) }
Obviously we need to check each part of the division to make sure if they are even or not. /s
ReluctantMuskrat@lemmy.world 2 years ago
Man I love how horrible this is!
callyral@pawb.social 2 years ago
…a recursive is-even
wow