打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
永远不要再犯的 5 个编程错误
返回原文英文原文:5 Programming Mistakes You Should Stop Making
参与翻译(6人):姜鹏飞w7219skyim媛媛小译其斤君羊315君
When you start out as a programmer, you can easily fall into the habit of following bad practices while programming.
As a programmer, you can't avoid mistakes and that's part oflearning your programming lessons. You'll make many mistakes in your career - some unique, some common ones - and that's how you'll learn to avoid them in future.
But if you are abeginner, you'll likely make some mistakes more often than others. How do you avoid these common mistakes that many programmers do everyday?
To avoid any mistake, you've to become aware of it. And that's why I would like to share with you some common mistakes that many of us still do that keeps us from growing as a programmer.
But before I share that with you, you may want to know how do I know that these are mistakes and not the right methods?
译者信息
当你开始成为一个程序员的时候,在编程的时候很容易陷入下面所述的一些坏习惯。
作为一名程序员,犯错误不可避免,这是你学习编程课程中的一部分。在你的职业生涯中你会犯很多错误 - 有的特别、有的普遍 - 通过这些错误你可以学习如何避免在将来再犯同样的错误。
但是如果你是一个初学者,你犯的错误可能会比其他人更频繁。那么如何才能避免大部分程序员每天都犯的这些普遍的错误呢?
想要避免错误,就要对它有所了解。这也是为什么我要和大家分享一些在我们的程序员生涯中阻碍我们成长的普遍错误。
在开始之前,你可能想知道为什么我知道这些是错误,不是最佳的方法?
There is a simple answer - I have done all of them at some point in my career. Some more often, while some only a few times. And I regretted doing them later.
But I didn't knew then that I was doing anything wrong by following such bad practices. Once I realized that I was doing the wrong thing I started avoiding them. And now my code is at least better than what I wrote before.
And you too can avoid doing such mistakes. Part of the solution is just to realize that what you're doing is wrong. I know that most programmers won't do anything wrong, if they knew right then that their actions can have a negative impact on their application and their professional growth.
Most of our wrong programming habits are due to our ignorance and nothing else.
译者信息
有一个简单的回答就是 - 在我的职业生涯中,所有这些情况我都遇到过。有些情况经常遇到,有些只遇到过几次。每次犯错之后,我都后悔莫及。
最坏的情况是我根本你不知道我在做错的东西。一旦我意识到我在做错事,我就开始避免这些失误。至少,我现在写的代码比以前写的要好多了。
现在你们也可以避免这些错误。首先要知道你现在在做的是错误的。我知道大部门程序员都不会做任何错事,因为他们认为那是正确的,所以他们的行为会对程序和程序员的职业成长产生不利影响。
绝大部分的不良编程习惯都源于无知,而没有任何其他原因。
To become a good programmer, we have to remove these ignorances one by one. And that's whatgood programming books try to show us.
Part of the reason that we do such mistakes is because they do get the work done. And isn't that what we are payed to do - make our programs run, and finish our day's work.
But to make something work is only part of your job. If your application is any good, you'll have to update it regularly, and fix any new bugs that may arise from time to time. And then the only thing that'll make your work easier is followinggood programming practices.
Also, while you can get away with such mistakes in small programs, you simply can't afford them when you make bigger applications.
If you still do them, your application may work and do the needful tasks. But it'll be buggy, full of unoptimized code, and hard to maintain. And even you'll find it difficult to understand the code, when you look at it after long time.
译者信息
要成为一个好的程序员,我们必须一个一个的去掉这些无知。这也是那些好的编程书籍所尽力展示给我们的。
我们犯这些错误的部分原因在于它们确实完成了工作。并不是我们要做的 - 让我们的程序运行起来,完成我们日常的工作。
但是让什么好用只是你工作的一部分。如果想要让你的应用程序好用,你将不得不定期更新,修复任何新的bug,这些将有可能变得很频繁。这样一来能让你的工作变得比较容易的方法就是遵循好的编程实践。
另外,即使你在小型程序中能够摆脱这些错误,在大型程序中你也可能碰到他们。
如果你仍然犯这些错误,可能你的程序依然正常运行,能够完成需要的任务,但是它会变得易出bug,充满低效率的代码,难于维护。并且,当你很长时间后再来看它的代码的时候,你会发现代码很难理解。
As programmers our job isn't just to make our applications work and let the users deal with the bugs. Our job is to make sure that there is no way users get undesired results even if they give it wrong input.
So to create high-quality applications, make sure you don't do these common mistakes while programming:
Copy-pasting code without understanding it
Often you'll find that the code you are looking for is already available in some other program. It's very tempting to copy the code entirely and use it as it is, without bothering to understand each and every line of it.
Sometimes, the code you are copying may be so large that you don't have time to understand it completely. If you copy any code this way, there is a risk of making your applications vulnerable and buggy.
While this may get the job done, but what if the code does some undesirable activities in the background. What if it slows down your application or does some malicious activity. For that you need to understand the code properly, or you need to be absolutely sure of the source from which you copied your code.
And if any bugs do arise later, you'll find it hard to understand the code as you didn't evenwrite it. And you'll find it hard to trace out a bug and fix it, especially if you copy lots of code at different places in your program.
So be careful when you copy even a little piece of code. Make sure you understand it completely. If you have already used a piece of code before and are 100% sure about the way it runs, then it's safe to copy it. But otherwise be cautious.
译者信息
作为程序员,我们的工作不仅仅是让我们的程序工作,而让用户来处理bug。我们的工作是确保用户即使输入错误也不会得到意外的结果。
所以要创建高品质的应用程序,请确保你不会在编程的时候犯下面的这些普遍的错误:
不加理解的拷贝代码
你经常会发现你需要的代码在一些别的程序里面有。整段的拷贝代码并且就这么使用它而不去烦恼于理解每一行代码是很诱人的。
有时候你拷贝的代码可能太大了以至于没有时间去完全理解它。如果你拷贝任何代码都像这样,就会有让你的程序变得脆弱易出bug等风险。
这样可能让工作完成,但是如果这段代码在某种情况下产生了一些意外的行为将会怎么样?如果使你的程序变慢或者有恶意行为将会怎么样?因此需要恰当的理解这些代码,或者需要绝对的确信你拷贝的代码的出处。
如果以后产生了bug,你会发现很难理解这些代码,因为你从来没有写过它。甚至于你会发现很难去找出bug并且修复它,特别是如果拷贝了很多代码在程序的不同地方。
所以当拷贝代码的时候要小心,即使很少的代码。确保你完全理解它了。如果你以前用过一段代码并且可以百分之百的保证它可以工作,那么它是安全可用的。但是如果不是的话,就要当心了。
Starting from scratch every time
This goes exactly opposite to what I said before but it's another mistake that many beginners do. You may think that it's best tostart from scratch every time you create a new application. But that's a huge waste of resources - your time, energy, and mind - that can be better used elsewhere.
If something you need to do is already out there, use it and make your job easier. There is no need to reinvent the same basic concepts again and again.
You can use the same time to make your application more better in other aspects.
If an API, framework, or game engine eases your task, there is no reason you shouldn't use it. Your goal shouldn't be to show offhow talented you are, and how you can do everything on your own without anyone's help. Your goal should be to make sure that your application works perfectly, and it takes as little resources as possible to create it.
This way you can do the same work in less time and save tens or even hundreds of hours. And as time is money, even if youwork for yourself, you earn more for the same amount of time.
译者信息
每次都从头开始
这和我之前说完全相反,但是这确实是初学者容易犯的另外一个错误。
也许你认为每次都从头开始会很好,但是实际上它浪费了太多资源--时间,精力和思维,你可以更好的在其他方面使用它们。
如果你需要的东西已经存在了,那么使用它们。不要反复重复最基础的东西。
你可以使用这些时间让你的应用在其他方面更加优秀。
如果一个API、框架或者游戏引擎让你的任务更加轻松,你没有理由不适用它们。你的目标不是展示你有多么的优秀,也不是证明你可以独立完成任何任务。你的目标是保证你的应用完美工作,并且尽可能少花费一些资源去创造它们。
如果你这样做,你可以用更少的时间去完成同样地工作。时间就是金钱,即使是你为你自己工作,你也应该试着在同样的时间赚更多的钱。
Searching google without trying yourself
Many times, by habit, as soon as you come across a new problem, you hit google and search for solutions. This isn't the way to become a good programmer. If you always search for solutions outside, without even trying once on your own, you'll never challenge your mind.
When you stop challenging your mind, you stop growing thoseprogramming skills inside you. To become good at any skill you have to solve new problems on your own. That applies to programming too.
Else you'll only create what's already there. You'll nevercreate any original work. Is that something you want to do?
While it's smart to look for existing solutions, but if you blindly do it, your laziness will stop you from becoming a better programmer. Even if you do want to look for solutions, it's alright, but first at least spend some time and think upon the problem.
Maybe you can solve it on your own without wasting much time. Maybe you can solve it in a better way than what others have done. Maybe your solution is more accurate than the other ones.
You'll never know these if you don't try.
译者信息
没自己尝试就开始Google
很多次,出于习惯,每次出现新的问题,你都会通过Google来找找解决方案。对于程序来说,这不是个好办法。如果你总是没有自己试一试就通过外部方法来搜索答案,那么你的思维永远都不会受到挑战。
当你的思维停止挑战,你自身的编程技能就会停止增长。把你自己的任何技能都练得很棒,你就可以自己解决问题,这也适用于程序开发。
你是创建一个已经存在的东西,你从来不进行原创。这真是你想要做的吗?
搜寻存在的解决方案看起来很聪明,但是这会蒙蔽你的双眼,你的懒惰会阻止你成为一个好的程序员。如果你真的你想要搜寻一个解决方案,至少,开始的时候你在这个问题上先花一点事件思考一下。
也许你自己不花多少事件就能解决掉它。也许你会有比其他人更好的解决它。也许你的解决方案比其他人的更加精确。
如果你不尝试,你永远都不知道。
Ignoring warnings
This is another mistake that I did earlier while developing applications. I can't tell you what a huge difference it makes when your application shows a hundred warnings and when it doesn't show even one - the most important being the ease with which you can recognize new problems.
Warnings are a sign that you are potentially trying to do something that may not work every time. Sometimes, these warnings aren't serious and it's safe to ignore them. But the real problem comes when you have a big application that shows hundreds of warnings, and something doesn't work right.
It becomes difficult to find the cause of that error. And you have to spend more time to analyze each warning and to find the root cause of the problem. Instead it's always better to resolve any warning issues at the start itself, as soon as they arise.
And usually you just need to use the right variables or functions to resolve most warnings. It doesn't take hours to do so; mostly a few minutes, if you remove them as soon as you come across them.
Try to remove any warnings as early as possible. A clean code not only looks good but works good too. Just remember the old saying - treat warnings as errors .
译者信息
忽略警告
这是一个早期我进行程序开发时犯的另一个错误。我不能告诉你当你的程序中出现几百个警号和一次都不出现有什么大的不同-最重要的是忽略掉它就出现新的问题。
警告通常是你做的东西可能不是每次都能正常工作的一个标志。有时,忽略这些警告会造成很大的安全问题。但是真正的问题通常是出现在程序出现几百个警告,或者程序不能正常工作时。
很难确定到底是什么原因造成了那个错误,你必须花更很多的时间来分析每一个警告来找出造成问题发生的根本原因。相反,你可以在警告发生的时候就处理掉它。
通常你仅仅需要使用正确的变量或者正确的函数来处理这些警告。不会花你几小时,只需要几分钟遇到它们就把它们处理掉。
要尽早的处理警告。干净的代码看起来舒服工作起来也会很高。记住- 对待警告和对待错误一样 .
Making Quick fixes instead of Permanent ones
Yes. I am guilty of doing this one too. And I am not proud of it. So often, we just come up with a quick fix that's barely enough to solve the problem at hand.
And it works and makes the problem go away. But if you aren't careful it ends up coming back again and again in different ways.
Whenever you fix a problem, make sure that it doesn't break the system in any way. A fix should improve the overall working of a system, not make it slower or more bulkier.
Also, make a fix that'll solve the problem permanently. Think of long-term, not just short-term. Sometimes, due to our laziness or ignorance, we just want to do our work quickly, instead of spending more time on it. And that's why we write code that does the intended work, but might not work in all possible scenarios.
If you skip on doing your work now, you'll only have to work even more on that problem later.
译者信息
快速修复而不是永久性解决
是的,我对这样做感到愧疚。我不为此而自豪。但通常,我们仅仅是草草的修复一下,很少会去从根本上解决这个问题。
它能正常工作了,问题也处理掉了。但是如果你一不小心,问题又会以不同的方式重新出现。
无论你怎么修复一个问题,都应确保你不会把整个系统破坏掉。修复应该提升整个系统的运行状况,而不是让它更慢或更笨重。
同时,进行一个修复要能永久性的解决这个问题。要长期,不要短期。有时,由于懒惰和无知,我们通常喜欢快速的把问题解决掉,而不想在上面花太多时间。这就是为什么我们的写的代码能正常的工作,但是却不是在所有情况下都能工作。
如果你在工作的时候把它忽略掉,你会在后面花更多的时间。
Just knowing these above mistakes can help you in avoiding them. If you know what you're doing is wrong, most times you won't do it.
And to do a good job you shouldlove what you do. If you don't like programming for some reason then you'll rarely take the extra steps that are needed to write good, maintainable programs.
And if you do intend to write such good programs then you need to change the way you look at programming.
Think ofprogramming as an art and yourself as an artist. Then you'll never make this mistake of being lazy or careless.
Would a writer write incomplete article and publish it? Would a painter leave his painting incomplete and sell it? Would a singer just sing any useless words between his songs?
Definitely not.
The same applies to programming. Don't write incomplete code that doesn't test all scenarios. Don't leave your application unfinished and ship it. Don't write useless code if you can do without it.
译者信息
了解上面这些错误能有助于你避免它们。如果你知道你所做的是错误的,一般来说你就不会去做。
为了把工作干好你应该热爱你所做的。如果因为某些原因你不喜欢编程了那么你几乎不会花额外的功夫来编写好的可维护的程序。
如果你打算写一手好程序那么你就应该 改变你对编程的看法。
你要把编程看成一门艺术而你自己则是一个艺术家。那么你就不会因为懒惰和不小心而犯错。
作家会把一篇未完成的文章发表么?画家会把未完成的画作拿来出售么?歌手会在他的歌中唱没有用的歌词么?
绝不会。
对编程来说也一样。任何情况下,都别编写未经测试的半吊子代码。在你的程序未写完前,不要发布它。别编写不会使用的无用代码。
These are just some basic mistakes that we do, because we are tempted to do less work and do something else. But we can't go far with this approach. Sooner or later, you have to become responsible for your work and make sure that there is no flaw in your code.
The sooner you start practicing the right programming methods, the better it'll be for you and your users. Sometimesbeing a good programmer means just to make sure that you don't do the same mistakes that bad programmers do.
Thanks for reading this post. If you know anyone who unknowingly follows such programming practices please share this post with them and help them become a better programmer.
译者信息
这都是一些我们犯的一般性错误,因为我们喜欢在工作花更少的时间而去干其他事情。但这是不行的,迟早你都会为确保你的代码不出问题而负责。
越早的练习正确的编程方法,就对你的用户和自己越好。有时成为一个好的程序员意味着你不会犯糟糕程序员同样的错误。
谢谢大家的阅读。如果你知道谁不知道这些编程技巧的,请你把这篇文章发给他们,以便让他们成为好的程序员。
本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
计算机英语高级词汇·Programming
Fatherly Advice To New Programmers
回调函数(callback)是什么?
无我编程的10条诫律
对比编程语言的四种错误处理方法,哪种才是最优方案?
从及时的同步修正改错着手
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服