C# beginners, please stay away from the code generator! ! !

C# beginners, please stay away from the code generator! ! !

In the world of program development, in order to improve the so-called coding speed, the predecessors of all walks of life have come up with a variety of code generators to avoid the so-called repetitive manual pasting and copying of code to improve productivity.

A few years ago, I might think this approach was really useful, especially in terms of encoding speed. ​ Yes, sometimes the code generator can help our developers generate templated, standardized, large-scale machine code. But many people regard it as a powerful tool for program development. Without a code generator, it is impossible to write code and work.

I feel like I can use several code generators. I am proud to show off in front of the bosses or technical managers who do not know the technology: "XXX, you see how efficient my work is, your needs, and the functions you want. I only need simple code generation to quickly Get it done.". This approach is like someone putting a slaughtered and cut beef in front of you, and then asking you: "How many steps does it take to put these beef in the refrigerator?"

Maybe you know the answer? That's right, three steps. 1. Open the refrigerator door; 2. Put beef into the refrigerator; 3. Close the refrigerator door is easy, right? So, if someone gave you a whole cow instead of cut beef, and asked you to put the cow in the refrigerator, what would you do? The above case is actually the same as the use of code generators by developers (especially junior developers). When using a code generator, the generator is like cut beef. The developer does not care how the bottom layer of the code generator is encapsulated when using it, nor does it know how the internal logic is handled. It's like not knowing or caring about how the cow was slaughtered and how it was dissected. How did Pao Ding Jie Niu come from? It is a realm reached by the butchers after repeated practice and mastering the structure and meridian of the cow. The same is true in the world of development. I have seen many developers (most of them are .NET developers, because the author mainly focuses on .NET development) are used to and like to use code generators to generate projects, and even the entire solution can be generated for them. It's perfect. Some of them have 5, 6 or 7, 8 years of development experience, and are no longer beginners, but they are still using the traditional XX code generator to generate traditional three-tier solutions. , The front-end UI code is full of various DataTables and DataSets, various if...else...logical judgments, and various SQL statement splicing. . .

I don’t know if you are experiencing the same situation or the same scene when you see it here?

Maybe you said: "I'm not such a developer."

So I am very pleased that I am keen on development, but such friends should not be in the majority, otherwise the domestic .NET development environment will not be what it is today. Is my opinion accurate?

The reason is nothing more than this:

In the early years, many people who came into contact with program development (this article is mainly C#) joined the army of developers because of the high salary of the Internet. They were for money, not for future. They don't really like it, or they love programming.

In their bones, or at all, they just treat program development as a shortcut to make more money.

They were thinking: "I have been in the programming world for a few years. When I get old, have a few years of development experience or change jobs constantly, my salary will naturally continue to rise. When I am 30 years old, I will Qualified to be a senior engineer, a project manager, and a project supervisor. It doesn’t matter whether you have strong skills or not."

Therefore, as you, me, he has seen today's domestic development environment, there are very few people who really love programming and are willing to study technology in depth, because their purpose is not at all.

They just want to "make quick money" through a simple code generator. After they have been in the programming world for a few years, they still don't know the idea of ​​C# object-oriented programming, what generics are, and they have never heard of reflection. , Delegates, events, I don’t know there are design patterns, domain-driven design. . . Anyway, they knew there was something called a "code generator". I even asked in surprise: "So there are so many more in C#?"

Just imagine, if code generators can handle our programming work, why not just write a bunch of code generators for technology-driven technology companies like Microsoft, Google, Baidu, Ali, Tencent, etc.? Why raise thousands of developers every year?

To be more specific, for example, we use a certain code generator to generate a three-tier architecture (this is the most familiar routine for many C# beginners in the first few years of their entry or development career). This architecture contains three layers: entity layer , BLL, and DAL.

As the requirements of a project continue to change, will your data table structure change? So, is the problem here? Do you need to regenerate these three layers of code every time you change the table structure, and then replace the original code.

If you add your own code to any of the three layers, will you encounter problems when replacing it?

Have you ever wondered if there is a way to solve these problems instead of just holding on to the code generator. After the code is changed, everything will be fine after the logical judgment in the UI is modified accordingly.

The author has described so much, what I want to express is (especially for C# beginners): just getting started or in the initial stage, more hand-written code, more familiar with the class library in the .NET Framework, always thinking: " What the code generator can do for me is that I can’t learn real advanced programming knowledge and techniques.

If you stubbornly like to use traditional code generators to solve most of the work in your project, then congratulations, you have made a mistake, please leave as soon as possible to avoid getting deeper and deeper, because you do not love this business, you Sooner or later, I will leave, which will only waste your precious youth.

Concluding remarks

If you choose the .NET path, please use your heart and take it seriously, because this is your career and your efforts will be rewarded.

Reference: https://cloud.tencent.com/developer/article/1034512 C# beginners, please stay away from the code generator! ! ! -Cloud + Community-Tencent Cloud