r/shittyprogramming • u/doctorhow95 • Jun 28 '15
Python Function to determine if someone has a life or not [xpost /r/python]
46
u/flarn2006 Jun 28 '15
def has_a_life(outside_activities):
return outside_activities > 27
u/DreamLimbo Jun 29 '15
Legitimate question: Am I wrong in thinking that this is about just as readable as the code on the slide? Is it really bad practice to use an if-else statement for returning True or False like that?
14
u/mnbvas Jun 29 '15
I'd consider this practice horrible, for me it adds nothing but 3 pointless lines that you have parse when reading.
but then I enjoy assembly, so YMMV
2
Jun 29 '15
If it's true then it's true, or else if it is false, then it's false. Yeah, it's fucking stupid.
1
1
u/Scaliwag Jun 29 '15
It's as simple as if you can understand the way
ifwould behave then you should also be able to understand what thereturndoes. So no need for the other stuff.8
u/pie-oh Jun 29 '15
Preface: Ruby dev, and haven't touched Python in near 7 years.
Surely outside_activities is an array though, and thus you'd need the equivalent of #length ?
15
u/Rothaga Jun 29 '15
You could interpret it any way. We have no idea how outside_activities is being passed. And there's really no point in speculating either.
3
1
6
1
u/stone_henge Jun 29 '15
Surely? Maybe it's just a number. Perhaps it is an object that overloads the comparison operators. There is no information about the type so you can't know. But it surely isn't a regular list unless an exception is desired.
1
u/pie-oh Jun 29 '15
In my experience in naming variables, a plural suggests an array. (Remember I'm from Ruby, where Rails' model conventions are pluralised arrays.)
2
2
5
19
u/romulusnr Jun 29 '15
if (preferred_language == python):
return false0
Jun 29 '15
[deleted]
3
u/guthran Jun 29 '15
You're just jealous of the superior styling
3
u/Saucebergenstein Jun 29 '15
And readability!
4
u/romulusnr Jun 29 '15
And spending hours poring over code that doesn't work until...
"Oh."
[TAB]runs perfectly
4
u/LondonNoodles Jun 29 '15
If you spend hours poring over code that doesn't work, when the python interpreter tells you "IndentationError at line x", maybe you shouldn't code at all.
10
u/lelarentaka Jun 28 '15 edited Jun 28 '15
I passed in a PDF of my yearly scrapbook with all the pictures and journal entries of me mountaineering down the Andes as well volunteering at my local church and feeding the homeless.
The function returned false. It is obviously buggy.
7
u/MagicalVagina Jun 28 '15
Fucking useless "else".
50
u/mrwonko Jun 28 '15
Fucking useless
if.41
u/MagicalVagina Jun 28 '15
So much. Return outside_activities > 2 for fuck's sake.
44
u/Kattzalos Jun 28 '15
return (outside_activities > 2) ? true : false;41
u/stormcrowsx Jun 29 '15
You managed to get shitty code downvoted in /r/shittyprogramming. slow clap
15
16
u/immibis Jun 29 '15
It was supposed to be >=. With that in mind...
return (outside_activities & 4294967294) != 0 ? true : false;7
u/choikwa Jun 29 '15 edited Jun 29 '15
return (outside_activities--) ? outside_activities : outside_activities
7
u/immibis Jun 29 '15
should be
return (!outside_activities) ? outside_activities : outside_activities - 1;or
return outside_activities ? outside_activities - 1 : outside_activities;It even scales recursively to higher numbers! For >=3:
return (outside_activities ? outside_activities - 1 : outside_activities) ? (outside_activities ? outside_activities - 1 : outside_activities) - 1 : (outside_activities ? outside_activities - 1 : outside_activities);1
u/stone_henge Jun 29 '15 edited Jun 29 '15
while ((1 == 1) == true) { // Loops while (1 == 1) == true return !(outside_activities / 3 == 0); // Returns !(outside_activities / 3 == 0); break; // Breaks the loop }
1
u/x-postbot Jul 18 '15
Here is the x-post from /r/Python that the title refers to;
x-post linker v1.3 coded by /u/dynabeast.
-10
0
Jun 28 '15
[deleted]
33
u/deanf Jun 28 '15
Totally agree with this one. I have always made it clear at work that our evenings belong to us and down time is unquestionable. Juniors will always feel bad leaving before you, so make their life easier and tell them to leave if you can't.
I worked 2 years in a miserable job where people worked 8:30 - 6:30 (yet they magically billed the client 7 hours a day), I would leave at 6 and get frowned upon.
Since that job I've always been staunch about staying back, especially now because of my son. I always make a huge point that I'm fine if overtime is needed, but I do that shit from home or pre-9AM.
21
u/massenburger Jun 28 '15
Thank you for being part of the change we need in corporate America. My current boss is almost exactly like you, and I love it. He told me in my first review that he values programmers who can get their assigned work done during work hours over programmers who stay late.
I feel like some people stay late at work just to look good, even if they don't have work to do. From the moment I get into work until the moment I leave I'm hard at work and I get all my shit done on time every time and only very rarely have to stay late. I get home and spend time with my family, and don't think a thought about work until the next day. I hope we can get to a place like this in society someday, instead of this mindset of the longer you work, the better of an employee you are.
1
Jun 30 '15
I stay late because that's whet my best work is done. I also come in late to compensate. :D
3
u/GeorgeRRZimmerman Jun 29 '15
I didn't.
Wrecked my health. Lost my job. Suffer from agonizing anxiety now. Every time I think about updating my dice profile or creating a linkedin or sending out resumes I get so messed up that it wrecks the rest of my day. The only thing that works out for me is my wonderful wife.
Kudos to you for learning to say no, for staying staunch about how much of yourself you give up. At the end of the day, if what you need to get done outside of overtime can't be done without overtime, then the timelines are bad or you're working short. I tried squeezing blood from a stone, I only squeezed out my own.
4
u/deanf Jun 29 '15
I've been in your shoes before too man. Early in my career I suffered chronic anxiety because of overworking and being belittled on a daily basis. That's part of what keeps me strict on my work boundaries, I sometimes feel myself heading down that path and I make a correction.
I'd definitely be a few steps ahead in my career if I did make life sacrifices but I do what I can to keep myself away from that shit place in life. For example, the client asked me to stay back tonight, so I said I'd arrive early tomorrow. I got to get home on time, have dinner, see my son. I just wont have that lengthy morning time-wasting routine like i usually do.
1
100
u/dkms0t Jun 28 '15
ITT: The fizzbuzz effect, where people offer their superior implementations to beginner-level code without paying attention to context. It's a live talk people, the code is meant to be read like English.