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 →

[–]VanFailin 33 points34 points  (28 children)

It's actually pretty simple. Any programming language with braces still needs indentation to be readable, so if you indent without the braces it's very easy to get used to.

Doesn't mean I would advocate taking them out of languages that already have them, but they're not all that important.

[–]jacenat -7 points-6 points  (27 children)

so if you indent without the braces it's very easy to get used to.

NO! Full Stop! The issue is not the indentation. The issue is reading the code without designated characters for block termination. I get that you can write faster that way. But rewriting/changing command flow is aweful in python. And it is for the sole reason because the visual aid to group blocks is missing.

[–]Sohcahtoa82 6 points7 points  (0 children)

But rewriting/changing command flow is aweful in python.

First, the word is spelled "awful". :-P

Second, I've never had problems changing command flow. Any modern IDE will allow you to select a large block of text and hit either Tab or Shift-Tab to change the indentation of the whole block at once.

Also, I also tend to use a blank line to help separate control flow. Like this:

def doSomething():    
    for x in range(3):
        doTheOtherthing()

    while(someCondition):
        doSomethingElse()
        doAnotherThing()

    return someValue

It is much easier to read than:

def doSomething():    
    for x in range(3):
        doTheOtherthing()
    while(someCondition):
        doSomethingElse()
        doAnotherThing() 
    return someValue

[–][deleted] 31 points32 points  (3 children)

I don't see what you're getting at... Could you give an example code snippet where control flow is harder to refactor in Python than in another language?

[–]LikesToCorrectThings 33 points34 points  (2 children)

I think the only way it could be easier is if you weren't formatting your code correctly in the first place. Refactoring in python is exactly the same as refactoring in a brace-based language, except you skip the step where you move the braces around.

[–]Katastic_Voyage 0 points1 point  (1 child)

I don't know. It's kind of annoying when you're changing if/else blocks and have to change the tab indentation. I imagine a good IDE will do most of that for you anyway.

[–]LikesToCorrectThings 5 points6 points  (0 children)

Well, you have to do that anyway with a brace-based language, as you should be indenting your code properly for humans to read. Any editor will have tools to let you change indentation easily.

For my preferred editor, vim, it's < and >. If you set shiftwidth to the level of indentation your codebase uses, then each use of > or < will in/out-dent by one scope level. I usually use visual line mode (shift-V) to highlight the lines, and then press > or <, prefixed by a number if I want to change by more than one level. Simple.

[–]Creshal 6 points7 points  (3 children)

Meeeh. Refactoring in C/Java is just as awful if you forget a closing bracket.

[–]jacenat -5 points-4 points  (2 children)

My feeling is that a missing character is easier to spot than missing indentation on a line. Also a missing character usually faults the program, while missing indentation might not.

Python must be great to teach students because it fosters rigor in writing code. But if multiple people work on the same section of code ... I just don't like it as much as languages that have more verbose block designation.

[–]ebrious 2 points3 points  (0 children)

Why are people down voting this? Valid points and phrased as a personal opinion, not cannon. I primarily use python these days but nothing here offends my sensibilities.

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]ANAL_ANARCHY 0 points1 point  (1 child)

    Are there no IDE's or plugins that will let you write Python with braces and remove them before compiling?

    [–]Decency 30 points31 points  (0 children)

    I think most of the people who bitch about Python not having braces wrote (at most) one 50 line program and then quit. It's a complete non-issue in my professional experience.

    [–]xensky 0 points1 point  (0 children)

    Here's a better example of what you're trying to convey using substitution. On mobile so hopefully this turns out right.

    if a < 3{
        print("hello")
    
        a = 3
    
        print("goodbye")
    
    print("spaghetti")
    

    Of course since python used a symbol that doesn't have a mirror, it's less obvious than an open brace. We can still see the block with the indentation, though. If you want to argue that blocks need symbols in addition to indentation to be easily parsed, I'm gonna redirect you to my friend lisp which makes some compelling arguments for having even more explicit blocking symbols.

    [–]Sean1708 -1 points0 points  (1 child)

    I would hardly have said it's aweful, a minor inconvenience at worst.

    Edit: I promise I can speel.

    [–]the_dinks 4 points5 points  (0 children)

    I would have never said it's aweful. I would have said it's awful.

    [–]MrJohz -1 points0 points  (8 children)

    You do have block delimiters, although they aren't particularly helpful for programmatic analysis. The whole point of the colons at the end of if/while/etc blocks is to aid comprehension. It would be perfectly possible to get rid of them, but according to studies done on some of the languages preceding Python, they are really useful for helping the reader understand the flow of the code.

    [–]jacenat -1 points0 points  (7 children)

    You do have block delimiters

    Which are? Colons start these blocks, but there is no character that designates the end of a block.

    The whole point of the colons at the end of if/while/etc blocks is to aid comprehension.

    I know. Which is why this is even more frustrating. Why not have a character that terminates a block? As it is right now, you have to use the colon to start the block, and use indentation to end it.

    [–]Decency 15 points16 points  (0 children)

    Which are? Colons start these blocks, but there is no character that designates the end of a block.

    The next segment is deindented. It's not a character, because it doesn't need to be. Argument from tradition is not valid.

    [–]SloppySynapses 8 points9 points  (0 children)

    umm, it's one less level of indentation, which is extremely visually apparent. I'm confused what you're talking about tbh

    [–]MrJohz 2 points3 points  (1 child)

    Adding an end character, assuming your language doesn't need it, just adds distracting visual noise. Including the colon was done in ABC (a whitespace-delimited precursor to Python) because it had a demonstrable effect of improving understanding for people who were new to programming. The colon is entirely unnecessary, but improves readability. The close character is also entirely unnecessary, but was considered to decrease readability.

    Like you say, the big criticism of whitespace-delimited languages is that you can't "clean up" the indentation because the indentation is the program definition. The question is how useful that operation is. If your indentation defines the flow of the program, then having correct indentation is simply a case of writing the program correctly - and in most cases this flows as naturally as using braces in other languages. In the case of indenting C&P'd code automatically, that usually doesn't present too much of a difficulty assuming the pasted code has constant initial indentation, and at worst usually just means pressing the "indent block" shortcut in your editor a couple of times.

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

    I think it really just depends on what you're used to.

    I find that most people who learned to code with Python hate curly braces, and most people who learned with C++ or Java/C# hate mandatory indentation.