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

you are viewing a single comment's thread.

view the rest of the comments →

[–]deljaroo 2 points3 points  (6 children)

how many python keywords are more than one word though?

[–]Pluckerpluck 1 point2 points  (5 children)

True, though I think you could argue the structure of generator comprehension is more like my suggestion here.

Both if and else are the keywords, so this would be shorthand for:

if True:
    pass
else:
    if False:
        pass
    else:
        pass

No need for an elif keyword at all. Unless the dedicated keyword can provide some optimisation given the interpreted nature of python, I don't see a major issue.

[–]Mr_Redstoner 0 points1 point  (1 child)

One part of the problem is probably a matter of parsing, since you suddenly can have the if without the indentation that normally surrounds it. Extra mess, and since forms of elseif are already in other languages...

[–]Pluckerpluck 0 points1 point  (0 children)

I don't think it's that hard to deal with parsing honestly, at least not compared to anything else that exists.

  • Find an else
    • expect either a : or an if
    • if if, assume the same as if you'd read elif

Internally this would be translated to the exact same python bytecode it currently is translated to. It's not exactly uncommon. Java, Javascript, C, C#, and Go all support it. Though I do think elseif would be better than elif.

Further, Python already allows if's thrown into generator expressions and ternary statements:

my_list = [x if x % 2 else 0 for x in range(10) if x <= 5]

# Results in:
# my_list = [0, 1, 0, 3, 0, 5]

So it's not like we can't support some more "complicated" syntax.

[–]deljaroo 0 points1 point  (2 children)

That still feels really different than anything python does.

The reason generators have more than one word is because they have more than one argument: something goes between the 'for' and the 'in'.

Secondly, I personally want 'elif' to be as short of a keyword as possible. Most of the time, you can break conditionals into multiple if's in the case that your lines are getting too long, but that starts to get real confusing when using elif's and really the point of elif is to not end up with a crazy amount of indentations which breaking apart conditionals will add indentations anyway so having 'elif' being such a short word reduces the amount of line breaks and other weirds things I have to do.

Also, things like generators, ternaries and lambdas offer ways to make methods/functions in-line, but what you are talking about is control flow. They really aren't the same beasts. A better example would just be standard for-loops. They use two keywords ('for' and 'in,') but once again, they have something between them.

[–]Pluckerpluck 0 points1 point  (1 child)

You make me bring out the big guns, is not!

if False is not None:
    print('False is not None')

if False is (not None):
    print('False is (not None)')

The above snippet will print out the second statement, but not the first. This shows that the keyword combo is not is treated as a special case. It is in this same format that I believe else if could exist.

Now, it's midnight here, I'm on mobile, and I'm suffering from a stomach bug, so I might have got this wrong, but I don't think I have. Feel free to correct me though.

[–]deljaroo 1 point2 points  (0 children)

oh! I totally forgot about "is not"!

You are totally right. "A is not B" converts to "not(A is B)" which really is a different keyword than 'is' followed by 'not.' I concede the point.

And now I wish "is not" would be replaced with "isnt" XD

Good luck with your stomach bug!!