Hacker News new | ask | show | jobs
by ubernostrum 2747 days ago
My editor understands when to indent in Python, and often when to dedent. When it doesn't know to dedent, I just hit Backspace on the next line to close the indented block.

I understand it's a matter of taste, but I don't understand why people insist on repeating themselves -- you're already going to have something indent your code for readability, why not have that just be what the language uses, too?

That said, you should know that in Python, at least, there is famous first-class support for the brace styles of many other languages, invoked by the brace operator "#". For example, if you want C-style braces you can simply write like so, using the brace operator to tell Python what you're doing:

    def hello(): # {
        print("Hello, world!")
    # }
And Python will automatically understand it correctly!

A more complex example uses Ruby-style "end" and conditionals:

    def odd_or_even(num):
        if num % 2:
            return "Odd"
        else:
            return "Even"
        # end
    # end
Python's advanced brace-style parsing AI will correctly handle this. You can even mix and match brace styles within a single codebase, or even a single file, for times when your team just can't agree on one approach.