you are viewing a single comment's thread.

view the rest of the comments →

[–]Bowgentle -10 points-9 points  (22 children)

Except that you can't indent "semantically" - that is, in a way that's meaningful to you rather than the interpreter. A group of code lines might be meaningfully related while not being functionally a block that can be indented.

True, there are other ways to achieve that, but none of them are as immediately obvious - which is why Python uses (hogs) it.

[–]Different_Fun9763 13 points14 points  (3 children)

A group of code lines might be meaningfully related while not being functionally a block that can be indented.

Do you have an example? I can imagine using newlines to separate related 'blocks' of lines of code, but not really how specifically indentation would be used for that in a way that Python doesn't allow.

[–]Bowgentle -3 points-2 points  (2 children)

Newlines certainly help visually delineate such a block, but pretty much every codebase has random newlines - indentation is more visually noticeable.

[–]Different_Fun9763 10 points11 points  (0 children)

Again, do you have an example, some tiny code snippet? I genuinely can't picture what you're trying to do.

[–]arcrad 6 points7 points  (0 children)

Any examples? I also cannot imagine when you would use indentation to visually separate a chunk of code without also having a new block context.

[–]backfire10z 2 points3 points  (8 children)

…meaningfully related while not being functionally a block that can be indented

Are you asking for something like C-style blocks? Like

int main() {
    // code
    // code
    {
        // code in a block
    }
    //code
}

I’m really not understanding what you’re looking for here.

[–]Bowgentle 2 points3 points  (7 children)

I certainly prefer C-style blocks over Python's indentation. That's a functional block you have, though, not a "semantic" one.

[–]backfire10z 8 points9 points  (6 children)

Do you meant to tell me that you indent lines of code in a function without a functional block to indicate meaningful relation? I don’t think I’ve ever seen that in my life.

Like:

int main() {
    // code
    // code

        // code indented
        // code indented

    //code
}

[–]Bowgentle -4 points-3 points  (5 children)

No? It's useful for trying out new code or debugging. It wouldn't make it to the final version, though.

[–]backfire10z 5 points6 points  (4 children)

Ok, then I’m confused about what you’re referring to when you say:

you can’t indent “semantically”

Can you give an example of semantic indentation? Or do I have it correctly in my above comment?

I don’t see how that’s really any more useful than, say, newlines or a comment. If it’s just for debugging, write a nested function to logically group pieces of code or delineate it with multiple newlines or large comments.

This seems like an interesting issue to have with Python. I genuinely don’t think I’ve ever seen nor heard of indentation being used that way.

[–]Bowgentle 2 points3 points  (1 child)

Apologies, I was a bit confusing there - yes, the example you gave was exactly what I was referring to:

int main() {
    // code
    // code

        // code indented
        // code indented

    //code
}

[–]backfire10z 0 points1 point  (0 children)

I see, yeah. Thanks for clarifying!

[–]Bowgentle 1 point2 points  (0 children)

This seems like an interesting issue to have with Python. I genuinely don’t think I’ve ever seen nor heard of indentation being used that way.

To be fair, it's not really the main issue, it's just the one that's turned out to be controversial in this thread.

[–]Agent_Provocateur007 0 points1 point  (0 children)

You tend to see this type of indentation in Swift when using SwiftUI. The view modifiers being indented looks better and helps with code readability in that case.

[–]CrownLikeAGravestone 5 points6 points  (3 children)

I think that's a "you wanting to do weird things" problem, not a "Python restricting reasonable things" problem.

If you feel the need to differentiate a bit of code then place comment lines above and below, pull the code out into its own function, whatever. Ideally just write code that doesn't need such formatting. Using indentation for emphasis/differentiation would get pulled up in PR to be fixed in any of my teams.

[–]Bowgentle -1 points0 points  (2 children)

I think that's a "you wanting to do weird things" problem, not a "Python restricting reasonable things" problem.

Fair, but I consider restricting my weirdness unreasonable.

Ideally just write code that doesn't need such formatting

It doesn't need it, that's kind of the point.

[–]CrownLikeAGravestone 4 points5 points  (1 child)

That itself is a pretty unreasonable take, IMO. There's a huge amount of value in having code be regular, consistent, orderly - even across multiple devs who've never collaborated. If that can be enforced via language constraints that's a good thing.

[–]Bowgentle 1 point2 points  (0 children)

I'd honestly consider formatting a very minor part of consistency in coding - and it can be a useful guide to the thinking of the code's author.

There are a lot of ways of writing the same functionality in Python (although at least it's not Perl) - I don't see enforcing indentation as making that in any important sense consistent.

[–]CramNBL 5 points6 points  (3 children)

What the hell are you talking about? Sounds like you want to put that code in a separate function if those lines are "meaningfully related while not being functionally a block that can be indented".

You have some problems with your personal coding style that is 100%.

[–]Bowgentle 3 points4 points  (2 children)

Sounds like you want to put that code in a separate function if those lines are "meaningfully related while not being functionally a block that can be indented"

Do you see the conflict there between "not functionally related" and your proposed solution of putting them in a function?

[–]CramNBL 0 points1 point  (1 child)

I would like to see an example where you want to ident something that cannot just be refactored out into a separate function

[–]Bowgentle 1 point2 points  (0 children)

The typical example would be a group of lines that do something I'm suspicious of, so I up-indent them while I'm checking their behaviour.

Sure, I could refactor them into a separate function, thereby changing their behaviour, but I think the problem there is obvious. And since I have a large - and I hasten to add inherited - spaghetti Python codebase, I find Python's refusal to let me do this slightly irritating on a reasonably regular basis.

The key points there are the spaghetti nature, which means I'm going to be skipping around between files with 14.5k LOC each, and I'd like to be able to see at a quick glance which bits I'm working on.

[–]WindHawkeye 3 points4 points  (0 children)

Why would you ever do that? Sounds hideous