B
B
Boris the Animal2015-10-10 15:07:00
.NET
Boris the Animal, 2015-10-10 15:07:00

Code style in .NET applications. Have you seen hell in code?

I worked in one organization for a year and a half, I wrote several projects myself. the code in terms of design is just almost perfect. Without any nonsense like Hungarian notation, etc.
I explain. If there is a normal IDE, then the Hungarian notation is not needed, the code turns into ripples from a mixture of abbreviations that only annoy. Hovered the mouse, saw the data type, and in fact everything is clear when you look at the code. I clicked on the variable, it was highlighted everywhere in the code. Everything is simple and clear.
I have seen code where variables looks like this:

public void Method(string[] arlines)
{
    int nIndex = 0; //далее эта переменная используется на 3 строках ниже
    //и всё! Нафига писать, что она типа int в названии? 
    //Ну видно же, что это за переменная парой строк выше.
}

Uh-huh, is he serious? What for to write that it is Array (ar)? Why is the next word after ar lowercase? For whom is the code written for people or just to be as less readable as possible?
public static bool Serialize(CEventContainer ob, byte[] arDest, int nIndex) { }

Why write C at the beginning of the class name, if the whole dotnet is written in a normal, human style? Well, that's okay, it's all right, although it's hard to read this.
The name of the variable ob is generally what kind of tin? Why not container? The fool understands that this object will be there at the time of execution.
In general, when I read a similar code at a new job, I thought about sending everything and quitting there, because there are tons of such feces. And it is not known whether I will be allowed to refactor all this and bring it back to normal.
Actually, you understand that I got a new job. The salary is 2 times more than at the previous job, only it keeps. Well, I'm not omnipotent, I also have something to learn, for example, T-SQL needs to be taught, working with a database, and much more. That is, I'm not a genius, but such little things really strain.
By the way, this is not the worst. The worst thing is the creepy PPC in the form of terrible class design in different styles. Everything is mixed up, somewhere the methods are on top, the constructor is in the middle, the fields are generally scattered everywhere. Somewhere, every field of the property is right next to the property, this hell is generally hard to read. What for to store the field nearby? Well, write in the comments in which folder this class is then to the heap. There are simple comments above the methods, not XML or they don’t exist at all, but everything is described in the documentation with terrible document names, it’s very difficult to navigate in them, but you can. Different classes have different indents. Almost all classes in the main project lie, no folders and namespaces corresponding to them (with rare exceptions). The names of the files in the project do not match the classes inside them. This is real hell! I have no words...
Did you have something similar? Did you somehow solve this problem?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
O
OnYourLips, 2015-10-10
@OnYourLips

Why write C at the beginning of the class name, if the whole dotnet is written in a normal, human style?
Because those who wrote this have no experience and are new to C# development.
Here are the conventions that are common in good quality code:
C# Coding Conventions
Naming Guidelines

T
Tsiren Naimanov, 2015-10-10
@ImmortalCAT

hmm
unit what i heard
I don't know how correct this is, but that's how I use it

S
Stanislav Makarov, 2015-10-10
@Nipheris

It's obvious to me that this was written by former C/C++ developers. This is an ancient notation, many call it Hungarian, only here it is some kind of perverted version (I must say that the Hungarian notation itself was correctly used by units at one time, most did not fully understand its meaning). Now they don’t write like that on the pluses themselves, but for Sharp it’s bad manners. Gives the notation n in front of the index name (it means exactly "index", not int, although they usually write nUnit or nEmployee, not nIndex) and C in front of class names.
Completely agree with you.
Not so experienced guys wrote this code, and they are definitely not in trouble with code formatting in C#. They probably wrote a long time ago, when C# still appeared, and all C++ programmers started writing in it, retaining all their habits, many of which are unnecessary or even harmful.
The fact that different classes are decorated differently is not a big problem, not all projects manage to maintain the same style (although it's worth it of course).
This is also a plus - normal people, of course, use namespaces, but there they are not as ubiquitous as in C #, because assembly technology is fundamentally different.
And this, apart from your team led by a team leader, and even with the involvement of managers, no one can solve it. If you are ready to refactor half of the product, go ahead. Not ready - better not touch. Write new code in an appropriate style. If it were C++, I would even advise you to format the new code according to the rules of the project, but THESE rules within C# are completely inadequate.
I summarize: if there are no resources for code processing, be patient. Patience and the ability to work with legacy code that is not of the highest quality is probably the most important trait of a "team programmer". Old and not the prettiest code is a reality, it is just as real as dilapidated buildings that you just can’t rebuild without serious investments.
You were lucky in terms of code quality. Now not so lucky. As AtomKrieg said , it's good that it's not Cobol (at least then you would be paid even more).
Normal XML comments in C# code are generally a luxury. I see them only in serious libraries, and in any corporate trash only the most important classes in the program (10-15 pieces) are commented like that. Be glad there is documentation at all. If you have the desire and time - transfer it to the code, it will certainly be useful.

N
nico, 2015-10-18
@nico

on my project, the team lead puts commas at the beginning of the line, like

Method(int a
, int b
, int c)

want to shoot. I understand that in SQL they do this in order to quickly look at the data there, but in C # why look?).
And yet no one takes a steam bath and write lines of as many characters as long as they want. I found and 400-500.
In general, I edit all this when I work in methods with someone else's code, but damn it they write again). I ask you guys, do you have 50 inch monitors? You, bla, how do you look through the code, butter the mouse back and forth? They look at me with their Filipino eyes with glasses and smile...

T
Taxist410, 2015-10-10
@Taksist410

The main thing is that the code works and the architecture is reasonable. And how it is designed is the second question. There is also a point to hard-to-read code: it's harder to steal. I write this myself when I return from a shift and am tired. After all, Visual Studio has a lot of good code analysis tools.

M
MrDywar Pichugin, 2015-10-11
@Dywar

Codestyle
Visual Studio Code analysis rule set reference
The rules must be agreed upon by the company and specific groups of developers in advance so that everyone follows them at once. You already know all this, but not everyone uses it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question