I’ve seen arguments about using tabs instead of sp...
# intellij
s
I’ve seen arguments about using tabs instead of spaces in code editors in order for people to freely pick for themselves if a tab would take 2 spaces or 4 spaces. Basically so that each team member can pick the one of their liking of how the code shows on their IDE. I however can’t seem to find where such an option would be inside IntelliJ. Does it exist, and if yes how would I go about editing it, has anyone got any experience with such a thing?
k
It's easy: with Kotlin code in your editor window, click on the text showing "4 spaces" in the status bar at the bottom. You'll get a self-describing dialog box where you'll know what to do. I haven't tried it myself, because in Java and Kotlin there are widespread conventions where the use of spaces (instead of tabs) for indents is almost universal, so I keep to the convention. The use of tabs is more common in other languages, such as C and C++. In an old project I worked on a very long time ago, our code style was to use tabs for indents. Most people liked setting the tabs to be at every 3 columns. Not 2, not 4, but 3! And it worked quite well! I don't know what this obsession with powers of 2 is about.
s
Hmm right, I can see the icon on the bottom right as you said. Slight problem, that one is overriden as I understand it since we have defined a .editorconfig in the root of the project which we’re actually using for ktlint to pickup and know how to run ktlintCheck and ktlintFormat so that it’s consistent across all of us. If one would edit that for themselves they’d actually have to reformat the file to represent the tab as more spaces instead of just visually doing so. Does what I say make sense or am I possibly misunderstanding something? Also super interesting that there’s people who like 3 spaces 😂
s
According to the editorconfig docs:
when
indent_style
is set to tab, it may be desirable to leave
indent_size
unspecified so readers may view the file using their preferred indentation width.
That sounds like what you want. The question is whether it works or not in IntelliJ 😄
s
Hmm I see, but I’d still want the actual space taken to be worth 2 columns, as if it was different for different people it’d mean that we wouldn’t all get consistent errors when going over the 100/120 max width limit you know what I mean?
s
I do understand what you mean, but I don't know if it's possible to achieve
s
Yeah I am not sure either, thanks for helping out! If I do find out a solution I will post it here, but I think what we’ll eventually do is simply force 2 spaces for everyone 🤷‍♂️
👀 1
s
yeaah that's a hard problem. because you're talking about line wrapping. but then, how can something know to line wrap if you are saying that line length is ethereal in nature?
s
Yeah I hoped this would’ve been a solved problem 😅 In my head it makes total sense. Things will take 2 physical spaces, but depending on one’s configuration the tab might visually show 4 spaces instead. That does in fact mean that at the right side, if the limit is say 100 characters that would visually be different for those people who have this different setting, but still the IDE would be able to highlight the lines that go over than and the auto-formatter would still know how to fix it since in reality it’d be 2 spaces. But again, in my head, maybe practically it’s not that simple 😅
s
i guess if nobody did hard wraps and everyone used tabs and everyone used soft wraps, then it just might work
s
Not quite sure I understand the soft/hard wraps part? Why would it break if people purposefully wrapped code at specific places? Unless I don’t quite get what a hard wrap is. As far as using tabs that’s what we got our IDE/ktlint for, that one isn’t a problem since we’re all working on the same environment. As a side note, for now we just agreed to give 2 spaces a try and see how it feels since we can’t let this open to customize.
s
a hard wrap is \n or \r\n. These are actual character sequences. It's what most people use When you have it set to say, wrap at 140 characters, most editors will hard wrap to that. Meaning it inserts a wrap character. This is so that other editors and such can see it it means that your code reflects exactly what you told it. But that is also the straw that breaks the camel's back when it comes to editor independent formatting
because it means if i'm telling my editor to have 1 tab == 8 spaces, and you've got 1 tab == 2 spaces. My editor would have to re-wrap the lines of code accordingly, if you want indentation to really work right but maybe i'm thinking about this incorrectly, 🤷‍♂️
it's a stupid problem to be honest, tabs/spaces shouldn't be an issue at this point with all the AI and crap in the world. but here we are