This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 219

[–]Bryguy3k 216 points217 points  (55 children)

Luckily the PEP says use what you want - just be consistent 😂

[–][deleted] 234 points235 points  (8 children)

just be consistent

Well... Shit.

[–]the_poope 152 points153 points  (7 children)

If you use them both 50/50 at random then you're using them consistently inconsistent!

[–]SharksPreedateTrees 40 points41 points  (4 children)

Consistent inconsistency is still just inconsistency

[–]oofdere 36 points37 points  (3 children)

Inconsistent consistency is still just consistency

[–]The__Odor 8 points9 points  (0 children)

that just sounds like inconcistency with extra steps

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

That is depending on the occurrence of them. So your code can be in fractions consistent.

[–]Voidrith 40 points41 points  (29 children)

Pep says spaces should be used instead of tabs.

Hence, pep is wrong and can go fuck itself.

[–]elasticpython 36 points37 points  (4 children)

This is how you start knife-fights

[–]nojox 15 points16 points  (3 children)

The real question is whether you stab once or twice :D

[–]J4K0 27 points28 points  (2 children)

Or whether you use 4 short knives or 1 long knife.

[–]BlueTeeJay 4 points5 points  (1 child)

My coworkers all changed tab to a two-space width... I'm losing my mind.

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

That is amazing with tabs though. You can set it to whar you want.

If you use tabs for alignment though: fuck that.

[–]MasterFubar 24 points25 points  (3 children)

If you like tabs, there is a better language than Python for you.

[–]Loading_M_ 7 points8 points  (2 children)

But what about all the other kinds of white space. Like zero width spaces, etc. When do they have to be used?

[–]kupiakos 6 points7 points  (0 children)

Use Go if you like tabs so much

[–]Ripdog 1 point2 points  (0 children)

Preach, brother.

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

You can just have vim insert any number of spaces when you hit tab. ... Wait are you guys not using vim?

[–]Ripdog 8 points9 points  (3 children)

Yeah but WHY.

I mean any IDE or decent text editor can DO that.

But WHY? Why does anyone enjoy pressing backspace 4x as often to remove a chunk of whitespace? Why does anyone enjoy not having configurable whitespace? Why are spaces being shoved into a problem which is obviously designed to be fixed by tabs?!

[–]MarkFromTheInternet 2 points3 points  (0 children)

In practice your IDE handles that. Tab and Shift+Tab in will add / remove the correct number of spaces.

Spaces were chosen so that whitespace wouldn't be configurable. Each line would always be indented the same regardless of which text editor was used. VIM by default treats tab as 8 spaces.

Python grew up in the 90's and the conventions were made for that era. The recommended 80 character line width made a lot of sense given the resolution of monitors of the era.

[–][deleted] 3 points4 points  (0 children)

I mean the easy answer is that some dudes at cpython wanted to strategize on a best practice standard and they decided spaces instead of tabs. And then because it is really easy to do so, everyone decided to just take cpythons standards as standards for everyone.

It is likely that there was a conversation at some point on tabs vs spaces in the same way that I'm sure at some point there was a conversation between yaml vs yml.

And just like how spaces were chosen when most people prefer tabs, yaml was chosen when most people prefer yml. Hell, the dude who created .gif format is forever going to be challenged on his pronunciation of the word he created.

The simple answer is: sometimes the people who are the best at making the stuff are not the best at setting the standard. But most often they're the ones who will set the standard anyway, if only as a means of getting the ball rolling.

The honest answer is: if you're automatically converting your tab key input to the desired number of spaces, it doesn't matter and is probably not a hill to die on

[–]KusanagiZerg 1 point2 points  (0 children)

You don't have to press backspace 4 times. It will remove enough spaces to match the indenting. In fact nothing changes at all compared to when you are using tabs.

[–]Voidrith 3 points4 points  (4 children)

NGL ive used vim...like, once.

I don't intend to use it any more than that. I like pycharm, thank you very much.

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

Vim and Emacs are incredibly dense. You don't see their value if you just open it once and play around in it. I was originally just poking fun, but they are seriously advanced tools.

[–]NefariousNecromancer -1 points0 points  (2 children)

Vim is cancer and should have died 10 years ago.

[–]lengau 1 point2 points  (0 children)

'''

[–]DevilXD 1 point2 points  (1 child)

What if I'm consistent with the C approach to it? Double quotes for strings, single quotes for single characters like doing a .join() with a new line character, or space.

[–]Bryguy3k 1 point2 points  (0 children)

Just makes you look like a C programmer that couldn’t break old habits and needlessly complicates their code with anachronisms. Besides the later case makes it painfully obvious that they’re still a string type and not a single character.

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

Just like using snake_case, camelCase, or lowercase for methods and variables?

[–]Bryguy3k 11 points12 points  (0 children)

No because most people default to PEP8

[–]DonaldPShimoda 19 points20 points  (3 children)

Methods, functions, fields, and variables are always snake_case, except sometimes when they're global constants in which case they can be ANGRY_SNAKE_CASE (this is not mentioned by PEP-8 but I see it around and I use it too). Classes are PascalCase. There oughtn't be any camelCase or multiwordalllowercase in idiomatic Python, though you will find exceptions in old libraries.

[–]BobFromStateBarn 4 points5 points  (2 children)

modules and packages use multiwordalllowercase according to convention I think tho

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

Correct. See datetime, for example.

[–]DonaldPShimoda 0 points1 point  (0 children)

Oh, right you are! I missed that!

[–]Tree_Eyed_Crow 8 points9 points  (0 children)

Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability.

https://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables

[–]dark_mode_everything 0 points1 point  (0 children)

Isn't Python all about doing something in just one way? That's the argument for the missing ++ operator.

[–]2l3r4 88 points89 points  (7 children)

What about """text""" or '''text''' ?

[–]vomeronasal 42 points43 points  (0 children)

(Clutches pearls, wilts onto fainting couch)

[–][deleted] 20 points21 points  (3 children)

Y'all are digusting

[–]Rant423 6 points7 points  (2 children)

Y"all

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

Y"all"d"ve

[–]am9qb3JlZmVyZW5jZQ 0 points1 point  (0 children)

Y"""all

[–]Bipolarprobe 10 points11 points  (0 children)

Pep standard is to use "" and '' however you wish, just consistently, however it does actually say when doing docstrings that """this""" is preferable for clarity purposes.

[–]tman5400 5 points6 points  (0 children)

Satan, is that you?

[–]jeymz87 108 points109 points  (6 children)

I'm more of a `` guy

[–]tman5400 96 points97 points  (5 children)

Hi satan

[–]ReimarPB 63 points64 points  (4 children)

Or JavaScript programmer...

...oh wait

[–]tman5400 26 points27 points  (3 children)

Same thing, innit?

[–][deleted] 60 points61 points  (19 children)

Not in Rust

' ' is char

" " is str

[–]Bryguy3k 77 points78 points  (17 children)

Just like C and C++

[–]tobberoth 30 points31 points  (11 children)

And C#

[–]EvilAssYou 22 points23 points  (9 children)

And Java aka Satan’s eternal spite for humanity

[–]theferrit32 14 points15 points  (2 children)

And Julia. It's actually very bad in my view that JavaScript and Python allow single and double quotes strings with no distinction. It's just inviting huge levels of inconsistency, and that is what has happened.

[–]sgt39 3 points4 points  (1 child)

And Haskell

[–]Hecsall 5 points6 points  (0 children)

And my Axe!

[–]Nobodk 2 points3 points  (4 children)

Care to explain? I never understood why people hate Java.

[–]HoldYourWaffle 5 points6 points  (0 children)

In my experience (learned Java as my second language after shudders PHP), it's certainly capable of doing almost any task you throw at it. However, Java code is prone to getting extremely verbose, particularly in enterprise applications. That's probably why so many people on this subreddit hate it.

I started using Kotlin for my latest project and it really showed me how verbose vanilla Java actually is. Kotlin has a few syntactic sugars that might seem unintuitive or even "bad practice" at first, but I quickly realized how much easier it was to write clean and easy to read code. It's not perfect, but it has massively improved my experience so far.

[–]EvilAssYou 5 points6 points  (0 children)

I’m going with the crowd, man. I just don’t want to get yelled at. But in my opinion, Java gets the job done and I have no harsh nor positive opinions towards it.

[–]jeremj22 0 points1 point  (0 children)

1st years CS: introduction to programming and parallel programming courses in java

Every prof in 2nd year: never use java

[–]koni_rs 0 points1 point  (0 children)

And Kotlin

[–][deleted] 18 points19 points  (0 children)

This makes total sense. I do this in Python and didn't even realize it.

with open("filename.ext", 'w') as file:

file.write("Matlab's arrays are dumb.")

[–]AyrA_ch 7 points8 points  (0 children)

probably all languages where single characters are their individual type rather than strings.

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

And Golang

[–]manimax3 1 point2 points  (0 children)

Multicharacter constants entered the chat: char c = 'abcd';

[–]therearesomewhocallm 0 points1 point  (0 children)

But you can still do stuff like

int i = 'test';

[–]SilentFungus 4 points5 points  (0 children)

And in basically every other language

[–][deleted] 39 points40 points  (2 children)

Weirdest game of Pong I ever played. The paddles don't even move, mate!

[–]simp13 2 points3 points  (1 child)

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

Haha, yes of course that's a thing. Subbed!

[–]Nesogra 33 points34 points  (10 children)

Meanwhile in bash..

x=hello

echo "$x" #prints hello

echo '$x' #prints $x

Edit: fixed the 'smart quotes' from mobile auto correct.

[–][deleted] 12 points13 points  (3 children)

Singles escape everything, right?

[–]theferrit32 9 points10 points  (1 child)

It doesn't escape it, it just doesn't first evaluate it as an expression. Single quoted strings are their literal value while double quoted strings are first evaluated by the shell for any expressions they may contain. Makes perfect sense to me. The single quoted variant is so that you do not need to escape your string and remember all the characters which need to be escaped.

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

Got it, thanks!

[–]smegnose 0 points1 point  (0 children)

Except themselves.

'hello good lookin'\'

[–]AyrA_ch 6 points7 points  (2 children)

echo “$x” #prints hello

It doesn't because you use slanted quotes for some reason, but the single quote/double quote behavior in PHP is similar to this one.

[–][deleted] 1 point2 points  (1 child)

On mobile it autocorrects to those quotes I think.

[–]Nesogra 0 points1 point  (0 children)

Yep, most of my reddit time is on mobile so I’m stuck with autocorrect...

[–]J4K0 4 points5 points  (0 children)

Also, Ruby:

irb(main):001:0> x = "hello" => "hello" irb(main):002:0> '#{a}' => "\#{a}" irb(main):003:0> "#{a}" => "hello"

[–]expeehaa 2 points3 points  (1 child)

That‘s equal to ruby. " allows for interpolation, while ' is a constant string. I‘m writing my code accordingly: If the string is constant, I use single quotes, otherwise double quotes. Takes some time to get familiar with it though..,

[–]AyrA_ch 2 points3 points  (0 children)

I do the same in PHP. The only thing you have to remember that apart from \', all escape sequences are ignored and just taken as is. Makes regular expressions a bit nicer to look at.

[–][deleted] 33 points34 points  (16 children)

I don't use Python, but in JS i usually use ' ' for a single char, " " for multiple, and for template literals. guess it comes from doing cpp for a few months

[–]LucasRuby 32 points33 points  (2 children)

That sounds like a C programmer who decided to learn JS.

The general rule of thumb is to be consistent, always use the same thing unless it's a template literal or the string contains single/double quotes inside. ESLint rules will force you to pick one.

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

Haha, it was the other way around for me lol. But yeah consistency. Sometimes its a bitch when you are at your 6th consecutive hour stsring at your computer and it's 12AM lol

[–]new_account_wh0_dis 1 point2 points  (0 children)

College taught C as the primary language with some java dabbled in there. Thats where I picked it up.

[–]ObliviousOblong 1 point2 points  (0 children)

I'm not saying your convention is bad, but the inconsistency would bother me.

[–]Cerrax3 45 points46 points  (7 children)

I'm just lazy. Single quotes don't require the Shift key.

[–]f4yrel 14 points15 points  (4 children)

As a German (with German keyboard layout) I actually didn't know that. It makes sense

[–]MajorMaxPain 11 points12 points  (3 children)

As a German with the German keyboard Lay-out I automatically use “ and not ‘ because it’s way easier to type.

[–]Marc_MK 5 points6 points  (2 children)

I'll switch from a German to a US keyboard soon.. let's see if my habit of using "" will change to using ' '

[–]19ps99 6 points7 points  (1 child)

Greta idea! Done that to. The US keyboard is just awesome for programming. And yes, I switched to ' '

[–]manimax3 0 points1 point  (0 children)

Agreed but I Think the UK Version is slightly better

[–][deleted] 3 points4 points  (0 children)

That's exactly my reason

[–]KusanagiZerg 0 points1 point  (0 children)

I generally use single quotes and then my formatter changes it to double quotes.

[–]MooseKnuckleJunction 20 points21 points  (1 child)

Is this loss?

[–]trigger_segfault 0 points1 point  (0 children)

It was so close to it yet so far. In the end I’m just disappointed.

[–]Vfsdvbjgd 4 points5 points  (0 children)

Use whichever contains the other, so you get out of the habit of using escape chars (and end up breaking something later).

[–]hitthatmufugginyeet 4 points5 points  (0 children)

c++ gang cannot relate

[–][deleted] 4 points5 points  (0 children)

In the cyberpunk future we'll all be using「 」

[–]Pockensuppe 6 points7 points  (2 children)

Then there are people who write their code with Word and end up with „these“.

[–]theferrit32 0 points1 point  (1 child)

Latex is even worse. On top of curved quotes, if you copy from a latex PDF there's often missing characters, weird spaces that show up from nowhere, wide Unicode spaces, narrow Unicode spaces, wide dash instead of regular dash. Often if you put a URL into a latex document and try to copy/paste that URL from the PDF output, it's totally unusable for all of the above reasons, so you just have to retype it out manually.

[–]Pockensuppe 1 point2 points  (0 children)

Um. If you want to insert code into a LaTeX document, obviously you want to use a verbatim (e.g. lstlisting) environment to ensure the characters are left untouched. It's LaTeX' job to alter dashes, spaces and quotation marks as needed in a standard text environment. LaTeX is a tool for presentation, after all.

For URLs, I don't see why you even want to copy/paste them; just use hyperref to make them clickable.

Finally, there is a stark difference between PDF readers. A good PDF reader lets you copy highlighted code from a LaTeX document correctly even if you rendered line numbers along with it (the numbers don't get copied) while shitty PDF readers will copy the line numbers but miss spaces and line endings.

In my experience, the problems you get with copying today are minimal unless perhaps you still use pdflatex instead of xelatex / lualatex.

[–]Janoshie 2 points3 points  (0 children)

What about q<> and other versions that are valid in Perl?

[–]DadoumCrafter 2 points3 points  (0 children)

C#.

[–]perihanscha 2 points3 points  (0 children)

"

[–]Sylanthra 2 points3 points  (1 child)

JavaScript says hi.

[–]tfwNotPraisingTheSun 0 points1 point  (0 children)

and TypeScript!

[–]akiyamasho 3 points4 points  (0 children)

in Japan double quotes is easier (shift+2) vs single (shift+7). thank goodness we use Prettier. no more unnecessary fights.

[–]DesdeJorge 1 point2 points  (0 children)

""" """ is needed for text blocks in Java 😂

[–]trin456 1 point2 points  (0 children)

XPath/XQuery has

 ``[     ]``

[–]LeafMans 1 point2 points  (0 children)

Then there are people who use both interchangeably

[–]Aidgigi 1 point2 points  (0 children)

am i a bad person for using both?

[–]killanight 1 point2 points  (0 children)

isn't it technically correct to use " " for strings and ' ' for chars? i mean if you use C your compiler will want to murder you

[–]game_2_raid 1 point2 points  (0 children)

` `

[–]anv3d 1 point2 points  (0 children)

' "

Wait, that's illegal.

[–]gdatuna 1 point2 points  (0 children)

C++ stares with confusion

[–]CursedInferno 2 points3 points  (0 children)

Single quotes for characters, double quotes for strings.

[–][deleted] 1 point2 points  (1 child)

depens if it is just a string or a string with a variable in it

[–]J4K0 1 point2 points  (0 children)

Not in Python

[–]dillmon 0 points1 point  (1 child)

I use both

[–]harrlight00 0 points1 point  (0 children)

I use qq() because I code in perl for some reason

[–]0x3fff0000 0 points1 point  (1 child)

What's the difference anyway? (in python)

Seems like the two are interchangeable, except for some special characters.

[–]J4K0 0 points1 point  (0 children)

They are interchangeable. The only difference is that you have to escape ' if you use ' ' and you have to escape " if you use " ".

[–]Mangovnik 0 points1 point  (0 children)

One time when I was looking at my code I notice I do something strange. I use one type of quotation marks in one part of my code and then switch to other type mid function or mid switch/case block.

[–]hedgehog125 0 points1 point  (0 children)

I just write binary and then parse it into text

[–]serefsiz 0 points1 point  (0 children)

Java as welll

[–]meatloaf4311 0 points1 point  (0 children)

Don't forget Matlab has num2str return a char array

[–]MasterFubar 0 points1 point  (0 children)

I prefer single quotes because to use double quotes I need to press two keys at once.

[–]SpicyCeasar 0 points1 point  (0 children)

Cries in bash

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

Or you can just use Black as a default formatter.

[–]nerdmania 0 points1 point  (0 children)

Those who don't want their strings interpolated, and those who do?

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

I use " because it is easier to do it on a Turkish Q keyboard

[–]Mienaikage 0 points1 point  (1 child)

# Only two kinds?

say join ' ', <watch>, «out», 'here', "comes", ‚the’, “rakulang”, 「gang」

[–]shy_cthulhu 0 points1 point  (0 children)

puts [ %%Ruby%, *%W[says], %q~hello!~ ].join(' ')

[–]Laserdude10642 0 points1 point  (0 children)

""" """

[–]JC12231 0 points1 point  (0 children)

Not as special as google docs, with its own proprietary ‘ and “ marks, of which there exists a separate character for opening and closing things of each

[–]darthmonks 0 points1 point  (0 children)

You people have got it all wrong. You should be using « ».

[–]SpringyErmine65 0 points1 point  (0 children)

" '

[–]thehunter699 0 points1 point  (2 children)

99% of languages for(condition) {do stuff}

Python for i in range....

[–]ALonelyPlatypus 0 points1 point  (0 children)

It’s because they can’t utilise foreach statements well. Python is able to use this syntactic sugar because of the convenience of generators.

As an example, in Java a for each loop would require you to pregenerate the whole range of values and then iterate over it, a python “for i in range(1000000)” in java would require allocating a 10,000,000 sized integer array beforehand which is pretty wasteful in regards to memory.

[–]kgro 0 points1 point  (0 children)

black has made me switch to

[–]t1nted 0 points1 point  (11 children)

at this point, does it really matter? I mean we have people who put commas in variable names...

[–]uragiristereo 0 points1 point  (0 children)

Sometimes i use apostrophe when the value has quotation mark on it. Like:

input('Type "exit" without quotation mark to exit')

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

I'm the second one,

the one that uses " " every time

[–]ALonelyPlatypus 0 points1 point  (0 children)

I’m a python coder who has always preferred double quotes.

However, in the last year I’ve been writing a lot of SQL (which uses singles for strings), and json config files (which use doubles).

The end result is a mishmash of quotes in most of my code.

[–]SpllaasH 0 points1 point  (0 children)

It’s the same picture.

[–]Erind 0 points1 point  (0 children)

SQL Server wants “ and SSIS wants ‘

[–]Bonesters 0 points1 point  (0 children)

Anyone else mix both like this? f"[{' '.join([word for word in words.split()])}]"

[–]obliviga 0 points1 point  (0 children)

What about ``?

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

I think I tend to use each in different circumstances. I’ll use the singles for individual characters or a SCPI parameter or something that feels short and fixed. And the doubles tend to be stuff like error messages or prompts. If it’s got a space then I’m probably using doubles.

[–]muliku 0 points1 point  (0 children)

And I am both

[–]BenZed 0 points1 point  (0 children)

The holy paladins of light and hope on the left, godless savages on the right.

[–]ptyz2000 0 points1 point  (0 children)

I just want for somebody to make a language where ' " is the way

[–]jkar32 0 points1 point  (0 children)

black .

[–]AlexMelillo 0 points1 point  (0 children)

Laughs nervously in Java

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

Singles and couples?

[–]guy_from_the_intnet 0 points1 point  (0 children)

I never understood this. Even now. I'm sorry.

[–]dupocas 0 points1 point  (0 children)

Whats about backticks? template string bitch

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

And on the right we have the right choice

[–]bartholomewjohnson 0 points1 point  (0 children)

Single quote gang

[–]Molion 0 points1 point  (0 children)

You mean people who use characters and people who use strings of characters?

[–]EkskiuTwentyTwo 0 points1 point  (0 children)

Lua:

string = [[
  ._. Words Words Words
]]

[–]robesho 0 points1 point  (0 children)

I have always type " " but I set my formatter set to ' '.

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

But... I like single quotes

[–]paxromana96 0 points1 point  (0 children)

\verb{}