this post was submitted on 28 Feb 2024
996 points (97.0% liked)

Programmer Humor

32079 readers
287 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Dirk@lemmy.ml 77 points 6 months ago (4 children)

Python: So you used spaces and tabs for indentation? NOW DIE!

[–] WhiteHawk@lemmy.world 47 points 6 months ago (2 children)

Mixing spaces and tabs should be a warcrime.

[–] pingveno@lemmy.ml 9 points 6 months ago

And in Python, it's merely a SyntaxCrime.

[–] merc@sh.itjust.works -5 points 6 months ago (4 children)

Find me anyone who claims they use tabs for indentation, and I bet I'll find at least one case where they're using both tabs and spaces.

The only safe way to avoid war crimes is to avoid tabs.

[–] Holzkohlen@feddit.de 7 points 6 months ago (2 children)

Don't IDEs just replace any tab with 4 spaces anyways? Pretty sure VSCode does

[–] _dev_null@lemmy.zxcvn.xyz 4 points 6 months ago

I    don't    use    an    ide,    but    I    wrote    a    script    that    replaces    any    space    I    type    with    four.

I    haven't    worked    out    all    the    use    cases    yet,    though.

[–] merc@sh.itjust.works 2 points 6 months ago

That's a setting in the editor.

[–] HopFlop@discuss.tchncs.de 7 points 6 months ago (2 children)

Why would I use spaces if I use tabs? Also, it seemd like a huge waste of time hitting the space bar so many times...

[–] merc@sh.itjust.works 7 points 6 months ago* (last edited 6 months ago) (1 children)

Why would I use spaces if I use tabs?

To comply with Python's best practices:

https://peps.python.org/pep-0008/

Also, if you work on the Linux Kernel, you'll see a mix of tabs and spaces:

https://elixir.bootlin.com/linux/latest/source/block/bfq-iosched.c#L390

Also, it seemd like a huge waste of time hitting the space bar so many times…

You use an editor that doesn't auto-indent?

[–] FlorianSimon@sh.itjust.works 3 points 6 months ago (1 children)

I assume this was a joke 😁

[–] BeardedGingerWonder@feddit.uk 2 points 6 months ago (1 children)

I use vi without syntax highlighting.

[–] FlorianSimon@sh.itjust.works 1 points 6 months ago (1 children)

Please don't hack me, mister FBI

[–] BeardedGingerWonder@feddit.uk 1 points 6 months ago (1 children)

To be fair you can totally bind an arbitrary number of spaces to tab in vi. I'll dig out the syntax highlighting file some time. Oh and I use vim really.

[–] FlorianSimon@sh.itjust.works 2 points 6 months ago

I do use neovim myself too 😁

[–] dotMonkey@lemmy.world 7 points 6 months ago (1 children)

I use the tab key but I'm pretty sure vs code converts that to spaces

[–] gears@sh.itjust.works 4 points 6 months ago (1 children)

Depends on your settings, but yeah typically it does

[–] merc@sh.itjust.works 1 points 6 months ago (1 children)

It worries me that a programmer wouldn't know for sure what's happening when they hit tab, and that it's a setting that can be changed.

[–] dotMonkey@lemmy.world 2 points 6 months ago

I mean I was 99% sure it convert to spaces, I cannot say I was certain. The default settings are fine for what I do, I only ever had to change the spacing from 4 to 2 spaces once when dealing with someone else's files

[–] ramsay@lemmy.world 3 points 6 months ago* (last edited 6 months ago) (1 children)
[–] xigoi@lemmy.sdf.org 22 points 6 months ago (2 children)

Good. Spaces and tabs for indentation should never be mixed in any language other than Whitespace.

[–] Faresh@lemmy.ml 4 points 6 months ago* (last edited 6 months ago) (1 children)

Some people use tabs for indentation and spaces for alignment. It kind of gets the pros of tabs (user configurable indent-width) and the pros of spaces (alignment). That doesn't work in Python where you can't align stuff and the interpreter doesn't allow mixing tabs with spaces, but in other languages it is a possible style.

[–] BeardedGingerWonder@feddit.uk -1 points 6 months ago

There are no pros to tabs. Configure tabs to a number of spaces.

[–] Dirk@lemmy.ml 3 points 6 months ago

Raw adjust with tabs, fine adjust with spaces.

Don't laugh, people are actually doing that.

[–] malle_yeno@pawb.social 5 points 6 months ago

Mixing tabs and white spaces in 2024 is categorically a you problem lmao

[–] brettvitaz@programming.dev 4 points 6 months ago