217
(page 2) 50 comments
sorted by: hot top controversial new old
[-] potterman28wxcv@beehaw.org 8 points 1 year ago* (last edited 1 year ago)

Interesting take. I prefer spaces because each piece of code that I see with tabs has an implicit tabsize you really need to have if you don't want the code to look ugly - especially if the person has been mixing tabs and spaces - and they usually do. Sometimes unadvertently.

When you remove all tabs at least everyone is on the same page.

To the actual problem raised by the article:

I have ADHD. Two spaces per indent makes it damn near impossible for me to scan code. My brain gets too distracted by the visual noise. Someone who’s visually impaired might bump their font size up really large, and need to scale up or down the amount of space per indent. Someone might just prefer it because…

I wonder if it could be possible to adjust the "indent number of spaces you see" in code editors. Code editors are able to figure out what are indents and what are not, so in theory it should be possible. Perhaps that would be an idea for a new feature?

load more comments (3 replies)
[-] SleveMcDichael@programming.dev 8 points 1 year ago

Tabs let you define how big you want each indent to be, and spaces do not.

Spaces can too: Simply use more or less of them, to taste.

I have ADHD. Two spaces per indent makes it damn near impossible for me to scan code.

Then use four, or six, or eight, or 20. Hell, most code I've seen uses four spaces per indent anyway.

[Re: braille]

Surely there's an editor out there that will automatically display indent spaces as a tab character. Or failing that it seems like it would be rather trivial create a program to convert n spaces to tabs, and vice versa.

[-] kevincox@lemmy.ml 7 points 1 year ago

You are missing the point. Lots of code has multiple authors. There is offer no space indention that works for all authors. With tabs each author or reader can use the width that works for them.

automatically display indent spaces as a tab character

You can't really do this reliably. The problem is that spaces may be used in other places for alignment where the width shouldn't be dynamic. If you do a simple s/ /\t/g you will have funny results where code was aligned carefully using spaces. (The reverse does work though if you want to go from tabs to spaces, because tabs contain more information.)

You could potentially do a good job with a full parser for the language in question to determine the indent level and separate indent from alignment. But I'd rather not rely on this for no reason. Sometimes I don't have a full parser available for every language I want to edit.

load more comments (1 replies)
[-] skulbuny@sh.itjust.works 7 points 1 year ago

laughs in lisp

Nah, I'll keep on sticking with spaces or whatever the language's formatter uses. Ain't no way am I mixing tabs and spaces, will just stick with spaces.

[-] sekhat@lemmy.temporus.me 4 points 1 year ago

I used to be a tabs guy, somepoint over time, especially when I realized some of the edge cases I have in formatting only remain consistent when using spaces, I switched.

load more comments (2 replies)
[-] 30p87@feddit.de 5 points 1 year ago

Ah yes I understand now!

[-] TheCee@programming.dev 4 points 1 year ago* (last edited 1 year ago)

Original poster is right by all accounts, of course. Now, let's come up with exotic significant indentations.

function xyz(a, b):
|   var x = 2

|   if true:
|   |   do_something()
|   else:
|   |   do_something_else()

|   anyway()

Pro: Your editor no longer needs to implement indentation hints.

Con: Looks obstructive if not highlighted like an indentation hint.

Your turn.

load more comments
view more: ‹ prev next ›
this post was submitted on 05 Sep 2023
217 points (100.0% liked)

Programming

17443 readers
132 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS