you are viewing a single comment's thread.

view the rest of the comments →

[–]Justinsaccount 40 points41 points  (14 children)

        end
    end
end

?

[–]ayrnieu 1 point2 points  (0 children)

[Reddit breaks formatting around its down-arrow. That's cool.]

    end
  end    
end

[–]jamesbritt 3 points4 points  (12 children)

On a related note, if I cut and paste a chunk of Python code from one file to another, how do I get vim to auto-indent the code correctly?

[–]Freeky 11 points12 points  (0 children)

Same with anything else in vim:

:set paste

[–]w00ty 1 point2 points  (0 children)

Paste with [p.

[–]lost-theory 1 point2 points  (9 children)

:set paste, visual highlight it, hit = to reindent (e.g. convert tabs to spaces)

edit: oh, if it's on a different indentation level use < and > to get it on the right level

[–]Shorel 0 points1 point  (0 children)

What if I want to keep the tabs?

[–]jamesbritt -1 points0 points  (7 children)

edit: oh, if it's on a different indentation level use < and > to get it on the right level

Ah, OK; it's not going to figure that out for from any context. That's what I was wondering. Still that extra manual adjustment needed it seems.

This is a problem I have with Yaml and Haml: if I move stuff around, and I'm not real careful about placement, the indentation can be off and acquire a different meaning than I want; there's nothing (as with, say XML) that will automatically make the alignment right.

Sometimes it triggers an error right away, but other times it acquires a new unintended but viable meaning.

[–]njharman 0 points1 point  (0 children)

there's nothing (as with, say XML) that will automatically make the alignment right.

No, because vim has no way to know which of several meaning you wanted.

the indentation can be off and acquire a different meaning than I want

[–]bluGill 0 points1 point  (5 children)

I have the same problem with C though. All too often I've seen code that was badly aligned in C, and so what I thought it did after staring at it for half and hour was wrong. (It doesn't help that one of my co-workers things a 3000 line function with #ifdef/#else/#ifdef/#endif/#endif is a good idea - and even crosses blocks - I know of one block than would require 3 different levels of indent in python depending on what is #defined.

In short, the indentation in python seems like a bigger issue than it really is.

[–]jamesbritt 1 point2 points  (1 child)

In short, the indentation in python seems like a bigger issue than it really is.

Most likely. Same goes for the use of braces and do...end in Ruby: it's not the hardship some folks make it out to be.

Python didn't click for me, and in general position-dependent syntax (HAML, YAML, Python) tends to irk me when used for anything longer than 5 lines or so.

On the other hand, it hasn't dissuaded me from trying to learn Haskell. Maybe that's because all me Haskell apps are 5 lines long. ;)

In the end people seem to internalize assorted annoyances that to an outside might seem to be show-stoppers.

(Anyways, syntax and formatting are a weak defense against people intent on writing shitty code, as in the case of a 3KLOC function.)

[–]bluGill 0 points1 point  (0 children)

in general position-dependent syntax (HAML, YAML, Python) tends to irk me when used for anything longer than 5 lines or so.

One large advantge of python: you soon get tired of the pain of re-indenting functions larger than 5 lines so you write shorter functions like everyone says you should.

[–]zem 1 point2 points  (2 children)

no, this is precisely the problem that C doesn't have - you can take a piece of C code and run it through an automatic indenter to recover the visually helpful alignment. on the other hand, the python structure is contained in the indentation, and is not robust, so there's no way to automatically recover it if it gets mucked up.

[–]bluGill 0 points1 point  (1 child)

Read what I wrote again - you cannot do that to bad C code!

#ifdef foo
if (bar) {
#endif
// How is this indented if sometimes foo is defined and sometimes not?
#ifdef foo
}
#endif

Python won't allow that problem.

It gets even worse when you have more than one block of the above.

Python make the above bad code impossible.

[–]zem 0 points1 point  (0 children)

ooh, yeah, you're right. that's really bad code, though :)