Hacker News new | ask | show | jobs
by BeetleB 2747 days ago
It is because those things are simply not needed to parse or understand the code.

Everyone indents anyway. So why need braces?

Most people write one statement per line. Who needs semicolons. I've often called it the most useless character in programming language history. Whenever I switch from a language that doesn't use them to one that needs them, it's a horrible transition. I have to mentally remember to add this character at the end of most lines.

Parentheses for function calls - in some contexts they are helpful. In most, though, they are not needed. Wherever they are needed, you will have them in F#. For people who went from Python 2 to Python 3, you'll know the pain of suddenly needing parentheses for print statements, and for most of those people, you will not see any benefit to adding those parentheses. Extend that to other functions.

1 comments

"Everyone indents anyway. So why need braces?"

I don't indent. I let the editor do it based on braces.

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.
Fair enough. I save on keystrokes by not inserting braces. I do have to manually indent once in a while, but the editor will usually figure out what I mean.

As an example, in a for loop in Python, I need to press a single key for indenting[1]. In a language like C, it would be 4 keystrokes - 2 for each brace. Come to think of it, this is true for if conditions, functions, etc. Pretty much all places you'd need braces in C. I'm having trouble figuring out where in regular programming in Python a braces would mean less work for the programmer.

Indenting is simply less work than inserting braces.

[1]Strictly speaking, for dedenting when I'm done with the for loop.

All you are saying is personal taste and familiarity. Nothing wrong with that but I could argue every one of your points exactly the other way and would be as right as you are.

In the end you get used to almost everything.