The foundation of programmers and the thinking of solving problems are very important.

Source: Internet
Author: User

The foundation of programmers and the thinking of solving problems are very important.

Why do I suddenly want to talk about this topic today? It's because I 've been pitted by my teammates at work. For the same function, different people may implement it in different ways. Similarly, different results may be obtained. Some people have good performance, simplified code, good readability, easy maintenance, etc. The code written by some people is not only messy and can crash the server. The Foundation and thinking of programmers are very important. To solve problems, you need to think more, instead of simply completing functions. Nothing else can be done. Seriously, is there a way to work? All of us are born with aunts!

1. First, let me list one of the simplest basic programming questions. I fully believe that someone in my current company (although I have been working for several years...) will give me a wrong answer.

int a = 5;int b = a++ + (++a) * 2 + ++a;Console.WriteLine(a);Console.WriteLine(b);
Solution: 5 + a = a + 1 a = a + 1 a = 7 a = a + 1 = 5 + 7*2 + 8;
Pay attention to the priority. From left to right, The unary operator is higher than the binary operator.
The answer is:
8
27
If you do not know, please review the basic knowledge of this section and make up for it.
The calculation operator ++ -- ++ is divided into the front ++ and the back ++. Whether it is the front ++ or the back ++, the final result is the value of this variable plus 1. difference: If the ++ operator is encountered in an expression, if it is the first ++, the value of the variable itself will first add one, and then take the value after this plus to participate in the operation. If it is the plus ++, the original value is used in the calculation first. After the calculation is complete, add one.
Here is just an example. In reality, I see similar code. I am so busy ........ is this a test of my understanding and basic skills, or is it really amazing? So I still need to cultivate myself so that I can cope with it no matter how difficult others are.
2. Let's take A look at A basic question. Enter A score on the console. If the score is greater than or equal to 90, output A. If the score is greater than or equal to 80, output B, if 80> score> = 70 Output C, if 70> score> = 60 Output D, if score <60 Output E
(Whether it is better to use if-else Or if else if. Why ?)
The Code is as follows:
Console. WriteLine ("Enter your exam score"); int score = Convert. ToInt32 (Console. ReadLine ());
If else practices
# Region if-else practices if (score> = 90) {Console. writeLine ("A");} else // <90 {if (score> = 80) {Console. writeLine ("B");} else // <80 {if (score> = 70) {Console. writeLine ("C");} else // <70 {if (score> = 60) {Console. writeLine ("D");} else {Console. writeLine ("E") ;}}}# endregion
If practices
# Region if practices if (score> = 90) {Console. writeLine ("A");} if (score> = 80) {Console. writeLine ("B");} if (score> = 70) {Console. writeLine ("C");} if (score> = 60) {Console. writeLine ("D");} if (score <60) {Console. writeLine ("E");} # endregion
If else if practices
# Region if else if practices if (score> = 90) {Console. writeLine ("A");} else if (score> = 80) {Console. writeLine ("B");} else if (score> = 70) {Console. writeLine ("C");} else if (score> = 60) {Console. writeLine ("D");} # endregion

What are the differences between the three implementation methods? Which one is better? Why? During my work, I often see some programmers using if else in disorder, which clearly provides better implementation methods.

Branch Structure: if structure: if-else Structure
Select structure: if else-if

3. Use a synchronization program or scheduled task to send the order message to the Ftp server and then obtain the receipt message from the Ftp server.

Company Programs are written as follows:

1. query the orders to be renewed from the database

2. generate an order message on the server and store it in a folder.

3. Use Ftp to upload the order message. If the order message has been uploaded successfully, modify the message name (followed by + _ 1)

4. After the packet is uploaded, download the receipt message from the Ftp server based on the packet name and store it in a folder.

5. Read the receipt file in this folder. If you have read the file, rename the receipt file.

.......

I really can't say it anymore. When I saw it for the first time, I felt that the person who wrote the code should catch it and close it in the cell. Don't put it out.

As a result, the program ran for a month, and the server crashed. I deleted the packet file on the server for two hours, dozens of GB, and read the program code, 10 million horses rushed over, and arranged for someone to rewrite the code...

I can't understand why the program should be written like this? Even if you want to generate an order message, you generate a report file by year, month, or day. After processing, move the message file to a specific directory, which is faster than renaming it, then, the transaction records of the previous month are regularly deleted (do not delete them directly) or compressed packages (compress the backups if necessary). Why don't you want to spend the next month, there are hundreds of thousands of files in this folder. This is a typical task of killing servers. As for downloading the receipt file on the Ftp according to the file name, you do not need to traverse all the _ 1 file names from this folder and then download it. How slow is this, why not record it in redis or the mysql DATA table of the memory storage type? There are also transaction messages generated, uploaded transaction messages, and transaction message receipt are all in the same thread. Why not use multiple scheduled task plans and multiple processes? I keep wondering .........

However, the Customs technical personnel are really amazing. The order message uses XML, and an XML file is recorded one by one, which does not allow compression, upload, and decompression, the receipt directory also stores the receipt packets of several enterprises ......... it can only be said that State-owned enterprises are really rich, and there is no need to worry about the network traffic and the performance of the single-listed companies on our side. These silly e-commerce enterprises are stuck to find a sense of presence.

4. N update, insert, or delete database operations in a foreach or for Loop

I'm curious, why do I need to perform a database connection in a loop, then perform database operations, and then close the connection? Why don't I save the content that requires database operations in a set, the last one-time SQL operation is executed so that only one open, execute, or close operation is performed in the loop? There are batch processing operations in the orm framework ....

I have seen many places in the project, such C # code is often seen during batch import and batch update of the receipt status, I want to drag the person who writes the code and hold it ...........

5. The system background is a complete interface. That is to say, whatever you click, the entire interface is refreshed, every time I refresh the page, I read html from the session and re-load the menu. The first time I saw the page, my eyes were blurred ....... then, in the left-side menu bar, in order to keep the record selected status, various js + cookies will come out, and hundreds of js pieces will be interspersed. I did not have the heart to refactor at the time, I want to rewrite it (but who gave me the time? A mess ...), in addition, the wonderful resource role permission management is semi-automated, and the market is already fully automated. What is semi-automated? It is the background interface configuration, and the code should be modified, it's hard-coded. I am really familiar with it. It's not like downloading a source code from the Internet! I don't want to talk about why I can make such a project. Finally, the customer could not stand it and asked for a change. I arranged for a colleague to change it. I made a frameset in the simplest way and deleted the hundreds of lines of js, finally, only the middle part is refreshed. Alas! I remember what the artist gave me (I was working as a financial system http://www.cnblogs.com/jiekzou/p/4508392.html) and the same interface for this project developer, It was a world of difference after I could do it ....

10 thousand words are the most basic things. Why do some programmers who have been working for a few years make such mistakes? It is estimated that programmers are too lazy to think about it, but be diligent in thinking .....

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.