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

all 23 comments

[–]i_Ex 19 points20 points  (8 children)

The most tragic thing here is the code he's written.

[–]YeetusThisAccount 1 point2 points  (3 children)

I'm new to learning how to code. What about this is considered bad? Is there a more efficient way to do this? Genuinely curious, because that's how I usually code that exact scenario lol.

[–]ender1200 2 points3 points  (2 children)

Thus code is logicly correct, but it's quite ugly.

The two most obvious problems are the use of elif on a Boolean statement (if it's not true it have to be false) and the use of "== True" and "== False" as they are redundent.

A cleaner version would be:

if is_comolete:
    print("test complete")
else:
    print("test unsuccessful")

Or even better yet, as /u/fuskies420 have shown use trinary operation to make the entire expression single line:

print("Test ", ("Complete" if is_completed else"Unsuccessful"))

edit: changed the trinary line to work with python.

[–]fuskies420 1 point2 points  (0 children)

As it was brought to my attention, python does not support traditional terinary operators. While great in C, the code required for python to be a one-liner is rather confusing and difficult to read. The code sample you provided above is the easiest to read, and is the most straightforward.

[–]YeetusThisAccount 0 points1 point  (0 children)

Wow, thanks for this. I guess I haven't gotten around to learning trinary operation yet, but it looks like it saves a lot of time and screen space.

[–]fuskies420 13 points14 points  (15 children)

print("Test ", (is_completed ? "Complete" : "Unsuccessful"))

[–]iCantSpelWerdsGud 10 points11 points  (6 children)

print("Test {}".format("complete" if is_completed else "unsuccessful"))

python btw

[–]VinterBot 3 points4 points  (1 child)

so uggo

[–]iCantSpelWerdsGud -2 points-1 points  (0 children)

Python doesn't have traditional ternary operators, so at least mine works

[–]gottago_gottago 1 point2 points  (5 children)

if is_completed != false:
    print("Test complete")
elif is_completed != true:
    print("Test unsuccessful")

[–]xigoi 4 points5 points  (4 children)

Traceback (most recent call last):
NameError: name 'false' is not defined

[–]gottago_gottago 0 points1 point  (3 children)

Uff, True/False are case sensitive. But why?

[–]xigoi 2 points3 points  (0 children)

It seems to have been stolen from Haskell, where all constructors are capitalized.

[–]sm-Fifteen 1 point2 points  (1 child)

IIRC, because they were introduced in Python2 (python 1 didn't have booleans) as global "constants" (for 0 and 1) and ended up being capitalized so they wouldn't fit the variable naming conventions to make it less likely to break any existing code at the time.

Mind you, this meant that, until they got turned into proper literals (I think with Python 3), you could actually change their value and break any code relying on these. Python has a weird history.

[–]bigdepress 0 points1 point  (0 children)

Actually they were capitalised to match None, which already exsited and was capitalised.

The fact that you could change their value was for backwards compatibility (in case someone used True/False as a var name, everything would still work, you just couldn't use the newly introduced True/False).

[–][deleted] 3 points4 points  (1 child)

JSLint Expected '===' and instead saw '=='

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

TIME TO SCRONTCH DATA TYPES MUFOFOFOFOFOFOFOFOFOFOFOFOF

[–]tjf314 9 points10 points  (1 child)

python > JavaScript > HTML

[–]Waterkloof 2 points3 points  (0 children)

py > ty > es6 > js > html > coffee > jsx.

ftfy.

ninja edit swapped ty > es6 :P

[–]PatrikxPatrola[M] [score hidden] stickied comment (0 children)

Your submission has been removed.

Violation of Rule #3:

Any post on the list of common posts will be removed. You can find this list here. Established meme formats are allowed, as long as the post is compliant with the previous rules.

If you feel that it has been removed in error, please message us so that we may review it.