How to take great programmers a step further

Overview: This article is excerpted from an article on blogoverflow.com, a well-known foreign programmer blog site. The article points out some qualities that a programmer should have to achieve better than "excellent".

As a programmer who has been working for many years, has your thinking been sublimated? The goal is no longer to stay at the "good" level, but to move towards a higher level of "greatness"? Now you want to make all the programs you write follow your own philosophy; now you want to be a programming guru - not a mediocre nerd who lives on the .Net interface; now you Think of programming as an art not a science, and you want to be the Picasso of programmers, respectable.

Programmer's Path to Success

Closer to home, the most important thing now is how to achieve this goal of becoming "great".

As a seasoned programmer, you should realize that the difference between "great" and "good" is not limited to technical aspects. One of the important distinctions is that "great" programmers can analyze requirements from the customer's point of view, making the design more human. And "good" programmers only do what they're supposed to do. Of course, not being able to provide helpful technical support can't be called "great" if you know what your customers want. So let's take a look at some of the attributes that one should have to be "great".

Regularly clean up duplicate code

Programmers who copy and paste are not real programmers. If you find yourself writing lines of code that have the same (or similar) situation more than once, it's time to consider cleaning up those snippets. This work of making code smaller, easier to maintain, and less prone to bugs is called code refactoring, and it is part of the daily work that must be done.

Keep your code short and practical

After you've mastered the art of cleaning and refactoring your code, the next step is to learn the style of keeping your code short and functional. Imagine how terrifying a long, outrageously long main program code would be for the person maintaining it. Then adding the header file before the main program and packaging the cumbersome main program in blocks will make the program maintenance simple and clear at a glance, and the compilation time is exactly the same, why not do it?

Learn about YAGNI principles and the art of programming

YAGNI全称为You Ain’t Gonna Need It,即为“你不会需要它”之意。作为程序员,我们常希望自己设计的东西能够涵盖所有基本需求。可事实往往是这样的,最开始客户希望应用程序完成其中的a功能,在你完成后,他们又认为应该加上b和c功能。然后,我们又花上几天时间去完成b和c 功能,毕竟这是客户的需求。这样的需求变更一次又一次,最后会得到一个比计划大很多的代码库和应用程序,而你曾经编写的一半代码都没用。为了减小更改需求带来的影响,让你的解决方案保持灵活性、可定制性和可预见性是工作中的一个非常重要的部分。在这里,编程真的就成为了一门艺术了——没有硬性规定,完全自由的裁量度,灵活性全部由程序员自己决定——这和绘画一样,多一笔少一笔,是轻还是重全由艺术家来权衡。

学会尊重他人

代码审查是将代码提交给有经验的程序员来帮助检查源代码与编码标准的符合性以及代码质量的活动,很多人会以为这就是给代码挑刺的活动,事实上代码审查最重要的并不是去关注技术细节,而是去留意设计理念,设计方法和实现过程,并提出参考性的建议。如果你觉得应该把别人的每个BUG的细节都一一罗列出来,展示别人的代码有多么的糟糕,那就错了。这在无意之间传递了一条错误讯息:我是来找碴的,是来让你难堪的。别人会因此刻意回避与你讨论,而你也将失去一个学习的机会。在这里,你应当学会尊重他人,就算他比你差很多,你也应该抱着这样的心态:“我们是来互相学习的。”

灵活运用设计模式

阅读设计模式的经典书籍常会为你带来灵光突现的时刻——“哈,这就是我解决这个混乱编码问题的方法。”设计模式可以在软件工程的开发中给人们带来便利,但是,往往其结果却是使程序变得更加混乱。这是因为人们在掌握了设计模式这个“锤子”后,往往会把所有的问题都想像成是“钉子”,而不根据实际情况进行具体分析,这样常使结果适得其反。灵活理性的使用设计模式很重要。

对最新的框架和库了然于心

对于最新的框架和库,你可能不会使用它们,但是你得清楚它们能够干什么。这里我举一个自己的例子——在SignalR出现以前,我一直坚信到目前为止还没有方法能够轻易实现网络应用实时通告的功能,我用了许多的代码来完成这项功能,费时又费力。但事实上,pubnub这样的库已经能够轻松实现这样的功能了,只是我不知道而已。因此,如果你无法对所有的框架和库都了然于心的话,在编写程序的时候,难免会干出许多低效率且无意义的事。滴水穿石,聚沙成塔,你要记住,伟大源自不断的积累和坚持。

不要忘记为代码添加注释

这无疑是一个利己利人的好习惯,不要因为它的麻烦而拒绝它忽略它。试想一下,你要对半年以前自己写的程序进行维护,如果没有注释的话,单凭半年以前的零星记忆,要在成千上万条代码行里去寻找你想找的东西无疑是大海捞针。 另外,使用注释也是对设计理念,算法流程的最好保存,当别人问及你算法中“X功能是如何实现的”,你难道 要跑去翻半年前的算法设计图纸或者挨着把程序从头到尾看一遍?添加注释虽然费时但却能为以后的工作省时省力,磨刀不误砍柴工,说的就是这个道理。

重视单元测试

编写测试用例能够确保你的代码能够持续正常工作。通过对用例的单元检测,你可以及时的搞清楚程序的哪一块运行正常,而哪一块与设计的预期不符,并及时更正,而不是等到几天后应用程序出来,只发现有数据异常,却无法及时找出这些异常的所在。另外,你还应当学习TDD(驱动开发测试)。

了解控制反转(IOC)与依赖注入(DI)

控制反转是目前备受争议的一种技术,它把传统上由程序代码直接操控的对象的调用权交给容器,通过容器来实现对象组件的装配和管理。而依赖注入是其中最流行的IOC类型,其中包含接口注入,设值注入和构造器注入三种方式。如果你仍不了解IOC是怎么一回事,你可以这么想像:把代码比做曾经的对象掌权者,它现在被剥夺了控制权,被排挤出了核心领导层。

学习多种编程语言的精髓

There are often programmers on forums arguing about which programming language is better or worse, which is actually meaningless. After you learn about multiple programming languages, you will be surprised to find that each language has its advantages and disadvantages. For example, the ease of use of python and the brilliance of ruby ​​on rails in web application development are one side of the coin. On the other side of the coin is neat, powerful javascript and C++. Likewise, c# developers and Java developers on either side of the coin will see each other differently. The blind man touches the elephant. Only by touching the programming language elephant as widely as possible will its image be more complete.

Know how to get along well with other programmers

Programmers are a strange species, and there are lunatics, madmen, idiots, and weirdos, and of course you may be one of them. How to get along with these people is a challenge. Here, I recommend Carnegie's "How to Win Friendship and Influence Others", this book is a classic.

This article is compiled from What programming concepts I should master to have a deep understanding of my craft?

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326504794&siteId=291194637