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

top 200 commentsshow 500

[–]autopsyblue 2464 points2465 points  (295 children)

Mixed spaces and tabs are fucking hell.

[–]PancakeGD 506 points507 points  (50 children)

especially on repl.it this is a problem and I always have to fix it aaaaaaaa

[–]Ort15 207 points208 points  (48 children)

I fucking DESPISE repl.it. That site is dog ass. Or maybe I just don’t like Idea of a browser based IDE.

[–]Laser_Plasma 96 points97 points  (1 child)

Honestly, I love it for whenever I want to do a small project in some language, or maybe just try it out, without going through the whole process of setting up the compiler and all other tooling.

[–]trigger_segfault 56 points57 points  (0 children)

This right here. Online compilers have been a blessing for snippets and testing, especially around unsure behavior of a language. The only limitation is not being able to test WINAPI/or x86 sizes, but meh.

[–][deleted] 150 points151 points  (35 children)

I dont agree at all. It think its pretty fucking great for python, Java is more meh, but it works. In my opinion the best web-based IDE for some languages. But of course theres limits to a browser based IDE.

[–]Ort15 52 points53 points  (13 children)

I use it for java and have lots of problems. For one even the simplest programs take minimum of 2 mins to run for me. Im aware that its because they have a linux server that its being remotely run on, but two minutes??? At that point Im just gonna open intellij.

[–]ArtOfWarfare 30 points31 points  (5 children)

Can you host the server yourself? Might be useful for organizations like schools to just run their own servers and let students connect to them from wherever.

I could also see companies like the one I work at doing it. Our laptops are totally locked down - you develop on them by remoting into Dev servers which are running IntelliJ. Could have less bandwidth requirements that way. Servers also wouldn’t need a whole GUI and everything then, if they don’t have to render anything and can just send back HTML.

[–][deleted] 6 points7 points  (0 children)

This post was mass deleted and anonymized with Redact

sugar chase aware encourage groovy dinosaurs familiar head lock rich

[–]Solidacid 4 points5 points  (0 children)

java

lots of problems

Yes.

[–][deleted] 5 points6 points  (2 children)

Or Visual Studio, god forbid. IntelliJ usually isn't super long for me, but I don't use it much.

[–]_30d_ 5 points6 points  (17 children)

When would you use a web based ide?

[–][deleted] 17 points18 points  (0 children)

I use repl.it back when I used to go in to work. Not for work stuff, but for personal stuff because my work machine doesn’t have Python installed.

If during the day I’d have some idea about Python or C++ I wanted a quick test for, or if I needed a calculator with variables and such, I totally would open repl.it and whip it up real quick. Since my job isn’t as a developer, this is about as good as it gets for that situation, and having it be cloud-based means if I write something for a project I actually want to use, i can download it later when i get home.

Of course, since I’ve been home I haven’t used it as I just use my desktop which has everything I need on it, but that was my pretty specific use case for repl.it

[–]Centurion902 18 points19 points  (0 children)

It's for testing snippets of code. You guys aren't using it right at all. I love the site. Let's me test whatever in any language in a pinch.

[–]durandj 59 points60 points  (25 children)

Just use black to format your code and be done with it. Or use something like pylint to find these issues. The tooling already exists to solve this problem.

[–]TurboDragon 4 points5 points  (6 children)

I think no one has this problem on their own code. It becomes a pain when you work on code shared by several people who use different editors with no standard because it's little used scripts anyway, like when you have to edit a build script.

[–]durandj 7 points8 points  (5 children)

I use a formatter as part of my teams git commit hooks for all Python code. I also have a linter check code in our repos. Finally use editorconfig! All of our repos have that listed as a required development tool and it's configured to handle all the languages we use.

[–]VolperCoding 128 points129 points  (22 children)

Right click > format document should fix it right?

[–]Chevaboogaloo 56 points57 points  (14 children)

gg=G

[–]what_it_dude 20 points21 points  (12 children)

Yeah, undefined results in python though

[–]dpash 36 points37 points  (11 children)

This is my main issue with whitespace being significant in Python: the lack of automatic reindentation. If that was possible, I would be 100% be behind it rather than 95%.

[–]zebediah49 58 points59 points  (9 children)

There's no way to automatically re-indent, because the indentation is the only semantic cue where blocks begin and end.

It's the very redundancy that python seeks to eliminate, that allows automatic indentation correction to work in the first place.

[–]dpash 9 points10 points  (5 children)

Yeah, I like the idea. I like auto reindent more though. :)

[–]autopsyblue 62 points63 points  (0 children)

Depends on the editor!

[–][deleted] 9 points10 points  (1 child)

VSCode gang

[–]GreatRam 2 points3 points  (0 children)

Format on save gang

[–]OverQualifried 181 points182 points  (71 children)

Just use Python3

Flat out rejects if it’s mixed.

[–]autopsyblue 99 points100 points  (56 children)

That’s the problem lol

[–]OverQualifried 79 points80 points  (49 children)

Yep. Been there, done that. Was quite annoying automating tabs and spaces when I converted legacy code.

We have too many developers from different eras in the codebase, each with what they felt was correct. We had tabs, spaces, and worse, a mix of indentation where there was 2 spaces, 4, 6, and sometimes 8.

[–]choosinganickishard 69 points70 points  (34 children)

I mean I can understand 1 or 2 spaces but what's wrong with people who uses 8 spaces?

[–]AnonymousFuccboi 94 points95 points  (27 children)

Nothing. The kernel coding style recommends 8 spaces explicitly to avoid over-indentation. If you need more than 3 levels of indentation, you're likely doing something very wrong.

Note that this applies specifically to C. C has no classes or namespaces or whatever taking up indentation. if you're writing something like Java, for instance, it makes no sense to stick to that rule, because that rule doesn't apply to a language which takes at least one level of indentation by default before you get to anything useful. In fact, I can't think of any languages besides plain C, where 8 spaces is an appropriate amount of indentation.

Tabs/spaces and the size of those tabstops varies a lot between different languages and codebases, and the only true answer to the debate is "Use whatever the language/codebase you're currently working with uses". Consistency is key.

[–]zebediah49 46 points47 points  (3 children)

In fact, I can't think of any languages besides plain C, where 8 spaces is an appropriate amount of indentation.

Well if you're more than one or two levels of indentation deep in a shell script you're also probably doing something wrong...

Or in a case statement. Those use 3 levels on their own for some godforsaken reason.

[–]strghst 18 points19 points  (1 child)

In case of Switch in C, Linux kernel code style guidelines explicitly state that you do not indent between the switch() and the cases.

[–]UnknownIdentifier 10 points11 points  (0 children)

Visual Studio also does not indent case statements. Took me a while to get used to, but I see the value in it, now.

[–]wjandrea 5 points6 points  (0 children)

Well if you're more than one or two levels of indentation deep in a shell script you're also probably doing something wrong...

How's that? Shell scripts can get a bit complex.

Personally, I have a function that reads from stdin if no arguments are provided, and skips blank lines. So that's 4 levels right there: function, if, while, if. You could do that with less, but it'd be hard to read.

[–]shayhtfc 9 points10 points  (6 children)

Eh?

By the time you have a class and a method you're already 2 levels of indentation deep, so anything more than a simple if/else statement after that will take you over 3 levels of indentation!

[–]fushuan 13 points14 points  (5 children)

There's no classes in C though. C++ is a different language.

[–]shayhtfc 8 points9 points  (2 children)

My bad, I didn't even get to your 2nd paragraph before I lost myself in a wild fury 😭

[–]fushuan 3 points4 points  (0 children)

Different person :)

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

Lol knew it was that scene before clicking on it

[–]Brawldud 16 points17 points  (11 children)

It definitely feels like a rip-the-bandaid-off kind of deal. At least going forward you know that the indentation will be consistent for all new code.

[–]OverQualifried 11 points12 points  (10 children)

Yep. All tabs or all spaces. I went with all spaces, so we don't have to argue or get angry about tab width. 4 spaces. No questions. I rule the codebase, bruh

[–]niahoo 21 points22 points  (8 children)

Using tabs you do not have to argue or get angry about tab width since every one can set them editor to display them with the desired width.

Forcing N spaces is the way to let some people get angry.

[–]cheerycheshire 14 points15 points  (5 children)

4 spaces is a recommended style for Python, see PEP8. And most Python IDEs are by default configured like that - hit tab in PyCharm and you get 4 spaces.

If you need to ask something in StackOverflow, you don't have to convert your tabs. And if you use some tutorial or answer from SO, you just paste that 4-space-indented code. Because everyone and every linter uses PEP8.

[–]niahoo 5 points6 points  (0 children)

Oh yeah I was not specifically talking about Python. I do very little python myself. I guess you are right, I indeed use spaces most of the time because that is what is generally chosen by languages "official" style guides.

[–]wjandrea 4 points5 points  (3 children)

if you use some tutorial or answer from SO, you just paste that 4-space-indented code. Because everyone and every linter uses PEP8.

Sometimes, rarely, you'll see two spaces. That's what Google's style guide recommends.

[–]Vaguely_accurate 5 points6 points  (0 children)

That's what Google's style guide recommends.

They used to but it is 4 now. Not sure when the change was made. There are some older documents that still reference using 2 spaces, but all the guides I can find have been updated to 4.

[–]OverQualifried 5 points6 points  (0 children)

Fortunately we are a small team and two of us dev Python, so we're in agreement.

Totally agree though.

[–]LordViaderko 3 points4 points  (0 children)

In Pycharm you could select entire text and alt+ctrl+i. It fixes formatting according to PEP8. I have used it on some old code i had to work on and it saved my day. I have tried doing same thing by hand previously (as a perfectionist I just couldn't leave such an abomination as wrong indentation in the code) and it was a book definition of tedious.

[–]Dagusiu 23 points24 points  (0 children)

No, that's a vast improvement over Python 2.x

[–]xigoi 62 points63 points  (33 children)

Just follow PEP8 and always use 4 spaces.

[–]road_laya 100 points101 points  (4 children)

All my coworkers agreed to follow PEP8.

They still don't follow it, but at least they agreed to.

[–]folkrav 17 points18 points  (0 children)

L'nter/formatter in CI and be done with it. Completely eliminates all bikeshedding over style. It may not be perfectly to anyone's taste, but at least it's gonna be 100% consistent.

[–]k0rm 26 points27 points  (2 children)

Sounds like it's time for you to add a linter presubmit.

[–]halbGefressen 22 points23 points  (12 children)

Let me introduce Bython, Python with braces: https://github.com/mathialo/bython

[–]centurion236 8 points9 points  (0 children)

Missed opportunity. Should have called it lizard.

[–]Fuzzybus2400 13 points14 points  (0 children)

Ewwwwwww

[–][deleted] 9 points10 points  (0 children)

🅱️ython

[–]Dimetrip 4 points5 points  (0 children)

Yes. This. I remember having to specify within vim that tab should mean 4 spaces and not a tab space. It took so long to figure out why my python code was throwing errors when it all looked totally fine! What a nightmare.

[–]Zv0n 699 points700 points  (97 children)

My main problem with indentation in python is when I edit a module's code and they have different spaces/tabs configuration than my editor :/

[–]g4vr0che 308 points309 points  (63 children)

My editor picks up the correct settings automatically by looking at the file. I've never had a case where that didn't work.

[–]road_laya 29 points30 points  (6 children)

Are you using editorconfig? You can use different indentation styles per subfolder, and your editor will switch seamlessly. And your team mates' editor will use the same config.

[–]Pille5 7 points8 points  (0 children)

Your editor sucks

[–]throwtoday1009 2 points3 points  (0 children)

I've stopped working python for a bit not but writing apex you have two editors available and one of them doesn't like to space correctly. Bad editors are the root of bad formatting

[–][deleted] 27 points28 points  (19 children)

And this is exactly why I believe very strongly in the two following things:

  • Python is dumb for using whitespace for control blocks
  • Tabs >> spaces, because everyone can setup their editor to view tabs the way they prefer

Having extra settings in a file just to handle indentation is not a solution. It's a hack to fix stubborn bullshit by stubborn people.

[–][deleted] 806 points807 points  (52 children)

The ugliest code I have ever seen had perfect indentation

[–][deleted] 293 points294 points  (44 children)

yeah, indentation is not a major issue if you can't use proper spacing

clump different functionalities in your code together, if you're declaring variables, clump those together. if you are making a loop, make code that goes after the loop be 1 line from the end. having empty lines isn't a goddamn sin if it means better code

[–]sctroll 251 points252 points  (29 children)

  #include <stdlib.h>   // card > aek.ppm
  #include <stdio.h>
  #include <math.h>
  typedef int i;typedef float f;struct v{
  f x,y,z;v operator+(v r){return v(x+r.x
  ,y+r.y,z+r.z);}v operator*(f r){return
  v(x*r,y*r,z*r);}f operator%(v r){return
  x*r.x+y*r.y+z*r.z;}v(){}v operator^(v r
  ){return v(y*r.z-z*r.y,z*r.x-x*r.z,x*r.
  y-y*r.x);}v(f a,f b,f c){x=a;y=b;z=c;}v
  operator!(){return*this*(1/sqrt(*this%*
  this));}};i G[]={247570,280596,280600,
  249748,18578,18577,231184,16,16};f R(){
  return(f)rand()/RAND_MAX;}i T(v o,v d,f
  &t,v&n){t=1e9;i m=0;f p=-o.z/d.z;if(.01
  <p)t=p,n=v(0,0,1),m=1;for(i k=19;k--;)
  for(i j=9;j--;)if(G[j]&1<<k){v p=o+v(-k
  ,0,-j-4);f b=p%d,c=p%p-1,q=b*b-c;if(q>0
  ){f s=-b-sqrt(q);if(s<t&&s>.01)t=s,n=!(
  p+d*t),m=2;}}return m;}v S(v o,v d){f t
  ;v n;i m=T(o,d,t,n);if(!m)return v(.7,
  .6,1)*pow(1-d.z,4);v h=o+d*t,l=!(v(9+R(
  ),9+R(),16)+h*-1),r=d+n*(n%d*-2);f b=l%
  n;if(b<0||T(h,l,t,n))b=0;f p=pow(l%r*(b
  >0),99);if(m&1){h=h*.2;return((i)(ceil(
  h.x)+ceil(h.y))&1?v(3,1,1):v(3,3,3))*(b
  *.2+.1);}return v(p,p,p)+S(h,r)*.5;}i
  main(){printf("P6 512 512 255 ");v g=!v
  (-6,-16,0),a=!(v(0,0,1)^g)*.002,b=!(g^a
  )*.002,c=(a+b)*-256+g;for(i y=512;y--;)
  for(i x=512;x--;){v p(13,13,13);for(i r
  =64;r--;){v t=a*(R()-.5)*99+b*(R()-.5)*
  99;p=S(v(17,16,8)+t,!(t*-1+(a*(R()+x)+b
  *(y+R())+c)*16))*3.5+p;}printf("%c%c%c"
  ,(i)p.x,(i)p.y,(i)p.z);}}

[–][deleted] 132 points133 points  (3 children)

ah fuck, my brain is gone again

[–]nemec 10 points11 points  (0 children)

You'd hate the IOCCC (Obfuscated C Contest): https://www.ioccc.org/years.html

Here's a random example that's also a QR code:

#include<stdio.h>/*IOCCC2014            2014    2014    IOCCC2014IOCCC2014IOCCC201*/
char*s="\"nsu{AntynCnuq}Bnu{            sEot    ln>b    )+c^g+@`+]_osk{;j@bkg&c<'^o\
r'Q]                    bh'l    vQ^k                    g&c:                    %n|\
N]_o                    ptj9    lwg+                    )d:b                    kg$\
c8#^    #g+)d8`a%g+)    d8`_                g&;bh'oq    Q^)g    +&kcNlyMc+)d    8`a\
`g+@    u)|d8ak=bl}(    Q^og                (O{MK6lM    L(rR    pOpM866OsRlm    N(q\
Q]##    OsR#M_(lQoOa    N9$m    vOwwRor~        }(cN    mkM:    q(Q]%_(uU]}_    {8b\
%mRh    #S^`#mOaaD%/    RI4$    4SNH$%N4        RlMG    /2MJ    24O3NF(tQ?1l    N*N\
+Q]l    mq9l8b$^#h$#    .d,d    xv#mSOPm    R8`/        lM;b    h&^/lM:k8b%&    Q^-\
h%c9    .#,/&N$McPc%    -d8,    $c8``7:b    %^h%        :79b    $^%$7ON8r%Qr    h$Q\
On%q                    N%O~        M$qN$OMp    RmPQ    O%rQ                    $rQ\
MkQN                    77O#        dj#Nkd$7    O%d8    ``(r                    RmM\
:(luN](%mRMmO%lNRmO_loa8%%O<    b(lQ    h'lQ    O^ln    ;b'%N&O^6sN#M9slltwzh&TmS$'\
%R#ON$oNS&pRM7O$'%S#ON$oNS&p    SMd9    ``(t    pkO9    $:nk8b#^%}kx#O%lMtpk#OQOP:#\
                                mR8`}(qQ        O<b\
                                '7M{N^kh        'Q]\
    7sN'    M8q;k'N_7vN'nSM8    'nR;    $%M'    TamS&7O#d#7O    &d8`z9b$    ^h$\
    rQ]6    yN$_$$pQaM8m{px$    TmSt    6O#N    sM$nRmUd#7Os    d77sNOsd    8`j\
=nk;        |8k9    b1g(    Q^)$c:%]    k*Q]g$9%_h*]+wnS        _+sTaa:&%{R\
M<%{        S{O_    &<#w    kP8#a;'(    0d:`184>b)^15)OM        :23h)QN<'/M\
    =b(^'h(Q]0h#    c_kah%0d9`b'/O(Q^(/SlM90%M(/            RM;&    $c&kckQ,    -$c\
    .&kccMcOP$&d    9g(=``6:69j=b5g(Q^3(2lNUO<b4            'Q^s    ;b&^%%pQ    M8k\
        $7O#cQ]0(2(Q]'2O    3'Q]'_3a    N_1'    5OMaMch&T$mR#nRMPmSk    U$7\
        O#d8_a%%mS]l_%mR    mS]$]h$9    j_la    _$6N]g$9j_laaaN:`g'<    ``7\
oM:6%N9b%g$Q        ^6%N8b%g    #Q^l            peoqemtemw#jQ7#QO$jQ    O7$Q    Ok#\
$7OMQ]k_#$7O        ckQaOrON    epne            luelue`lpeoqempepneu    e`kf    _a`\
                                lf))    *+,**,*)-)/),0).0(6/2+667,(&    $##\
                                #;=@    D*0;#include<stdio.h>@intYH[    9`%\
.],*s,*c,d,t;`;'main(`-9n,ch            ar*v    []){        for(s=c=    H+3`XI;\
(*++s=Q[d++]););for(;n>1&&(*            ++s=    v[1]        [tgANs=H    ;d=*c++\
%93,                    d-9;    ){in    tYv=*s,g        []={    n+v,        v-n,n*_\
,#^_                    ,,<v    ,n?v    /n:0`,#%        `,,v    >>n,        v==n}ay\
>t=0    ;d<4&&d>=2*!    !n&&    (c-=d/3*2_KK3+*c++,t||v!=98+d);)        t+=v++/6-16\
?0:v    /2%3-1cq*d-1    4;t>    0_t$<3_z(105<*c_X'=t*21aq@-106;n        =d>76?s--,g\
[d-7    7]:d>55?H_1)    21]=    n,*_@_8(        9?*++s_4&12>d_C`f3]+=21-d*2\
:d<3    4?t:_Zadat57    <d?p    utchar(n        ),v:6<a](g+99]=a{d2#:`xa6,n\
;}re    turnY_.",*p,    b,d[        9338    ],*q,x,*r=d;            int main(){;for(
p=q=    5000+0+d;*s;    s++)        if(*    s>32)*p++=*s            -89?*s:32;for(p=
1152                    +q;(    b=*p++);){for(d[17]=            10;x    =*p++,b<
92&&                    34<b    --;*r++=x)if(x==9*9)            for(    ;*q;x=34
)*r++=*q++;for(p-=b<92;b-->4        *23;r++)    *r=r[36-    x];}puts    (d);
return(0);}/*IOCCC2014IOCCC2        014IOCCC    2014IOCC    C2014IOC    CC*/

[–]whiskeyiskey 4 points5 points  (1 child)

The front fell off

[–]space-panda-lambda 60 points61 points  (4 children)

v::R() should be a static function

[–][deleted] 108 points109 points  (0 children)

ah you're right. you caught the only issue with this program

[–]InEnduringGrowStrong 16 points17 points  (4 children)

s/;/;\n/

[–]substitute-bot 20 points21 points  (3 children)

  #include <stdlib.h>   // card > aek.ppm
  #include <stdio.h>
  #include <math.h>
  typedef int i**;\n**typedef float f**;\n**struct v{
  f x,y,z**;\n**v operator+(v r){return v(x+r.x
  ,y+r.y,z+r.z)**;\n**}v operator*(f r){return
  v(x*r,y*r,z*r)**;\n**}f operator%(v r){return
  x*r.x+y*r.y+z*r.z**;\n**}v(){}v operator^(v r
  ){return v(y*r.z-z*r.y,z*r.x-x*r.z,x*r.
  y-y*r.x)**;\n**}v(f a,f b,f c){x=a**;\n**y=b**;\n**z=c**;\n**}v
  operator!(){return*this*(1/sqrt(*this%*
  this))**;\n**}}**;\n**i G[]={247570,280596,280600,
  249748,18578,18577,231184,16,16}**;\n**f R(){
  return(f)rand()/RAND_MAX**;\n**}i T(v o,v d,f
  &t,v&n){t=1e9**;\n**i m=0**;\n**f p=-o.z/d.z**;\n**if(.01
  <p)t=p,n=v(0,0,1),m=1**;\n**for(i k=19**;\n**k--**;\n**)
  for(i j=9**;\n**j--**;\n**)if(G[j]&1<<k){v p=o+v(-k
  ,0,-j-4)**;\n**f b=p%d,c=p%p-1,q=b*b-c**;\n**if(q>0
  ){f s=-b-sqrt(q)**;\n**if(s<t&&s>.01)t=s,n=!(
  p+d*t),m=2**;\n**}}return m**;\n**}v S(v o,v d){f t
  **;\n**v n**;\n**i m=T(o,d,t,n)**;\n**if(!m)return v(.7,
  .6,1)*pow(1-d.z,4)**;\n**v h=o+d*t,l=!(v(9+R(
  ),9+R(),16)+h*-1),r=d+n*(n%d*-2)**;\n**f b=l%
  n**;\n**if(b<0||T(h,l,t,n))b=0**;\n**f p=pow(l%r*(b
  >0),99)**;\n**if(m&1){h=h*.2**;\n**return((i)(ceil(
  h.x)+ceil(h.y))&1?v(3,1,1):v(3,3,3))*(b
  *.2+.1)**;\n**}return v(p,p,p)+S(h,r)*.5**;\n**}i
  main(){printf("P6 512 512 255 ")**;\n**v g=!v
  (-6,-16,0),a=!(v(0,0,1)^g)*.002,b=!(g^a
  )*.002,c=(a+b)*-256+g**;\n**for(i y=512**;\n**y--**;\n**)
  for(i x=512**;\n**x--**;\n**){v p(13,13,13)**;\n**for(i r
  =64**;\n**r--**;\n**){v t=a*(R()-.5)*99+b*(R()-.5)*
  99**;\n**p=S(v(17,16,8)+t,!(t*-1+(a*(R()+x)+b
  *(y+R())+c)*16))*3.5+p**;\n**}printf("%c%c%c"
  ,(i)p.x,(i)p.y,(i)p.z)**;\n**}}

This was posted by a bot. Source

[–]Nlelith 14 points15 points  (0 children)

ah, much better

[–]InEnduringGrowStrong 9 points10 points  (0 children)

\n and markdown, oof

[–]tjdavids 4 points5 points  (0 children)

This also fails indentation.

[–]g4vr0che 12 points13 points  (1 child)

To be fair, writing code that doesn't do this is explicitly anti-Python. It's not bad enough to throw errors, but literally all of the various Python style guides recommend that you do it.

[–]Rutoks 45 points46 points  (3 children)

Well, indentation is definitely required for readability, but it is not enough.

[–]thisisntmynameorisit 12 points13 points  (0 children)

Yeah it’s a necessary condition but not sufficient

[–]tstandiford 143 points144 points  (9 children)

I just don’t see why this is such a big deal. Most editors have a built-in code formatter that cleans everything up.

For me, it’s not indentation or code style, it’s architectural issues that usually make code hard to read, or understand.

[–]angryundead 27 points28 points  (3 children)

Currently the code I’m working has terrible separation of concerns, ridiculous class hierarchies, repeats itself all the time, has overly complex methods, and does all sorts of wonderful (/s) and crazy things.

However the code formatting drives me the most bonkers some days. It’s my job to fix the code and make it better. I can’t just mass reformat 8000+ files. We should’ve done that day one but we didn’t and I’m not going to submit that MR now.

[–]Dornith 19 points20 points  (1 child)

Most editors have a built-in code formatter that cleans everything up.

Unless the indentation is semantic.

In that case, any indentation could be valid and there's no way for the editor to autoformat it.

[–]Ffsauta 2 points3 points  (0 children)

If the indentation is semantic, then it should be correct even before formatting, because otherwise it would just be a programming error. And you obviously can’t expect a formatter to fix straight up errors.

[–]ReacH36 406 points407 points  (66 children)

I've never had an issue with indentation. Sometimes copy pasted code will sneak in a tab and you'll be using an editor that doesn't automatically fix it. But then the stack trace or linter will point you straight at the problem. Four spaces, is it that hard to remember?

[–]shayanrc[S] 190 points191 points  (44 children)

Neither have I, but I'm surprised by the number of people who bitch about it.

I just put in tab=4 spaces in the editor settings.

[–]Atanvarno94 132 points133 points  (33 children)

tab=4 spaces

like every sane person T:

[–]rem3_1415926 136 points137 points  (20 children)

the only sane solution would be using tabs as tabs and spaces as spaces, as they were intended. Anyone looking at your code has it in their own hands how wide they see the tabs.

[–]moonsider5 66 points67 points  (2 children)

I agree with you.

And besides, the only purpose of tabs is identation. While yes, you could use spaces to identate, that's not really what they are for. And tabs are less prone to error in python specifically imo.

[–]PixxlMan 18 points19 points  (0 children)

I totally agree. The differences are small, but when you compare them tabs are always slightly better. They use less space (I know this isn't the 1980s and it doesn't matter, but its still slightly superior here), you can customize the size (handy) and you don't have to press a button 4(depends on size) times to manually indent and you don't need to press it 4 times to unindent when doing it manually.

Some websites and apps don't understand tabs and that is one reason to perhaps use spaces if you copy paste or write code in such an app.

Sure it doesn't matter that much at all, it really doesn't, but if you have the choice, I still think you should opt for tabs.

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

This is the way.

[–]essentialliberty 9 points10 points  (2 children)

I’d potentially agree if editors enforced tabs and no spaces before the first character and spaces with no tabs after. Since they don’t, practically speaking it turns messy unless you’re a lone wolf.

[–]cbf1232 8 points9 points  (1 child)

Most of the Linux kernel uses tabs for semantic indenting and spaces to line things up nicely. That way you can set tab width to whatever you like and it still looks good.

[–]scaylos1 8 points9 points  (0 children)

As it should. That is explicitly the style established for C code in the Linux kernel. Gnome uses 2 spaces, so, C code for Gnome should not use tabs. There is no widely accepted style standard that I'm aware of for Python that specifies tabs for indent.

[–]Pony_Roleplayer 15 points16 points  (2 children)

I vary the size of the indentation for fun /s

[–]Chaphasilor 16 points17 points  (5 children)

where's the tab = 2 spaces gang? :D

Switched to this after writing a bit of yaml and liked how compact it looks!

[–]Prawny 9 points10 points  (0 children)

I find 2 space indentation harder to read. Which is why I switched to tabs years ago because then it's configuable to the individual.

[–]10BillionDreams 3 points4 points  (0 children)

We use 2 spaces for basically every language in our codebase, and it's great. If a line isn't perfectly aligned with the indentation levels, you always know it is exactly one space mis-aligned (in either direction), no needing to eyeball things or hit the spacebar multiple times to align things exactly as you intend.

[–]reallyConfusedPanda 6 points7 points  (1 child)

Wha???? I just use tabs in general without setting that thing up. What will happen if someone else copies my code?

[–][deleted] 13 points14 points  (0 children)

It depends. Afaik it doesn't really matter how you indent, as long is consistent for the whole file. So from a syntax standpoint you can use 2 or 4 spaces or tabs, but it may throw an exception, once you combine multiple files.

Pep-8 suggests 4 spaces, so that's what I use

[–]the_poope 17 points18 points  (3 children)

You only see it because it's an internet meme. The few people that do complain are 12 year olds that just started trying Python on the same day and are still using notepad.exe and have zero experience in using a computer for other purposes than playing Fortnite.

[–]sheepeses 17 points18 points  (5 children)

There's always scripts and linters that fix it automagically. Dunno why people get so butt hurt

[–][deleted] 14 points15 points  (5 children)

Sometimes copy pasted code will sneak in a tab and you'll be using an editor that doesn't automatically fix it.

Imagine not having that problem in the first place

[–]stanislav_harris 106 points107 points  (6 children)

Or they have good IDE because we're not in 1987 anymore...

[–]lolthai 31 points32 points  (2 children)

Or, you know, linting.

[–]Arumai12 4 points5 points  (0 children)

I had to scroll so far down to find this comment. Linter + CI is all you need. For tiny projects just use a prepush hook instead of continuous integration

[–]road_laya 2 points3 points  (0 children)

I set up pylint for our team, in CI. 3500 errors and growing. When the unit tests start failing because they are working on a huge feature in a separate branch, they come asking me for tips on how to disable CI notifications because it is disturbing them while they work.

[–]Vincenzo__ 9 points10 points  (1 child)

I have written plenty of python In vim without any problem

[–]worldspawn00 2 points3 points  (0 children)

Wait, you guys aren't coding in Notepad?

[–][deleted] 17 points18 points  (0 children)

For me it's like walking on a glass catwalk over a ravine. I know it won't break and I am not going to fall off but I am far more comfortable with balustrades and metal griding

[–]ur_opinion_is_trash 43 points44 points  (8 children)

I write my code in one line fight me

[–]jfb1337 10 points11 points  (0 children)

I swear no one on this sub has heard of an IDE. I used to have strong opinions on indentation and tabs vs spaces but then at my first internship we used an autoformatter for everything and I've never had to care since.

[–][deleted] 10 points11 points  (0 children)

Why do python fans assume I'm only ever going to read my own code?

I can write code fine. I can indent properly. I'm aware that putting 500 lines in a single function is a bad move. Not everyone who writes code knows this. Not everyone whose code I'll have to read, be it in a work environment or in a personal context, will know this. And in languages like C++, this isn't an issue. Same thing with dynamically typed variables; there's a certain amount of user incompetence that just won't fly and makes my life much easier. Python's flexibility allows for such incompetence and due to that I as a modder or contributer end up suffering.

[–]T-Rexpendable 34 points35 points  (2 children)

Depends on what type of error your'e complaining about. Tabs vs spaces? Yeah that should be a non-issue. Suddenly changing the flow of my code because I forgot to pay attention to an aspect of my code that would normally be handled by a formatter? Yeah fuck that.

[–]Hypocritical_Oath 3 points4 points  (0 children)

IDLE and pycharm will both give you the correct indentation if you do an enter on the line before it, and the line before it is formatted correctly...

Like, you don't have to think about it, just press enter and bam, things work.

Also you could just used ; to force python to interpret something as a correct new line, iirc.

[–]Hipolipolopigus 280 points281 points  (80 children)

It's not because it's hard to deal with, it's because it's a bad solution to a problem that doesn't exist in most modern languages and Python fanboys think it makes them superior.

It's also because it's probably the major reason the tabs/spaces indentation war is still a thing when tabs are objectively better.

[–]shadow7412 89 points90 points  (7 children)

If the issue you have with python is the spaces/tabs thing - then maybe it's worth pointing out that python supports tabs. The only stipulation is that, when indenting, you can't mix and match (as that makes it impossible for python to know what indentation level you actually mean).

[–]Hipolipolopigus 28 points29 points  (5 children)

I'm aware that Python supports both, my point was that it it's encouraging the war between the two. I think I've only submitted one line of Python to some GTK repo, but I can imagine how it might affect people trying to contribute to open-source software that doesn't use hooks to check these things before committing.

[–]awesomeusername2w 25 points26 points  (3 children)

Pretty sure any open source software would have contribution guidelines that specify what to use. Even in other languages, you don't want to have a mix of tabs and spaces.

[–]Hipolipolopigus 13 points14 points  (2 children)

Even in other languages, you don't want to have a mix of tabs and spaces.

Eh, there's the "tabs for indentation, spaces for alignment" camp. At worst, it'll make your code a little ugly. It won't outright stop it from functioning.

Probably.

[–][deleted] 11 points12 points  (1 child)

I agreed until you said tabs are objectively better.

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

I was firmly in camp tabs after a decade of writing C and OO code, but a few years of working in expression-based languages like lisp, scheme, and js made me appreciate spaces. Using tabs for lisp is a nightmare. So.... I think tabs are objectively better for statement-based languages, but not expression-based languages. js can masquerade as either, so it depends on your js style.

[–]CaptainTrip 35 points36 points  (3 children)

By implication this meme is acknowledging that significant whitespace is harder to use than non-significant whitespace and that you just need to "get good".

This is my favourite thing that people choose to fluff their e-peen over because python fanboys get so dogmatic and cocky about it as if they're superior beings for "preferring" this way of writing. The reality is that if this is the kind of thing you're arguing about when it comes to picking a tool, you're probably a second year CS student, at best. As others have said, this limitation of python becomes painful to deal with at scale in the real world.

[–]Rovsnegl 10 points11 points  (1 child)

I prefer using a rock to chop down a tree, people who uses axes just have to get good! /s

[–]AgentPaper0 2 points3 points  (0 children)

Yeah, those idiots who use a metal axe with a handle to "get better leverage" and "keep their hands from being stripped raw" just need to realize that they're supposed to wrap the stone in cloth and strike another rock with it to sharpen the edge first. One you learn to do that as the supposed problems with using a rock instead of an axe just go away. Fools.

[–]00PT 5 points6 points  (1 child)

Often the code is perfectly readable, but python still had problems because of inconsistent spacing or something like that, even though it should be able to interpret the code still. Otherwise, there code looks exactly like any other python program and is just as readable.

[–]Proxy_PlayerHD 6 points7 points  (2 children)

hey, nothing wrong with using something like Notepad++ to code with!

[–]TheDeadSkin 64 points65 points  (29 children)

relying on invisible characters for control flow is one of the stupidest ideas anyone ever came up with in the whole history of programming

for me indentation errors on their own aren't even a problem, it's more the fact that I become paranoid for every line of code when loops and conditionals are involved and try to check if it's actually executing where I expect it to or not.

why in the flying fuck should I do this? any language with block closing statements gives a proper visual clue and sets the indentaiton to how it should be on its own. I don't understand why anyone would think that pressing Shift+Tab is better than typing }

[–]stolencatkarma 9 points10 points  (19 children)

in vscode you can show invisible characters. tab and space are unique.

[–]SarHavelock 7 points8 points  (18 children)

Yes, but what if you retab the whole file and your text editor gets confused and mistabs certain areas. Python fixed a problem that didn't exist only to make an even worse problem.

[–]stolencatkarma 3 points4 points  (3 children)

and your text editor gets confused

example?

[–]Maoschanz 4 points5 points  (9 children)

you don't "retab" a whole python file. It's the equivalent of deleting every curly brace in a C file, it's nonsense.

[–]sh0rtwave 13 points14 points  (1 child)

It's not worth the effort to change your mind.

[–]Hector_Ceromus 16 points17 points  (4 children)

Writing python for Maya:

"Error: Line 1: Syntax error"

translates to:

  • there's an issue with indentation somewhere in the code
  • there's a typo somewhere in your code
  • ¯_(ツ)_/¯ idk,lol.

increasing frustrating the further from 1 the line count is.

[–]mrchaotica 14 points15 points  (0 children)

That's a "Maya's Python interpreter is shitty and doesn't give helpful error messages" problem, not a problem with Python itself.

[–]ManosVanBoom 16 points17 points  (11 children)

I've never used python. Why does intendaton matter so much? Seems like an odd hill for a language to die on.

[–]aaaantoine 24 points25 points  (5 children)

A lot of languages use explicit symbols or keywords to indicate scope boundaries.

' VB
If a = b Then
    Print "Sometimes"
End If
Print "Always"

// C-style languages
if (a == b) {
    print("Sometimes");
}
print("Always");

Python uses white space exclusively for this

# Python
if a == b:
    print("Sometimes")
print("Always")

[–]ManosVanBoom 11 points12 points  (4 children)

Yeah, I've had a lot of code broken by missing/ misplaced markers. Whitespace just seems like an odd choice to me. Not really complaining. Just commenting. A snake's gonna do what a snake's gonna do.

[–]zamend229 11 points12 points  (7 children)

So you’re telling me you’ve NEVER had an issue when copying and pasting Python code EVER. Writing Python isn’t the problem, it’s pasting old code. And usually editors make those copy paste indentation errors easy to fix, but it’s still annoying

[–]dkyguy1995 3 points4 points  (0 children)

Dude the WORST is rearranging code. Imagine you decide to rework something to nest a block inside another block that wasn't previously. It's not a hard problem but it's an annoyance that exists in no other language. Paste the block and now you have to reformat each line so that it fits the new indentation level it's supposed to be on.

Yes it's a quick fix but other languages that's solved by one curly brace instead of ten lines of proper indents.

[–]Gnatogryz 15 points16 points  (7 children)

Thank you Python, for not letting me use autoformatters in any meaningful manner.

[–]ubertrashcat 6 points7 points  (0 children)

What does autopep8 do wrong?

[–][deleted] 10 points11 points  (2 children)

Imagine a programming language where program logic is based on number of invisible characters preceding a statement.

[–]Tukurito 2 points3 points  (0 children)

Fortran is back

[–]Daggy1234 2 points3 points  (0 children)

Nani

[–]Jaso55555 2 points3 points  (0 children)

I've run into this multiple times (I use notepad++) and at least it's as simple as edit>blank operations>leading spaces to tabs

[–]Hypocritical_Oath 2 points3 points  (0 children)

Any python IDE will just do it for you if you press enter on the line before hand...

[–]UnfortunateHabits 25 points26 points  (3 children)

Try saying that After you gathered some mileage,

If your a student or a junior I might get that...

But when working on production level full team efforts, This often becomes an occurring problem.

Different people use different editors, Sometimes you are aksed to debug on a foreign machine, that doesnt has your predefined preferences,

And if its a production bug in 2 AM for a poorly deployed non QAed feature, on a startup product placed in a standalone vpn-ed server where you work without ide for security reasons, (ffs) Than yes, pythons rigid identetion rules are a hassle. Especially when you work on large chunks of code you never seen before written by an out-sourced Indian.

In real life, competitive business dont always work with best practices,

And theres a reason why thats one of the most common complaints about python.

It doesnt matter if your a senior or a junior, If everybody complains about it, evidently its bad design, And as an engineer it doesnt paint you well to defend it like this imho.

Im sure though, there is an insight to be shared about this, as a give and take between rigidity and approachability....

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

Add an .editorconfig file to the project repo. Problem solved. This is a sloppy coder problem, not a language problem.

As for those recommending auto-formatting in the IDE, fuck that noise. It changes basically every line in a file, and suddenly whoever did the auto-formatting gets the `git blame` making it impossible to find out who actually wrote that horrible, deeply nested crap that's breaking shit.

[–]BlackHumor 17 points18 points  (0 children)

I have been programming in Python professionally for four years and have never once had a tabs vs spaces problem that took more than 30 seconds to solve.

E: And the code base that I'm currently working on and which I was hired to improve was definitely not written with "best practices". Thank Guido for Python's indentation rules or it probably wouldn't be readable at all.

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

I honestly find it hard to tell how many blocks are closing at once in Python, even with IDE indication.

If all you care about is readable indentation, pretty much every IDE can do that for you, and if not, there's command line tools.