良好的预防措施(实践)来启动 C++编程

发布于 2024-10-03 08:03:52 字数 147 浏览 0 评论 0原文


我的第一份工作就是开始 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

噩梦成真你也成魔 2024-10-10 08:03:52

也许您已经知道这一点,但对于习惯 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", like ClassType obj;.

断舍离 2024-10-10 08:03:52

有两件事:

  • 获取 Scott Meyers 撰写的 Effective C++ 的副本。
  • 检查你的代码。这不仅可以在开发过程的早期发现潜在的错误,还可以教会您良好的编码习惯(例如,将方法的输入参数声明为 const 引用)。我为此使用 PC-Lint

Two things:

  • Get yourself a copy of Effective C++ by Scott Meyers.
  • Lint your code. This will not only catch potential bugs early in the development process, but also teach you good coding habits (e.g. declaring a method's input arguments as const references). I use PC-Lint for this.
唠甜嗑 2024-10-10 08:03:52

对我来说,Java 和 C++ 之间最大的区别是指针,所以我会尝试把指针弄下来。只是我的意见。

For me, the biggest difference between Java and C++ is pointers, so I would try to get pointers down. Just my opinion.

反目相谮 2024-10-10 08:03:52

没有两种办法。除非你被 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. :-)

债姬 2024-10-10 08:03:52

肯定是钱斯说的。 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.

顾挽 2024-10-10 08:03:52

可能会给您一些想法。

一些重要的摘录:

研究人员(Bloom (1985)、Bryan & Harter (1899)、Hayes (1989)、Simmon & Chase (1973))表明,在任何广泛的领域中发展专业知识都需要大约十年的时间,包括国际象棋、音乐创作、电报操作、绘画、钢琴演奏、游泳、网球以及神经心理学和拓扑学研究。关键是刻意练习:不仅仅是一次又一次地做,而是用一项超出你当前能力的任务来挑战自己,尝试它,分析你在做时和做后的表现,并纠正任何错误。然后重复。然后再重复一次。

下面是如何做:

  • 对编程感兴趣,并做一些因为它很有趣。制作
    确保它足够有趣,这样你才会愿意
    投入你的十年/一万个小时。

  • 程序。最好的学习方式是边做边学。说起来
    更专业地说,“个人的最高表现水平
    在给定域中,不会自动获得
    经验丰富,但表现水平可以提高
    即使是经验丰富的人也经过深思熟虑
    努力改进。”(第 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 :

Researchers (Bloom (1985), Bryan & Harter (1899), Hayes (1989), Simmon & Chase (1973)) have shown it takes about ten years to develop expertise in any of a wide variety of areas, including chess playing, music composition, telegraph operation, painting, piano playing, swimming, tennis, and research in neuropsychology and topology. The key is deliberative practice: not just doing it again and again, but challenging yourself with a task that is just beyond your current ability, trying it, analyzing your performance while and after doing it, and correcting any mistakes. Then repeat. And repeat again.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文