Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
atheist99053yWhy not? C is syntactically valid on a single line. A lot of languages are. Why bother with whitespace at all?
-
atheist99053yAlso, an argument brought to you by the people insisting on 80 character line lengths and those that think spaces are better than tabs ("tab" isn't a fixed width, you can configure your editor to display whatever indentation you want).
-
Root825573yI like both two and three. Four is just too wide, and eight is insane.
Also, tabs ruin console output, and ruin vertical alignment too unless they’re mixed. -
Configure your IDE to deal with that for you and don't care about personal stakes of what the code should look like in the repo.
If you are not agreeing with an already set coding standard, it is probably not a good idea to mess with something basic like leading spaces. If there isn't, make your case.. -
so I don't have to press space 4 times but only 2 times. Efficient development 😏
-
@iiii Three is not a number that any developer should ever use.
It’s not a power of two. Hell, it‘s not even even!
It’s just wrong 😬 -
Grumm18053y@Lensflare But at the second level, you have 6 spaces... And that is the first perfect number.
You wouldn't never get that when using only 2 spaces. -
mojo20128143yAny amount if spaces is wrong!
The only valid option is tab. Spaces are for people who don‘t know better …
Change my mind 😂 -
@mojo2012 all hope for you is lost my child. You won‘t see the light of spaces. Only the the darkness of tabs.
However, tabs are better than 3 spaces, that‘s where I agree. But only because tabs are technically 0 spaces and 0 is an even number and even a power of 2. -
The answer seems to be ease of reading:
"As to "practical" advantages, I guess it may be easier to view and edit files if you don't waste too much screen real-estate with deep indentation. From that perspective 2 character indentation is better than 4 or 8 character indentation."
from: https://stackoverflow.com/questions...
Also, this:
"Two spaces is popular in JS because "callback hell" makes the average program have many more indents than the average C or PHP program. Popular in HTML for the same reason. You can get away with 8 space indents if you're never going to be indented more than three indents.."
from: https://reddit.com/r/javascript/... -
Grumm18053y@CaptainRant I also see that Google applies a 2 space indents in their open-source code style guideline.
Yet Microsoft uses a 4 space indent in C#.
But again when using Visual Studio (maybe other IDE too) you can use smart indenting, four-character indents, tabs saved as spaces settings.
This will make the question pointless and just a preference of the coder and only uses tabs.
I have a project and I used a different IDE with lets say 1 tab = 3 spaces.
An other dev used 1 tab = 2 spaces and in git when he edits the file, it will change all the indents to 2 spaces. What a nightmare... -
@iiii how? I mean one of the things that async await solves is flattening the code by making it look like it is synchronous instead of having completion callbacks.
-
Tbh I don’t do a lot of manual formatting bc the ide does it automatically when I save lol
-
@Grumm I gathered all that information already but I didn't want to provide an opinionated answer, but rather a documented one. Though, neither the ECMAScript specification nor Google's guidelines seemed to provide a real reason why they made this choice.
-
@iiii you seem to be not familiar with that 😄
The code is waiting at each "await", yes. But it is still asynchronous in the same way as completion callbacks are. It is kind of syntactic sugar which hides the callbacks and makes it look synchronous.
How it works exactly depends on the language but the idea and the syntax is always very similar.
The purpose is to avoid nested callbacks, increase readability and prevent mistakes where you would forget to call the completion handler. -
@Lensflare yes but async js doesn't all of a sudden fix the humongous amounts of js that has been laying around for 30 years since Netscape invented it.
-
@DarkMukke yeah but if the question is how many spaces should one use when writing code, then async/await is kinda relevant here. Because the main argument for less amount of spaces seems to be callback hell.
-
@Lensflare yep, you don't start using semicolons because tcl/tk now supports it, the coding standard has been no semicolons for decades, same argument for js, async or not
A question to JS developers...
Why 2 spaces indentation?
random