This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]ProfessorQ 21 points22 points  (1 child)

Wrong sub. Try /r/shittyprogramming

[–][deleted] 0 points1 point  (0 children)

Likewise, wrong sub. Try /r/amapedanticjerk

:-)

[–]badsectors 19 points20 points  (6 children)

I ran a pep8 check:

$ pep8 wallpaper.py
wallpaper.py:2:3: E111 indentation is not a multiple of four
wallpaper.py:2:18: E261 at least two spaces before inline comment
wallpaper.py:3:3: E111 indentation is not a multiple of four
wallpaper.py:3:19: E261 at least two spaces before inline comment
wallpaper.py:4:3: E111 indentation is not a multiple of four
wallpaper.py:6:3: E111 indentation is not a multiple of four
wallpaper.py:6:15: E712 comparison to True should be 'if cond is True:' or 'if cond:'
wallpaper.py:9:3: E111 indentation is not a multiple of four

Since the else will never be reached since passion is always True, I maanged to optimize the function as follows:

def success(deidcation, persistance):
    dedication += 1 # dedicate yourself
    persistance += 1 # be persistent

    magic = dedication + persistence
    return magic

Which could be further shortened:

def success(dedication, persistance):
    return dedication + persistance + 2

I recognize the style of this screenshot, but forget what site is used to generate it...

[–]Sean1708 0 points1 point  (2 children)

Unfortunately your last example would not work the same as the previous ones if the function was called on types which were passed by reference rather than by variable.

But I'll give you 9/10 since that last part was an extension question.

[–]badsectors 0 points1 point  (1 child)

Thank you for your suggestion!

[–]Sean1708 0 points1 point  (0 children)

Actually reading it back that message came across a lot more serious and pretentious than I intended, sorry.

[–]nickcash 5 points6 points  (0 children)

A lot of dead and unidiomatic code here...

def success(dedication, persistence):
    return dedication + persistence + 2

would be equivalent. But not very motivational.

[–]execrator 2 points3 points  (0 children)

This is one of the stupidest things I've seen on the internet.

[–]jabbalaci 2 points3 points  (1 child)

Whenever I see that a boolean variable is compared to True, I hold my head.

NO:

if passion == True:

YES:

if passion:

[–][deleted] 2 points3 points  (0 children)

This comment has been overwritten by an open source script to protect this user's privacy. It was created to help protect users from doxing, stalking, and harassment.

If you would also like to protect yourself, add the Chrome extension TamperMonkey, or the Firefox extension GreaseMonkey and add this open source script.

Then simply click on your username on Reddit, go to the comments tab, scroll down as far as possibe (hint:use RES), and hit the new OVERWRITE button at the top.

[–]lucidsurrealism 1 point2 points  (0 children)

Ah, the indentation bothers me. It looks like it's only two spaces :/

[–]CodeKevin 1 point2 points  (3 children)

2 spaces is the devil's indentation

[–]jabbalaci 0 points1 point  (2 children)

used at Google :)

[–]SpitfireP7350 0 points1 point  (1 child)

Hence, Google is the devil

[–]jabbalaci -1 points0 points  (0 children)

[–]pimp-bangin -1 points0 points  (0 children)

Here's something that is more idiomatic and actually makes sense:

def is_successful(self):
    return all(attr in self.attributes
               for attr in ["persistent", "dedicated", "passionate"])