良好的预防措施(实践)来启动 C++编程
我的第一份工作就是开始 C++ 编程。我是一名 CS 学生,我学习了 Java 编程。您有什么建议让我注意,以免在新工作中造成麻烦?
如果您有任何建议或参考,我们将不胜感激。
(例如:我知道C++比Java更容易出现内存问题)
非常感谢!
I'm starting C++ programming in my first job. I'm a CS student and I have learn programming in Java. What advice would you tell me to watch out so I don't cause trouble in my new job?
Would you have any advice or references would be appreciated.
(example: I know C++ is more likely to have memory problem than Java)
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
也许您已经知道这一点,但对于习惯 Java 和学习 C++ 的人来说,一个常见的错误是:
除非必要,否则不要使用
new
(而且您可能真的必须)。在大多数情况下,如果您想要创建一个对象,您应该只在“堆栈上”创建它,例如ClassType obj;
。Maybe you already know this, but one common mistake for folks used to Java and learning C++:
Don't use
new
unless you have to (and you probably don't really have to). In most cases where you want to create an object, you should just create it "on the stack", likeClassType obj;
.有两件事:
Two things:
对我来说,Java 和 C++ 之间最大的区别是指针,所以我会尝试把指针弄下来。只是我的意见。
For me, the biggest difference between Java and C++ is pointers, so I would try to get pointers down. Just my opinion.
没有两种办法。除非你被 C++ 陷阱咬得够深,以至于讨厌这门语言,否则你将成为一个威胁。我建议尝试编写函数而不是类。很多人认为 OOP 很棒,但实际上大多数用户希望您的代码“做”某事,而不是“成为”某事。不管怎样,祝你好运。 :-)
No two ways about it. You're going to be a menace until you've been bit enough by C++ gotchas to hate the language. I'd recommend trying to write functions and not classes. A lot of people think OOP is great, but really most users want your code to "do" something, not "be" something. Anyways, good luck. :-)
肯定是钱斯说的。 C++ 中的内存管理是明确的。我在大学里有一本很棒的教科书,叫做 Deitel C++。这是一本 C++ 圣经。
我还将学习标准模板库和 Boost。
Definitely what Chance said. Memory management is explicit in C++. I had an excellent textbook in college called Deitel C++. It's a C++ Bible.
I would also learn up on the Standard Template Library and Boost.
这可能会给您一些想法。
一些重要的摘录:
下面是如何做:
对编程感兴趣,并做一些因为它很有趣。制作
确保它足够有趣,这样你才会愿意
投入你的十年/一万个小时。
程序。最好的学习方式是边做边学。说起来
更专业地说,“个人的最高表现水平
在给定域中,不会自动获得
经验丰富,但表现水平可以提高
即使是经验丰富的人也经过深思熟虑
努力改进。”(第 366 页)和“最有效的学习
需要一个明确的任务,并具有适当的难度级别
特定的个人、信息反馈和机会
重复和纠正错误。”(第 20-21 页)这本书
实践中的认知:日常生活中的思维、数学和文化
生活是这个观点的一个有趣的参考。
与其他程序员交谈;阅读其他程序。这更
比任何书籍或培训课程都重要。
如果你愿意,可以在大学学习四年(或者在研究生学习更长的时间)
学校)。这将使您能够获得一些需要的工作
证书,它会让你更深入地了解
领域,但如果你不喜欢上学,你也可以(只要有一些奉献精神)
在自己或工作中获得类似的经验。无论如何,预订
仅靠学习是不够的。 “计算机科学教育不能
使任何人成为专家程序员不仅仅是学习画笔和
颜料可以使一个人成为专业画家”埃里克·雷蒙德说,
《新黑客词典》的作者。我最优秀的程序员之一
曾经被雇用的人只有高中学历;他制作了很多
很棒的软件,有自己的新闻组,库存充足
选择购买自己的夜总会。
与其他程序员一起处理项目。成为最好的程序员
一些项目;对其他人来说是最糟糕的。当你是最好的时候,你
测试您领导项目和激励他人的能力
与你的愿景。当你最糟糕的时候,你才能学到大师的东西
做,你就会学到他们不喜欢做的事情(因为他们让你
为他们做这件事)。
跟随其他程序员完成项目。了解一个程序
别人写的。了解如何理解并修复它
当原来的程序员不在身边时。想想如何
设计你的程序,让那些愿意维护的人更容易
他们在你之后。
学习至少六种编程语言。包括一个
支持类抽象的语言(如 Java 或 C++),一种
支持函数抽象(如 Lisp 或 ML),
支持句法抽象(如 Lisp),一种支持
声明性规范(如 Prolog 或 C++ 模板),一种
支持协程(如 Icon 或Scheme),并且支持
并行性(如 Sisal)。
记住“计算机科学”中有一个“计算机”。知识
你的计算机执行一条指令、取一个字需要多长时间
从内存(有或没有缓存未命中)读取连续的字
从磁盘中查找,并寻找磁盘上的新位置。 (答案在这里。)
参与语言标准化工作。它可能是
ANSI C++ 委员会,或者它可能会决定您的本地编码是否
style 将有 2 或 4 个空格缩进级别。不管怎样,你
了解其他人对某种语言的喜爱程度以及他们的喜爱程度
有这样的感觉,甚至可能了解一下他们为什么有这样的感觉。
有良好的意识摆脱语言标准化工作
尽快。
This might give you some ideas.
Some important excerpts :
And here is how to do :
Get interested in programming, and do some because it is fun. Make
sure that it keeps being enough fun so that you will be willing to
put in your ten years/10,000 hours.
Program. The best kind of learning is learning by doing. To put it
more technically, "the maximal level of performance for individuals
in a given domain is not attained automatically as a function of
extended experience, but the level of performance can be increased
even by highly experienced individuals as a result of deliberate
efforts to improve." (p. 366) and "the most effective learning
requires a well-defined task with an appropriate difficulty level for
the particular individual, informative feedback, and opportunities
for repetition and corrections of errors." (p. 20-21) The book
Cognition in Practice: Mind, Mathematics, and Culture in Everyday
Life is an interesting reference for this viewpoint.
Talk with other programmers; read other programs. This is more
important than any book or training course.
If you want, put in four years at a college (or more at a graduate
school). This will give you access to some jobs that require
credentials, and it will give you a deeper understanding of the
field, but if you don't enjoy school, you can (with some dedication)
get similar experience on your own or on the job. In any case, book
learning alone won't be enough. "Computer science education cannot
make anybody an expert programmer any more than studying brushes and
pigment can make somebody an expert painter" says Eric Raymond,
author of The New Hacker's Dictionary. One of the best programmers I
ever hired had only a High School degree; he's produced a lot of
great software, has his own news group, and made enough in stock
options to buy his own nightclub.
Work on projects with other programmers. Be the best programmer on
some projects; be the worst on some others. When you're the best, you
get to test your abilities to lead a project, and to inspire others
with your vision. When you're the worst, you learn what the masters
do, and you learn what they don't like to do (because they make you
do it for them).
Work on projects after other programmers. Understand a program
written by someone else. See what it takes to understand and fix it
when the original programmers are not around. Think about how to
design your programs to make it easier for those who will maintain
them after you.
Learn at least a half dozen programming languages. Include one
language that supports class abstractions (like Java or C++), one
that supports functional abstraction (like Lisp or ML), one that
supports syntactic abstraction (like Lisp), one that supports
declarative specifications (like Prolog or C++ templates), one that
supports coroutines (like Icon or Scheme), and one that supports
parallelism (like Sisal).
Remember that there is a "computer" in "computer science". Know how
long it takes your computer to execute an instruction, fetch a word
from memory (with and without a cache miss), read consecutive words
from disk, and seek to a new location on disk. (Answers here.)
Get involved in a language standardization effort. It could be the
ANSI C++ committee, or it could be deciding if your local coding
style will have 2 or 4 space indentation levels. Either way, you
learn about what other people like in a language, how deeply they
feel so, and perhaps even a little about why they feel so.
Have the good sense to get off the language standardization effort as
quickly as possible.