Why is the code so poorly written there?

The more I look at the code for open source projects in languages ​​that are not Python, the more I understand that it seems that many programmers do not believe in the right indentation. (I will not mention any projects in order to avoid anyone asking this question too often.) Usually the code is indented, but in some ways is quite different from the standard style that drives me crazy, especially in the old / cruel code. I noticed that when I write in C-type languages, I tend to backtrack correctly as religiously as when I write in Python, with the exception of the debugging code, which I really want to stick with like a sore thumb. Given how easy it is to use a modern IDE to correct an indent, what are some considerations for keeping the indent in illogical synchronization with curly braces?

+4
source share
6 answers

Most of the cases of this problem that appear in the source database, on which I work most of the time, are associated with interleaved tabs and spaces. In one person’s editor, with tabs set every 4 characters, this looks great, but in another person’s system with 2 or 8 space tabs it looks awful. You can change these numbers as you wish; some files are mixed up independently. Changing the interval is a huge pain for merging with the road, so it is never fixed.

+10
source

It's easy to have “bad indentation” of html if you code in php, I would say that it is more important for php to be neatly indented than the html that it spits out ...

+1
source

Two points in addition to Karl's Observation :

  • “Correct” indentation is a matter of convention and language structure.
  • Checking for the initial control, which consists only in changing the indentation of several lines, is likely to be considered very poorly without prior consultation.
+1
source

Why don't people dress correctly? Why don't people use the right amount of garlic when cooking? Why is everyone listening to strange music? Your question involves authority, which determines the correctness, which I have not seen.

In addition, I like the code, which is sequentially formatted throughout the file. If you use 1 tab or 3 spaces, I don't care if you use it sequentially. The same thing with braces on the same line or a separate line, it does not matter, just be consistent.

I personally use VS, which initially automatically formats everything for me, and I am completely satisfied with the default set of rules.

+1
source

It is widely recognized that the coding style is a matter of “personal choice,” and one style is as good as another. I do not think this is necessarily true. An article recently written for accu (available only online for participants) suggests that various speed reading methods can be applied to the code layout to make it easier to read and understand. Sure, there is a ton of data on how people accept information, but this article was the first I saw applying it to a code layout.

There may well be significant information demonstrating that some code layouts are more suitable for people to read and understand, but none of the (many) arguments that I have seen refers to such information, and usually includes style protection that people have get used to.

+1
source

Maybe just the idea of ​​programmers about the "right indentation" is different from yours? Maybe your code looks like an ugly mess f *** ed up indentation for them? Seriously, every programmer has his own idea of ​​"right" indentation, and a curious tendency to bash indentation styles as "wrong". Indentation has been an important topic of fiery wars from the very beginning of the Internet (and earlier). No need to add more fuel to the flame.

With everything said, what style you use is relatively unimportant. It is much more important to consistently use the same indentation style throughout the project. The most common mess begins when every programmer on a team tries to use and force his style on the rest of the team. The result is an ugly mess of mixed and unsuitable indentation styles that infuriate people. This is why it is important to set coding standards for each project that has several programmers. I repeat - what coding standards are selected, it does not matter, the calculation of consistency.

0
source

Source: https://habr.com/ru/post/1304490/


All Articles