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 1 year ago by nave@lemmy.zip to [deleted]
https://i.imgur.com/31qxtlZ.png
Comments
snek@lemmy.world 1 year ago
surewhynotlem@lemmy.world 1 year ago
In prod??
Listen up folks. This is why we do code reviews. This right here.
herrvogel@lemmy.world 1 year 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 1 year 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 1 year ago
That’s something I would do
Skyline969@lemmy.ca 1 year 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 1 year 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 1 year ago
Teach me
lobut@lemmy.ca 1 year 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 1 year 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 1 year ago
Obviously you couldn’t account for every number with only two lines.
ParsnipWitch@feddit.de 1 year ago
The number of comments posting a better solution is funny and somewhat concerning.
elauso@feddit.de 1 year ago
Yeah, “just use modulo” - no shit, you must be some kind of master programmer
affiliate@lemmy.world 1 year 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 1 year 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 1 year ago
Nice, how about bitwise & operator?
// n&1 is 1, then odd, else even return (!(n & 1));
Karyoplasma@discuss.tchncs.de 1 year 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.
Enkers@sh.itjust.works 1 year ago
def is_even (num): return num in [x*2 for x in range(sys.maxsize << 1)]
goddard_guryon@sopuli.xyz 1 year ago
That won’t work tho, you need to make it sys.maxsize//2 to coerce the output into int form
DarkMessiah@lemmy.world 1 year 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.
AnxiousOtter@lemmy.world 1 year ago
Modulo operator my dude.
Acters@lemmy.world 1 year 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 1 year ago
Huh?
return number % 2 == 0
That’s the only sane solution.
DarkMessiah@lemmy.world 1 year ago
Do note how I said “a decent” way, not “the best” way. Get that huh outta here.
nopt@lemmy.world 1 year ago
Or modulo %
oatscoop@midwest.social 1 year ago
private bool IsEven(int number){ return number % 2 ? false : true; }
257m@sh.itjust.works 1 year 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 1 year ago
If you are using floats, you really do not want to have an isEven function …
UNWILLING_PARTICIPANT@sh.itjust.works 1 year ago
Take out the
else
and I’m inDarkMessiah@lemmy.world 1 year ago
Valid point.
Karyoplasma@discuss.tchncs.de 1 year ago
while (true){ if (number == 0) return true; if (number == 1) return false; number -= 2 }
SamBBMe@lemmy.world 1 year ago
return !(number % 2)
stevep@lemmy.world 1 year ago
Setting number to -1 might cause you to wait a while.
Karyoplasma@discuss.tchncs.de 1 year 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 1 year 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 1 year ago
Because YandereDev is a legendary moron I can’t even tell if this is a joke or not.
mob@lemmy.world 1 year 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 1 year ago
I haven’t ever seen a GitHub file that big before in my life
Flax_vert@feddit.uk 1 year ago
Would be easier to make a script to write that script honestly
MolochAlter@lemmy.world 1 year ago
It’s a re-attribution of a joke tweet made by someone else.
WhiskyTangoFoxtrot@lemmy.world 1 year ago
Just do
npm install isEven
and don’t worry about it.where_am_i@sh.itjust.works 1 year ago
looks like it depends on isOdd, which is unmaintained. I have a dependency conflict, what should I do?
kogasa@programming.dev 1 year ago
Extract an interface and let the consumer supply the implementation.
BeigeAgenda@lemmy.ca 1 year ago
Good job my young padawan, let me teach you about the modulo operator …
mryessir@lemmy.sdf.org 1 year ago
Actually the modulo operator is the wrong solution.
BeigeAgenda@lemmy.ca 1 year 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 1 year ago
Wrong means that it doesn’t produce the right output.
How is the modulo operator the wrong solution?
Pulsar@lemmy.world 1 year ago
realpython.com/python-modulo-operator/#how-to-che…
I just wonder why module is the wrong solution.
Smacks@lemmy.world 1 year ago
Still some of YandereDev’s best code
dwalin@lemmy.world 1 year ago
Just do a recursive funcion subtracting 2 and stoping on -1 or 0. Easy
fox_the_apprentice@lemmynsfw.com 1 year ago
dwalinIsEven(-2)
FooBarrington@lemmy.world 1 year ago
Just return
null
, nobody knows whether negative numbers can be evendwalin@lemmy.world 1 year ago
Ok, thanks for the PR. I added a condition if we have an underflow we increment it instead
levi@aussie.zone 1 year ago
takeda@lemmy.world 1 year ago
And it is so light, it only requires is-odd package!
Dewded@lemmy.world 1 year ago
That one is bad, I use this one www.npmjs.com/package/is-is-is-even
Nobsi@feddit.de 1 year 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 1 year ago
left-pad PTSD intensifies
Floey@lemm.ee 1 year ago
I always forget if is even requires is odd or the other way around.
gandalf_der_12te@feddit.de 1 year ago
Weekly Downloads: 293.319
GoosLife@lemmy.world 1 year 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";
}`
kamen@lemmy.world 1 year ago
Plot twist: it’s generated code for the purpose of the joke.
callyral@pawb.social 1 year ago
number == 0
is not handledIceman@lemmy.ca 1 year ago
OMG they can’t even!
Scubus@sh.itjust.works 1 year 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 1 year 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 1 year 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 1 year ago
If only you could do something like…
def IsEven(number): return number % 2 == 0
dylanTheDeveloper@lemmy.world 1 year ago
Now make it a switch case
Zaphod@discuss.tchncs.de 1 year ago
no way this is real
UNWILLING_PARTICIPANT@sh.itjust.works 1 year 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 1 year 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 1 year ago
You only need to do the comparison on the last digit.
wtry@lemm.ee 1 year ago
bool iseven(int number){ if (number % 2 == 0){ return true; } else { return false; } }
Rentlar@lemmy.ca 1 year ago
They call me a StackOverflow expert:
nyoooom@lemmy.world 1 year ago
Rentlar@lemmy.ca 1 year ago
Damn that’s some solid optimization.
Johanno@feddit.de 1 year 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 1 year ago
Man I love how horrible this is!
callyral@pawb.social 1 year ago
…a recursive is-even
wow