Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

As a language, is Python limited due to no end statement?

Since Python uses tabs spacing to indicate scope (and as such, has no end of } symbols), does that limit the language in any way from having particular functionality?

Note: I'm not talking about personal preferences on coding-style, I'm talking about real language limitation as a direct result of not having an end statement?

For example, it appears by a post directly from Guido that the lack of multi-line lamba's due to Python not having a terminating end / } symbol?

If so, what other Python limations are there because of this language design decision to use indentation?


Update:

Please note this question is not about Lambda's and technically, not even Python per se. It's about programming language design ... and what limitations does a programming language have when it's designed to have indentation (as opposed to end statements) represent block scope.

like image 991
nickb Avatar asked Nov 12 '12 14:11

nickb


People also ask

Is Python a limited language?

So there is no limitation in any way.

Why does Python not have end?

The reason this isn't introduced to existing languages is that there are already billions of lines of code written in them, and you don't want to force people to change all of that just for some aesthetics.

What is Python not good for?

Python is mostly used in desktop and web server-side development. It is not considered ideal for mobile app development and game development due to the consumption of more memory and its slow processing speed while compared to other programming languages.

Why Python is different from other languages?

Python is an interpreted and dynamically typed language, whereas Java is a compiled and statically typed language. Python code doesn't need to be compiled before being run. Java code, on the other hand, needs to be compiled from code readable by humans to code readable by the machine.


2 Answers

There is no lack of end/ }: an end is represented by a "dedent" to the previous depth. So there is no limitation in any way.

Example:

x = 123
while x > 10:
    if x % 21:
        print("x")
    print("y")
print("z")

A "begin" corresponds to increasing of indentation level (after while, after if).

An "end" corresponds to decreasing of indentation level (after the respective print()s).

If you omit the print("y"), you have a "dedentation" to the topmost level, which corresponds to having two successive "end"s.

like image 98
glglgl Avatar answered Nov 14 '22 23:11

glglgl


The answer to this question ranges somewhere between syntactic sugar and language style, i.e. how to phrase a problem elegant and compliant to language philosophy. Any turing-complete language, even assembly language and C - definitely lacking any lambda support - may solve any problem. Lambda allows just a different (arguably more elegant if looking from functional language viewpoint) phrasing of stuff also stateable using standard function definition. So I can't recognize a limitation here beyond having to code differently.

like image 20
guidot Avatar answered Nov 14 '22 23:11

guidot