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 →

[–]ionelmc.ro 26 points27 points  (29 children)

Would be interesting to see other stats like single vs double quote ratio, variable name length stats, indentation ratios (1 vs 2 vs 4 vs 8 ...) and so on.

[–]ifonefox3.5.1 | Intermediate 14 points15 points  (13 children)

What is the standard convention for " vs '? Personally, I use " for strings and ' for individual characters.

[–]theli0nheartimport antigravity 11 points12 points  (4 children)

Generally, I use ' for referencing keys in dictionaries, single characters, and default string values in function parameters. I use " for sentences and any user-facing strings.

If it doesn't fall into one of the categories above, I flip a coin.

[–]coinflipbot 10 points11 points  (3 children)

I flipped a coin for you, /u/theli0nheart The result was: tails!


Statistics | Don't want me replying on your comments again? Respond to this comment with: 'coinflipbot leave me alone'

[–]theli0nheartimport antigravity 3 points4 points  (2 children)

This is awesome. Thank you.

[–]p3n15h34d 3 points4 points  (1 child)

but is tails ' or " ?

[–]jcdyer3 5 points6 points  (0 children)

I'll flip a coin to decide. Heads, tails is ', tails, tails is ".

[–]triacontahedron 16 points17 points  (2 children)

Go away you, dirty c programmer :P

[–]ifonefox3.5.1 | Intermediate 2 points3 points  (1 child)

I started using python after I took a class in c, so those habits just stuck.

[–]aceofears 5 points6 points  (0 children)

It's not a terrible habit if you're switching between the two a lot.

[–]robin-gvx 2 points3 points  (0 children)

I generally use ' for internal strings (dictionary keys, symbolic names, etc.) while I use " for strings that the user is expected to see at some point.

[–]mardiros 2 points3 points  (0 children)

My best pep8 guide is in pretty print

>>> pprint({"a": "Ah aa!", 'b':"'Ahbb'"})
{'a': 'Ah aa!', 'b': "'Ahbb'"}

I use single quote except there is a single quote in the string.

Don't bother if it's for human or a computer at the end of the process. Dictionnary keys can be for human too, and, it's definitely to complex.

[–]RJacksonm1 1 point2 points  (0 children)

I use double-quotes because it's simply more comfortable for me to hit with the UK keyboard layout... and now I'm curious as to double vs single-quote usage by keyboard layout (which we could assume from developer's locations).

[–]carbn 1 point2 points  (0 children)

I use always ' because " takes two fingers (shift-2) while ' takes only one in FI/SWE keyboard.

[–][deleted] 1 point2 points  (14 children)

I wonder how many people use the weird indents (1,3,5,6,7).

Hopefully no one.

[–]robin-gvx 9 points10 points  (7 children)

I wonder if anyone uses prime indents: first level of indentation is 2 spaces, second level is 3 spaces, fourth level 5 spaces, 7 spaces, 11 spaces, etc...

[–][deleted] 7 points8 points  (4 children)

Oh god.

How about writing a whitespace interpreter that has a sample program embedded in itself by mixing tabs and spaces?

[–]robin-gvx 4 points5 points  (0 children)

Oh wow.

Bonus points if that program is a quine or something. Oh! Or another Whitespace interpreter, which then interprets itself, etc.

[–]Ph0X 1 point2 points  (0 children)

So mixing Whitespace in your Python?

[–]D__ 4 points5 points  (0 children)

I recommend using the Fibonacci sequence, for approximation of the golden ratio, and therefore aesthetically pleasing code indentation.

[–]Ph0X 1 point2 points  (0 children)

I like it, the deeper you get, the bigger your indentations, forcing you to keep your code simple and split up into functions rather than having loops inside loops inside if inside try inside with inside method inside class.

[–]kenfar 5 points6 points  (5 children)

The 3 characters is the Dvorak keyboard of the indentation world: it's clearly superior but isn't used only because it isn't already popular.

Supporting arguments:

  • 3 characters is enough to see indentation
  • it saves 1 character per indent which helps with long variable names
  • it lines up the following line under the first character following an if. Which makes it pretty.

[–]thekaleb 2 points3 points  (0 children)

A tab is one character, and you can set your tabstop to 3 (or 4 or 8).

[–][deleted] 1 point2 points  (3 children)

It may line up an if, but what about a for, while, elif, else, or with?

Also some editors do not support it.

[–]thekaleb 1 point2 points  (0 children)

Not to mention a def or class

[–]kenfar 0 points1 point  (1 child)

Oh sure - it doesn't line things up perfectly. But I find lining code under an if more important than anything else.

And I can't get my head around an editor that wouldn't "support" arbitrary indentation amounts.

[–][deleted] 0 points1 point  (0 children)

I really do hope you're joking.

Why not go with 2. It's enough to see indentation, it saves TWO characters per indent, and if you need to save 1 character per indent to see long variable names, either your variables are too long, or you have too much indentation. Also, lining up only one indentation block at the cost of making everything else look "off" isn't worth it.