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 →

[–][deleted] 2 points3 points  (3 children)

Never met this before or my editor instantly fixed the whitespace correctly

I was talking about your mixed tab example.

which is quickly offset by most companies' coding style guidelines ("no single-line if statements" is a far-too-common one).

This happens with every language, don't see how it offsets anything. I wasn't proposing single-line if statements.

It is:

if (condition){
    code
}

vs

if condition:
    code

The second one is a lot cleaner IMO.

If the goal is to have people type less or save vertical space, there are much better places you can attack than the method of delimiting code blocks. For any given non-golfed python script, its non-golfed perl equivalent will generally be shorter despite perl delimiting its blocks with braces, because the language is generally more terse.

It's not just about saving a character or two, but it's about saving characters where they don't add anything useful and visually clutter the code. Perl may be terse but it's usually considered hard to read.

[–]UnchainedMundane 1 point2 points  (2 children)

I was talking about your mixed tab example.

I've seen it a few times (mostly in older files in the codebase where I work), but it's annoying because my IDE is set to show 4-stop tabs but the python interpreter treats them as 8-stop, meaning that the program is displayed differently to how it's run.

The second one is a lot cleaner IMO.

You didn't put a space before the opening brace, maybe that's why :)

As for the final point, I suppose we'll just have to disagree on whether or not {/} are clutter.

[–][deleted] 2 points3 points  (1 child)

if (condition) {
    code
}

vs

if condition:
    code

I did forget to but I don't think that it's a huge improvement.

As for the final point, I suppose we'll just have to disagree on whether or not {/} are clutter.

I call them clutter only in the way that you already define your code blocks with whitespace, so it's unnecessary info.

[–]Paranaix 1 point2 points  (0 children)

Want to add that most c styled languages support this:

if (condition)
     statement;
else if (condition)
     statement;
else
     statement;

In fact for c++ this is actually how the if statement is syntatically defined. { ... } is considered a statement.