BS领军人物--牛腩新闻发布系统
2014年11月10日,是个难忘的日子,这一天,小编的BS学习开始了,BS的开头,从牛腩新闻发布系统开始,之前学习的内容都是CS方面的知识,软考过后,开始学习BS,接触BS有几天的时间了,跟着牛腩老师敲着牛腩新闻发布系统,感觉棒棒哒,看了前面二十集,发现牛腩
2014年11月10日,是个难忘的日子,这一天,小编的BS学习开始了,BS的开头,从牛腩新闻发布系统开始,之前学习的内容都是CS方面的知识,软考过后,开始学习BS,接触BS有几天的时间了,跟着牛腩老师敲着牛腩新闻发布系统,感觉棒棒哒,看了前面二十集,发现牛腩老师真的是把党的思想贯彻的淋漓尽致,跟着牛腩老师一起学习,发现了很多让我怦然心动的小知识,每次都让我的小宇宙爆发,现在就把这些小技巧分享给小编的小伙伴。该博文小编主要讲解三个方面的知识。第一:如何让代码整齐美观,第二:代码的注释,第三:连接数据库的小技巧。第一:如何让代码整齐美观
为什么要写漂亮的代码?这点很重要,因为代码写出来,除了要跑起来之外,还有一个就是要看,你自己要看,别人也要看,如果写的很乱,很不清楚,日后自己回过头来看,那种感觉可以用春晚的一句话来概括了,恶心她妈妈给恶心开门,恶心到家了。那么什么才是漂亮的代码?首先,好看,至少整齐,不会有太长的行,不会有太长的变量名,批量赋值语句,初始化语句都对齐,有正确明显的缩进,也不会有太短的变量名。其次,好理解,这个特点很抽象,有些代码一看就懂,但是有写代码让你很费脑筋,所以,漂亮的代码,应该读起来很通顺,明白你的意图是什么,还有就是自然,每一个东西都顺理成章。最后,没阻力,这个可能更抽象了,而不是到处是规则,到处是限制,到处是制约关系,犹如跷跷板给人的那种感觉。
怎样写漂亮的代码,首先命名很重要,让代码告诉你她自己,那么命名到底有多重要呢,重要到这几乎是很多软件项目成功或者失败的罪魁祸首,究其原因,代码不光支撑了0和1在计算机系统中运行的业务逻辑,同时也是开发者进行交流与研究的标准语言,没有意义或者有歧义的命名,就像两个等待交流的人,面对了一堆火星文无从下口,让交流变成灾难,也就会导致很多问题,同时好的命名是自说明的,让代码告诉开发者我是谁,我做什么,我怎么做,当然,除了静态式的必要的注释说明之外,动态式的代码也可以包含传递信息的作用,让代码告诉你她自己,因为代码是“活代码”。在牛腩新闻发布系统中,牛腩老师教小编一个技巧就是,每次写完之后,都可以用ctrl+k,d。能很快的让我们的代码整齐起来,而且不是一横一横的对齐,是整个模块一下子就整齐了。有兴趣的小伙伴可以试一试哦,好神奇的说。
第二:代码的注释
注释是编写程序时,写程序的人给一个语句、程序段、函数等的解释或提示,能提高程序代码的可读性,以便于以后的参考、修改。注释是解释性文本,在运行程序时,会被程序跳过,不做处理,在小编的理解中,注释就类似于小编小时候学习文言文的时候,课本下方对古文中晦涩难懂的文字用现代话语翻译出来的过程,那么对于一个程序员来说,编程规范可谓是重中之重。还记得个人重构机房收费系统的时候,那个注释叫一个少啊,小编是改了又改,当然,不要狭义的把编程规范仅仅理解成是编码规范,整个软件开发过程都是需要规范的,软件工程本身就是一种规范。接下来,小编就给大家讲讲注释。
在编码规范的世界里,注释扮演着一个领衔主演的角色。那么,注释到底怎么重要了呢?首先,从编码者自身的角度考虑。我们完成一个项目,一般来说不是一天两天就完成了,经常是需要几周,几个月,甚至是几年。想象一下,如果我们之前没有写上相应的代码注释,现在让我们看自己几个月之前写的代码,我们能看懂多少?我们需要多长时间去回想我们自己当时的思路?这不是浪费时间嘛!而这些都是可以通过写注释来弥补的。其次,从别人的角度考虑。我们写代码,不仅仅是给自己看的,更重要的是让别人也能看懂。在软件开发的过程中,维护占大部分比例。而维护工作者可能不是当初编写代码的人。你可能是高手,编写代码的能力很高,本来应该是一天的工作,结果,你没有写注释,半天完成了。表面上看,似乎你的工作效率挺高的。但是我们应该为别人着想一下,后期维护的人可能需要用两天,甚至更长的时间去理解你写的代码。这就是好多人不愿意做维护工作的原因。我们总说,作为一个合格的程序员,要时时刻刻为客户着想,难道我们就不需要为和我们一起奋战的同胞们想一想吗?最后,从公司的角度考虑。如果我们不写注释,一天的工作半天完成了,为公司节省了半天时间。可是,到维护的时候,维护人员可能花了两天的时间才看懂你的代码。可想而知,你为公司带来了多大的“利益”!试问,如果你是公司老板,你会雇佣这样的程序员吗?肯定不会!总之,注释很重要,它是程序员之间沟通的鹊桥。
有句话说的很好:“一个人的活着不仅仅为了自己”。所以我们的每一行代码都不是为了实现这个功能就够了,关键的地方在于维护,所以我们提到这个注释就相当的有必要了。刚刚我们说过,当我们的程序转交别人的时候,那么如果我们的代码没有注释,那么没有人愿意接着你的代码写,也会对未来的维护增加了不必要的麻烦。有些人说,用//注释,变绿色就好了。其实这样比不注释的要好多了,但是若是你用///,我想你会发现另一个世界。我们来看看这个效果:
先来看看,我们在SQLHelper中写的代码:
/// <summary> /// 执行查询SQL语句或存储过程 /// </summary> /// <param name="cmdText">查询SQL语句或存储过程</param> /// <param name="ct">命令类型</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; }
第三:如何安全连接数据库
从VB机房收费系统一直走到现在,看到很多小伙伴连接数据库,若是用SQL Server 身份验证,用户名是sa,密码是:123456,感觉挺好,好记,但是之后发现这个很太多人用了,一般人多测试都用这个,所以自己的数据库别人闭着眼睛都能进去,安全性没有保障。有的小伙伴可能会说,数据库进行一次操作就连接一次,那么就不停的用:
string connStr=@"server=(local);database=newssystem;uid=sa;pwd=123456"
其实按照高内聚和低耦合的原则来讲,这是不符合要求的。然后我们就需要不断的找这句话,然后一处地方一处地方的更改,万一手一哆嗦,少改了一个,或者多了那么一个空格,就出不来结果了。是我们在web.config里边连接数据库,这样当我们的电脑需要更改连接数据库密码的时候,我们就方便多了。
<?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> <appSettings/> <connectionStrings> <add name ="connStr" connectionString=" server=(local);database=newssystem;uid=sa;pwd=123456"/> </connectionStrings> </configuration>
我们的DAL里边,SQLHelper里边这样写:
连接数据库部分:
public sqlHelper() { string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; conn = new SqlConnection(connStr); }
否则你的ConfigurationManager出不来,下一步就无法进行了。
小编寄语:该博文是小编第一次写BS方面的知识,内心小小的激动,该博文小编主要了三个方面的小知识,第一,如何让代码整齐美观,第二,代码的注释;第三,如何安全连接数据库,这小小的知识就像是BS路上的一朵朵小小的浪花,期待着这些小小的浪花激起惊涛骇浪,让我们在IT之路上越走越远......

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



You can view various contents on Xiaohongshu, which can provide you with various help and help you discover a better life. If you have anything you want to share, you can post it here so that everyone can take a look. , and at the same time, it can bring you profits. It is very cost-effective. If you don’t know how to publish your works here, you can check out the tutorial. You can use this software every day and publish various contents to help everyone use it better. Don’t miss it if you need it! 1. Open Xiaohongshu and click the plus icon below. 2. There are [Video] [Picture] [Live Picture] options here; select the content you want to publish and click to check. 3. Select [Next] on the content editing page. 4. Enter the text content you want to publish and click [Publish Pen]

With the rapid development of social media, short video platforms have become the main channel for many users to express themselves and share their lives. Many users may encounter various problems when publishing videos of their works on Xiaohongshu. This article will discuss the reasons that may cause the video publishing of Xiaohongshu works to fail and provide the correct publishing method. 1. Why can’t Xiaohongshu publish videos of works? The Xiaohongshu platform may occasionally experience system failures, which may be caused by system maintenance or upgrades. In this case, users may encounter the problem of being unable to publish videos of their works. Users need to wait patiently for the platform to return to normal before trying to publish. An unstable or slow network connection may prevent users from posting videos of their work on Xiaohongshu. Users should confirm their network environment to ensure that the connection is stable and

General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

As a lifestyle sharing platform, Xiaohongshu has attracted a large number of users to share their daily life and grow products. Many users have reported that their published content cannot be displayed. What is going on? This article will analyze the possible reasons why Xiaohongshu cannot be released and provide solutions. 1. Why can’t Xiaohongshu be released? Xiaohongshu implements strict community guidelines and has zero tolerance for publishing advertisements, spam, vulgar content, etc. If the user's content violates the regulations, the system will block it and the content will not be displayed. Xiaohongshu requires users to publish high-quality and valuable content, and the content needs to be unique and innovative. If the content is too generic and lacks innovation, it may not pass review and therefore not be displayed on the platform. 3. Account abnormality

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

In today's social network era, Xiaohongshu has become an important platform for young people to share their lives and obtain information. Many users hope to attract more attention and traffic by publishing content on Xiaohongshu. So, when is the best time to post content? This article will explore in detail the selection of Xiaohongshu’s publishing time and the publishing location with the most traffic recommendations. 1. When is the best time to publish Xiaohongshu? The best time to publish content on Xiaohongshu is usually during periods of high user activity. According to the characteristics and behavioral habits of Xiaohongshu users, there are several time periods that are more appropriate. During the time period from 7 pm to 9 pm, most users have returned home from get off work and started browsing content on their mobile phones in search of relaxation and entertainment. Therefore, content posted during this period is more likely to attract users

As a popular social e-commerce platform, Xiaohongshu has attracted a large number of users to share their daily life and shopping experiences. Sometimes we may inadvertently publish some inappropriate content, which needs to be deleted in time to better maintain our personal image or comply with platform regulations. 1. How to delete Xiaohongshu releases? 1. Log in to your Xiaohongshu account and enter your personal homepage. 2. At the bottom of the personal homepage, find the "My Creations" option and click to enter. 3. On the "My Creations" page, you can see all published content, including notes, videos, etc. 4. Find the content that needs to be deleted and click the "..." button on the right. 5. In the pop-up menu, select the "Delete" option. 6. After confirming the deletion, the content will disappear from your personal homepage and public page.

How does the Xiaohongshu app publish works? Many friends know that there are a large number of creative works and a strong dating circle in this software. For users who are new to this software, they probably don’t know how to publish their works, so that more people can watch the other side of you. If you still don’t know how to publish the works in it, then quickly refer to the five-minute tutorial on publishing works on the Xiaohongshu app recommended by the editor of this site. Tutorial on publishing works in Xiaohongshu app in five minutes 1. Click [Three] As shown in the picture, click [Three] pointed by the red arrow in the upper left corner. 2. Click [Creation Center] As shown in the picture, click [Creation Center] pointed by the red arrow. 3. Click [Go to Publish] as shown in the picture,
