6

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.

nicael
  • 18,550
  • 13
  • 57
  • 90
nickb
  • 9,140
  • 11
  • 39
  • 48

4 Answers4

13

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.

glglgl
  • 89,107
  • 13
  • 149
  • 217
  • Doesn't Guido himself disagree with this approach. http://www.artima.com/weblogs/viewpost.jsp?thread=147358 – nickb Nov 12 '12 at 14:16
  • 1
    There are some limitations, for example it must be a single expression and it can't contain any keywords. – Paolo Moretti Nov 12 '12 at 14:17
  • 3
    @PaoloMoretti Playing devil's advocate - I think "can't contain any keywords" isn't quite the right phrasing... `test = lambda L: 3 if L % 2 and L > 15 == 0 else 7`... – Jon Clements Nov 12 '12 at 14:27
  • 1
    @glglgl your 'answer' doesn't answer my question. Your speaking to Lamda's specifically and my question is 'what language limitations exists when a language is designed to use indentation to have block significance' – nickb Nov 12 '12 at 14:28
  • 1
    "Only can contain expressions" resp. "can't contain statements" would be correct. – glglgl Nov 12 '12 at 14:28
  • 1
    @nickb My answer answers with 'there are no limitations as there in fact is a "end" in the form of a dedent' – glglgl Nov 12 '12 at 14:29
  • @glglgl, then going back to Lamda's, there does appear to be limitations according directly from Guido himself. How do you explain that? – nickb Nov 12 '12 at 14:32
  • @JonClements I'm sorry. What I meant to say was that the body of a lambda has to be a single expression. – Paolo Moretti Nov 12 '12 at 14:41
  • 1
    @PaoloMoretti, EXACTLY. So there IS A LIMITATION. Hence, this 'answer' by glglgl is incorrect. glglgl says the language has no limitation when you just proved it does. (I'm frustrated to see so many upvotes for this 'answer' when it's clearly wrong). – nickb Nov 12 '12 at 14:43
  • 3
    The limitation isn't a language limitation it's a lambda limitation. – Wessie Nov 12 '12 at 15:09
  • In fact, it is a limitation, but I don't see how it comes from the lack of an "END" keyword/sign. In ANSI-C, for example, I cannot have something like `a = { while (expr) { do this; do that; }; expression }` in order to execute stuff and assign `expression`'s value to à`, although there is a `{ }`. (Note that GCC has an extension which makes such things possible. This is handy in `#define`d macros.) – glglgl Nov 12 '12 at 15:37
  • 3
    @glgl I think the point is that, since Python uses physical indentation to determine the grouping of statements (instead of braces or begin/end keywords), it's basically impossible to find a Pythonic way to express multi-line (i.e. multi-statement) anonymous functions. – Paolo Moretti Nov 12 '12 at 16:23
2

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.

guidot
  • 5,095
  • 2
  • 25
  • 37
0

One of the biggest limitations (if you would call it that) is that you can not use tabs and spaces in the same program.

And you shouldn't. Ever.

There are no apparent structural limitations, except perhaps when parsing a python source file (parsing, not interpreting):

def foo(bar):
        # If bar contains multiple elements
    if len(bar) > 1:
            return bar

This is perfectly legal python code, however, when parsing the file, you may run into trouble trying to figure out which indentation level the comment belongs to.

0

What do you mean by "limitation"? Do you mean there are computations Python cannot perform that other languages can? In that case, the answer is definitely No. Python is turing complete.

Do you mean that the lack of end statements change how computations are expressed in Python? In that case, the answer is "mostly not". You must understand that Python's dedent is an end statement; it's a byte sequence that the interpreter recognizes as the end of a block.

However, as others have mentioned, the use of indentation to denote blocks is awkward when it comes to inline functions (Python's lambda). This means the style of Python programs might be slightly different than from JavaScript, for example (where it's common to write large inline functions).

That being said, many languages don't even have inline functions to begin with, so I wouldn't call this a limitation.

Alex Miller
  • 1,566
  • 1
  • 13
  • 16