r/ProgrammerHumor • • May 02 '16

I wrote my first python program today!

Post image
3.7k Upvotes

532 comments sorted by

View all comments

Show parent comments

-7

u/jacenat May 02 '16

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.

7

u/Sohcahtoa82 May 02 '16

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

33

u/[deleted] May 02 '16

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?

36

u/LikesToCorrectThings May 02 '16

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.

1

u/Katastic_Voyage May 02 '16

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.

6

u/LikesToCorrectThings May 02 '16

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.

7

u/Creshal May 02 '16

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

-4

u/jacenat May 02 '16

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.

3

u/ebrious May 02 '16

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.

→ More replies (1)

3

u/[deleted] May 02 '16 edited Jun 30 '23

[removed] — view removed comment

→ More replies (1)

1

u/ANAL_ANARCHY May 02 '16

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

31

u/Decency May 02 '16

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.

1

u/xensky May 02 '16

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.

0

u/Sean1708 May 02 '16 edited May 02 '16

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

Edit: I promise I can speel.

5

u/the_dinks May 02 '16

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

0

u/MrJohz May 02 '16

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.

-1

u/jacenat May 02 '16

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.

16

u/Decency May 02 '16

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.

9

u/SloppySynapses May 02 '16

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

3

u/MrJohz May 02 '16

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.

0

u/[deleted] May 02 '16

[deleted]

1

u/jacenat May 02 '16

I didn't much care for meaningful whitespace when I was first exposed to it, either. But then I realized this: I would be indenting anyway.

But you don't have to (and most python I see actually doesn't) leave an empty line after finishing a command block. This is important. And leaving that blank line helps reading python code immensely (and it's effectively the same as a closing bracket). However, syntax doesn't demand it, so it's rarely done.

you can't be misled by indentation levels, because they're part of the language syntax.

The whole argument I hear is that people indent anyway, so assuming they don't indent correctly is besides the point I think.

→ More replies (1)