What programmers should do ~~

Source: Internet
Author: User

To become a successful programmer, a netizen wrote an article and I posted it here, hoping to share it with you.

Tip 1 requires methods instead of memory

One of my programmers often tells me how helpful it is to remember over 200 C ++ functions. "I never have to look up the definition of a function, so I can be 50% faster than other programmers programming ." He proudly said. What is the result? Doesn't he know that the automatic completion function of the compiler code can save a lot of time for searching and inputting functions? In addition, when C # is released, his efforts on memory functions were in vain. Of course, memorizing functions in programming is essential, but you should spend more time learning how to do things, such as creating a database connection, how to generate RSS sources, and then focus on how code is implemented. The correct way to learn and do things is far more important than memorizing things.

Tip 2 create your own resource library

We all have code sets that have to be created for one reason or another. I never remember the correct code statement for connecting to the database, so I had to spend 10 minutes in the Code set every time to query it. To solve this problem, I created a Word document for recording code snippets to help me remember and search. One of my colleagues created a record link bookmarks, and another saved the content in his email. Whatever your method is, it is a good habit for you to conveniently find files or content. After you build your knowledge base, you will find that it will greatly help you write your code better and faster.

Tip 3 Know what to do instead of how to do it

Many junior programmers asked me "how do I do this, or how do I do it ?" I always say, "What do you want to do ?" After hearing this, they will stare at me as if I have been dating their mother. This is my next point of view. never learn how to do it before you know what you want to do. For example, a programmer wants to search for a specific word in a text file. The following uses C # to achieve this goal:

View plaincopy to clipboardprint?
  1. StringFilecontent;
  2. System. Io. filestream mystream =NewFilestream ("C: // aa.txt", filemode. Open );
  3. System. Io. streamreader mystreamreader =NewStreamreader (mystream );
  4. Filecontent = mystreamreader. readtoend ();
  5. Mystreamreader. Close ();
  6. IntIdx = filecontent.
  7. Indexof ("string ");
  8. If(Idx)
  9. {
  10. Return True
  11. }
string fileContent;System.IO.FileStream myStream = new FileStream("c://aa.txt", FileMode.Open);System.IO.StreamReader myStreamReader = new StreamReader(myStream); fileContent = myStreamReader.ReadToEnd();myStreamReader.Close();int idx = fileContent.IndexOf("string"); if (idx){return true}

Now I give him the code to do this, but more importantly, I understand what I am trying to do. What we want to do in this example is: 1. open a file 2. read the content 3. close file 4. search for strings 5. if the result is found, this method is used to solve the problem. The following results are generated: 1. it makes language irrelevant 2. so that you focus on what needs to be done 3. make your code easier to read and effectively Know what to do will make your code more purposeful. Now it is easy to write the above Code in C ++, PHP, VB. NET, Ruby on Rails, because you understand what to do rather than how to do it.

Tip 4 Create a comment style suitable for you

Every programmer hates comments, but in order to write more quality and easy-to-read code, we need comments. The problem is that most programmers are often told how to make comments. Some companies want every line of code to have comments, while others want to have comments before each function, other provisions should be noted before different code blocks. I do not agree with this mandatory provision. As long as the code is available, readable, and valid, programmers should be able to comment in their preferred formats. For me, comments on each line will disrupt the code pace. I prefer to comment on the function to list what I will do next step, then, you can program the function by referring to the steps written in the annotation. This is suitable for me, so that we can help me organize the design before programming, and maintain my pace, so that I will not interrupt programming because of the need to note, it also helps others read my code. The following is an example of how I comment:

View plaincopy to clipboardprint?
  1. /* 1. Open File *
  2. 2. Read File into string *
  3. 3. Close file *
  4. 4. Search for key word *
  5. 5. If fond return true;
  6. */
  7. StringFilecontent;
  8. // 1.
  9. System. Io. filestream mystream =NewFilestream ("C: // aa.txt", filemode. Open );
  10. System. Io. streamreader mystreamreader =NewStreamreader (mystream );
  11. // 2.
  12. Filecontent = mystreamreader. readtoend ();
  13. // 3.
  14. Mystreamreader. Close ();
  15. // 4.
  16. IntIdx = filecontent. indexof ("string ");
  17. If(Idx)
  18. {
  19. // 5.
  20. Return True;
  21. }
/* 1. Open File* 2. Read file into string* 3. Close file* 4. Search for key word* 5. If fond return true;*/string fileContent;//1.System.IO.FileStream myStream = new FileStream("c://aa.txt", FileMode.Open);System.IO.StreamReader myStreamReader = new StreamReader(myStream);//2.fileContent = myStreamReader.ReadToEnd();//3.myStreamReader.Close(); //4.int idx = fileContent.IndexOf("string");if (idx){//5.return true;}

This annotation style makes it easy for me and most programmers to read it. Find a comment style that suits you.

Tip 5 proficient in one, learn another, follow next

Sometimes a programmer sends an email asking me what language he should learn and what is the best programming language. You should be proficient in at least one programming language, be able to write code well, and then learn to master another one, and gradually grow. Taking myself as an example, I have been proficient in C # And I am good at PhP. I have been using Ruby on Rails for about two months. Why? Proficient in a language can make you progress, write better code in progress, and find a better way to complete the task. Progress is also why I have been working as a programmer year after year, but I still don't feel bored.

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.