Beef Brisket News Announcement System--a summary of tips for learning web

Source: Internet
Author: User
Tags connectionstrings

November 10, 2014, it's a memorable day. This day. A small series of BS study began. The beginning of BS begins with the Beef brisket press release system. Before the content of the study is CS knowledge, after the soft test. Start to learn BS, contact BS have a few days, followed by the beef brisket teacher knocked the beef Brisket news release system, feel Bang Bang, looked at the front 20 episodes. found that the beef brisket teacher really is the party's ideological implementation of the incisively, with the beef Brisket teacher study together, found a lot of my little knowledge of the excitement, every time let my small universe broke out, and now put these small tips to share small small partners. This blog is a small part of the main explanation of three aspects of knowledge. First: How to make the code neat and Beautiful, the second: the gaze of the Code, the third: The small connection database tips.


First: How to make the code neat and beautiful

Why write beautiful code? This is very important, because the code is written out, except to run up. Another is to see, you want to see, others want to see, assuming that the writing is very messy, very unclear, and later look back. That feeling can be summed up with a sentence of the Spring Festival gala, disgusting her mother to disgust open the door. I'm sick of getting home. So what is the beautiful code? First of all. Good-looking, at least neat, not too long line, there will not be too long variable name, batch assignment statements, initialization statements are aligned, there is a correct obvious indentation. There will not be too short variable names.

Second, good understanding, this feature is very abstract, some code to understand at a glance, but there are code to make you very cost-minded, so, beautiful code, should read very fluent, clear what your intentions are. And there is nature, and every thing is logical. Finally, there is no resistance. This may be more abstract than the rules everywhere, and the restrictions are everywhere. It's all about restricting relationships, like the way the seesaw gives people.

How to write beautiful code. First name is very important, let the code tell you herself, so how important is the name. Important to this is almost a lot of software project success or failure of the culprit, the reason, the code not only supports 0 and 1 in the computer system to execute the business logic, the same time is also the developer of communication and research standard language, no meaning or ambiguous naming, like two people waiting to communicate, The face of a bunch of Martian text is impossible to swallow. Let communication turn into disaster. It can also cause a lot of problems. The same time a good name is self-explanatory, let the code tell the developer who I am, what I do and how I do it. Of course. Except for the static type of necessary gaze instructions. Dynamic code can also include the role of passing information, letting the code tell you about herself, because the code is "Live Code".

In the beef Brisket news release system, the beef Brisket teacher teaches small make up a skill is. Each time you finish writing, you can use Ctrl+k,d. We can get our code up and running very quickly, and it's not a cross-horizontal alignment. The whole module is neat all of a sudden.

Interested partners can give it a try oh, wonderful to say.

Second: The gaze of the Code

Staring is when you are typing code. A person who knocks on a code gives an explanation or hint of a statement, program segment, function, and so on. Can improve the readability of the program code, in order to facilitate future references, changes.

Staring is an explanatory text, when executing a program. Will be skipped by the program, do not do processing. In the understanding of small series. Staring is similar to the small series when learning classical Chinese, textbooks under the obscure language of ancient prose with modern words translated out of the process, then for a procedural ape, programming norms is the most important. Remember when the personal reconstruction of the computer room charge system, the gaze called a little ah. Small series is changed and changed, of course, do not narrow the programming norms only understood to be coding norms, the entire software development process is required to standardize, software project itself is a specification. Next, the small series will tell you about the gaze.
In the coding world, Gaze plays a starring role.

So how important is it to stare? First, consider it from the coder's own point of view. We are finished a project, generally not two days a day is over. It often takes weeks, months, even years. Imagine if we hadn't written the corresponding code gaze, now let's look at the code we wrote a few months ago, how much can we see? How long do we need to remember our own ideas? It's not a waste of time! And these can be made up by writing a gaze. Second, consider it from the perspective of others. We write code, not only for ourselves to see, more importantly, let others can understand.

In the process of software development, maintenance accounted for a large proportion. The maintenance worker may not be the person who originally wrote the Code.

You may be a master, the ability to write code is very high, it should have been a day of work, as a result, you did not write gaze. Half a day has ended. On the face of it, it seems that you are working very high.

But we should think for others, the latter may need two days, or even longer time to understand the code you write.

That's why so many people are reluctant to do maintenance work. We always say that as a qualified ape, we must be considerate to our customers. Do we not need to think about the people we fought with? At last. Consider it from the company's perspective. Suppose we do not write gaze, a day's work is finished, for the company to save half a day. However, it may take two days for maintenance personnel to understand your code when it comes to maintenance. It is conceivable that you have brought a lot of "benefits" to the company!

How can Suppose you are the boss of the company. Would you hire such a program ape? Definitely not! In short, staring is very important, it is the bridge of communication between the program apes.

There is a very good saying: "A person's life is not just for himself."

So our every line of code is not to achieve this function is enough, the key is to maintain, so we mentioned that the gaze is quite necessary. We just said that. When our program is handed over to others, then suppose our code does not stare. Then no one wants to follow your code and add unnecessary hassles to future maintenance.

Some people say. Use//Stare, turn green is good.

In fact this is better than not staring, but if you use///, I think you will find there is a world.

Let's take a look at this effect:

Take a look first. The code we wrote in SqlHelper:

<summary>       ///Run query SQL statements or stored procedures///</summary>//       <param name= "Cmdtext" > Querying SQL statements or stored procedures </param>//       <param name= "ct" > Command type </param>///       <returns></returns > Public        DataTable ExecuteQuery (String Cmdtext,commandtype ct)        {            DataTable dt = new DataTable ();            cmd = new SqlCommand (Cmdtext,getconn ());            Cmd.commandtype = ct;            using (SDR = cmd. ExecuteReader (commandbehavior.closeconnection))            {                  dt. Load (SDR);            return DT;        }
Then, when we call this method, there will be a pinch of what wonderful picture appears:

Third: How to securely connect to the database

from the VB Computer room charge system has come to today. See very many small partners connected to the database, if using SQL Server authentication, the username is Sa,password is: 123456. It feels good. Good to remember, but later found this very many people use. The average person to test all use this, so their own database other people can go in closed eyes, security is not guaranteed.

Some small partners may say that once a database is connected once, it is used continuously:

string [email protected] "server= (local);d atabase=newssystem;uid=sa;pwd=123456"

In fact, according to the principle of high cohesion and low coupling. This is not in line with the requirements. Then we need to constantly find this sentence, and then a place where a change, in case of a shiver, less change one, or more so a space, will not come out of the results.

We are connected to the database in Web. config, so that when our computer needs to change the connection database password, we are much more convenient.

<?

XML version= "1.0" encoding= "Utf-8"?><!-- for specific information on how to configure an ASP. NET application, please visit http://go.microsoft.com/fwlink /? linkid=169433 --><configuration> <system.web> <compilation debug= "true" targetframework= "4.5"/>

If we change the password. We just change the value of the pass and we're done. There is no need to make changes in the code, because this is in an external file, we just need to open the file with text: We have found the Web. config file in our program to save our website, and we can change it directly after we open it.

This is a technique introduced by the way.

We'll look at the key parts of our next:
In our Dal, inside, SqlHelper wrote:
Connection Database section:

Public SqlHelper ()       {           string connstr = configurationmanager.connectionstrings["ConnStr"]. ConnectionString;           conn = new SqlConnection (CONNSTR);       }
This advantage is self-evident. But don't forget to add a. NET reference "System.Configuration"

Otherwise your configurationmanager won't come out and the next step will be out of the way.


Small Editor's note: This blog post is the first time to write BS knowledge. Inner small excitement, the blog small part of the main three aspects of the small knowledge, first, how to make the code neat and beautiful. Second. The gaze of the Code; How to securely connect to the database, this little knowledge is like a BS on the road of a small spray, looking forward to these small waves to provoke a stormy sea, let us in the It road farther and farther ...




Beef Brisket News Announcement System--a summary of tips for learning web

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.