正确学习 C:是还是不是?

发布于 2024-07-13 05:51:32 字数 563 浏览 11 评论 0原文

我的主要语言是 PHP,但我也用其他语言做过一些(不是很多)编程。

我用 C 语言为 Apache 编写了 2 个模块。 我用 C 语言编写它们,因为这是性能非常重要的事情之一。 (动态生成世界投影地图并输出为 .png)。

这些模块可以工作,这是我可以保证代码质量的范围。 不要误会我的意思,我尽了最大努力编写正确的代码,但我确信它还有很大的改进空间。

我正在考虑将当前模块更改为线程化,但没有使用线程化软件的经验,并且诸如追查错误之类的事情仍然花费了我很多时间。

我的问题是:
我应该首先学习如何正确地用 C 编程(获取副本 C 编程语言)还是您推荐另一种方法。

注意:
我目前没有计划使用 C 语言(除了 Apache 模块)

My primary language is PHP, but I have done some (not very much) programming in other languages.

I've written 2 modules for Apache in C.
I wrote them in C because this was one of the things where performance did matter. (generating projected maps of the world on the fly and output to .png).

These modules work, and that's as far as I can guarantee the quality of the code.
Don't get me wrong, I did my best to write correct code, but I'm sure it has a lot of room for improvement.

I'm playing around with the thought of changing the current modules to be threaded but have no experience with threaded software and thing like chasing down bugs still take me a lot of time.

my question is:
Should I first learn to properly program in C (get a copy The C Programming Language) or do you recommend another approach.

note:
I've currently no plans for using C other that for Apache modules

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(14

杀手六號 2024-07-20 05:51:34

读了这本书。 你会很高兴你这么做了。 它会向您介绍很多您不会遇到的东西。 我们将向您介绍该语言的所有功能,而不必在您认为需要时才偶然发现它们。

Read the book. You'll be glad you did. It will introduce you to a lot of stuff that you wouldn't otherwise come across. You'll be introduced to all of the features of the language, instead of having to stumble across them when you think you need them.

欢烬 2024-07-20 05:51:34

也许我有点现代主义者,但如果你要正确学习 C,我不建议从 K&R 开始。 为什么要研究过时的标准? 拿起一本教您 C99 标准的书并从中学习。 因为您可能已经有点熟悉 C Primer Plus 或类似的东西。

Maybe i'm a bit of a modernist but if you are going to learn C properly I would not recommend starting with K&R. Why study an antiquated standard? Pick up a book that teaches you the C99 standard and learn from that. Since you're already a bit familiar maybe C Primer Plus or something similar.

晨曦÷微暖 2024-07-20 05:51:34

如果您不打算将 C 用于其他用途,我建议切换到 Java,因为它的并发性要容易得多(至少在我看来)。

它还有一个非常大的标准库,非常易于使用,并且可能会大大加快您的开发速度。

If you're not going to be using C for anything else, I'd recommend to switching to Java, as it's concurrency is much easier (in my opinion at least).

It also has a very large standard library that is very easy to work with and will probably speed your development up considerably.

亽野灬性zι浪 2024-07-20 05:51:33

如果你认真对待编程,我认为学习C真的很重要。 它是许多语言的基础,您会遇到很多用 C 编写的源代码。但是,我们可以告诉 Java、C++ 等。

恕我直言,我认为您应该继续编写模块并学习新东西,因为你需要它们。 这是学习东西的最好方式

If you are serious about programming, I think learning C is really important. It's the foundation of many languages and you'll encounter lots of source code written in C. However, we could tell so of Java, C++, etc..

IMHO, I think you should just continue to write your modules and learn new things as you need them. That's the best way of learning things

能怎样 2024-07-20 05:51:33

听起来你已经做得很好了。 开源这些模块并征求社区反馈怎么样?

Sounds like you are doing quite well already. What about open sourcing those modules and asking for feedback from the community?

陌若浮生 2024-07-20 05:51:33

只学习您需要的内容。

您无需花时间阅读《C 编程语言》并学习该语言的每个功能,它就会变得有用。 根据需要使用《C 编程语言》作为查找工具。 如果您更频繁地开始使用 c 语言编程,那么就投入时间更彻底地学习这门语言。

Only learn as much as you need to.

You don't need to spend the time to read The C Programming Language and learn every feature of the language for it to be useful. Use The C Programming Language as a look up tool as you need it. If you start programing in c more often, then invest the time is learning the language more thoroughly.

甜尕妞 2024-07-20 05:51:33

学习编程语言的最好方法就是使用它。 因此,向前迈进并实际用 C 编写 apache 模块是一个很好的方法。 但是,如果您想更深入地了解该语言,您应该做几件事:

  • 使用该语言。 您已经做到了:)
  • 了解该语言。 “圣经”K&R 是你至少应该有一些知识的东西——你不需要知道这本书的每一点,但你应该使用它至少对那些不存在的语言特性有一个想法。不要使用太频繁。 有一天它会有所帮助。
  • 与他人合作。 与其他人一起参与一个项目,让其他人阅读您的代码并阅读他们的代码。 开源通常是实现此目的的好方法,尽管也有其他选择。

就我的“职业生涯”而言,我也从 PHP 开始,最后转向 C。阅读书籍(我强烈推荐 Peter van der Linden 的《专家 C 编程》,不幸的是,该书已经绝版)将使您对 C 语言有更深入的了解。语言的内在,从而使您成为更好的程序员。 我不知道 K&R 的每一页,但我从不后悔使用它并适应它(我想我宁愿使用它而不是阅读它 - 在我看来,它不是一本教科书,而是一本参考书)。

The best way of learning a programming language is by using it. So stepping forward and actually writing apache modules in C is a good approach. If you, however, want to dive deeper in that language you should do several things:

  • use the language. You already did that :)
  • get to know the language. The "bible" K&R is something you should have at least some knowledge about -- you don't need to know every bit of the book, but you should use it to have at least an idea about the language features that aren't used too often. It will get helpful one day.
  • collaborate with others. Get involved in a project with others to have others read your code and also read their code. Open Source is usually a good way for doing this, though there are other options too.

Speaking from my "career" I also started with PHP and ended up at C. Reading books (I can highly recommend "Expert C Programming" by Peter van der Linden, which unfortunately is out of print) will give you a deeper understanding of the inners of the language and thus make you a better programmer. I don't know every page of K&R but I never regretted using and getting comfortable with it (I think I rather used it than read it -- it's not a text book but a reference in my opinion).

墨小沫ゞ 2024-07-20 05:51:33

我强烈推荐那本书。 即使您将来不会使用 C,您也永远不知道是否必须使用,这是一本完美的书,可以帮助您获得更多 C 的经验/知识。

如上所述,C 是许多其他流行语言的基础,因此即使您最终没有更多地使用 C,您也可能最终会使用它的后继者之一。

I would highly recommend that book. Even if you do not see yourself using C in the future, you never know if you may have to and that is a perfect book to gain some more experience/knowledge for C with.

And as mentioned above C is the foundation of many other popular languages, so even if you dont end up using C more you may end using one of it successors.

空城之時有危險 2024-07-20 05:51:33

即使你将来没有计划用 C 语言编程,或者即使你确信你永远不需要用一些与 C 相关的语言进行开发,出于历史原因,我还是会推荐 K&R 书:这是一个很好的实践向已知的艺术大师学习。

Even if you have no plan to program in C in the future, or even you are sure you will never have to develop in some c-related languages, I would recommend anyway the K&R book for historical reasons: it's a good practice to learn from the known masters of your art.

半城柳色半声笛 2024-07-20 05:51:33

我认为您在这里面临的真正问题是:

1) C 适合您正在执行的任务吗?
2)随着需求的变化,你是否应该增加你的C语言知识?

对于问题 1,也许您的应用程序有 C 的替代方案。 您需要输出 .png 图像,并且需要管理线程:也许 Java 或 Python 是 C 的更好替代品(.png 输出在两种语言中都是几行,而我认为您需要外部库等在 C 中。同样的事情对于

问题 2,如果您坚持使用 C,如果您想避免随着复杂性增加而陷入陷阱(特别是对于像 C 这样的低级语言),可能最好更深入地研究该语言。

I think the real issues you're facing here are:

1) is C appropriate for the task you're doing?
2) should you increase your knowledge of the C language as the requirements change?

For question 1, maybe there are alternatives to C for your application. You need to output .png images, and you need to manage threading: maybe Java or Python are better alternatives to C (.png output is a few lines in both languages, while I think you need external libraries and such in C. Same thing for threading.

For question 2, if you persist in using C, probably it's better to study the language more in depth, if you want to avoid pitfalls as complexity increases (expecially for a low level language like C).

碍人泪离人颜 2024-07-20 05:51:33

我想说,正确地学习一些东西永远不会有坏处。 对 C 的深入理解肯定会加深你对编程的理解。

您将来是否会使用该语言本身并不重要,但对于理解底层发生的事情来说,它是无价的。

I'd say it never hurts to learn something properly. And a solid understanding of C will definitely further your understanding of programming.

It does not matter if you will use the language itself in the future, but for understanding what is happening under the hood, its priceless.

云朵有点甜 2024-07-20 05:51:33

我想说,对于每个程序员来说,掌握 C 语言中重要的低级概念(例如指针和手动内存管理)非常重要。 这使您能够深入了解事物的实际工作原理,并且即使在更高级别的编程时也很有用。 但是,如果您不定期使用 C,我认为真正掌握整个语言没有任何意义。 例如,我不会花太多时间在标准库上或学习如何用 C 语言设计重要的项目。只需坚持关键概念即可。

I'd say it's important for every programmer to master the low-level concepts that are important in C, like pointers and manual memory management. This gives you tremendous insight into how things really work and is useful even when programming at higher levels. However, if you won't be using C on a regular basis, I don't see any point in truly mastering the whole language. For example, I wouldn't spend too much time on the standard library or on learning how to design non-trivial projects in C. Just stick to the key concepts.

陌路黄昏 2024-07-20 05:51:33

我已经从 BASIC 发展到 FORTRAN,然后是 Java,目前主要使用 PHP 和 Perl 的组合。 除了摆弄 Apache 模块之外,我从未真正使用过 C,但无论你学习哪种语言,最好的学习方法就是实践。

使用一本书向您介绍该语言,但要实际学习。

I have progressed from BASIC to FORTRAN then Java and currently mainly using combinations of PHP and Perl. I have never really used C apart from messing around with Apache modules, but whichever language you do learn the best way to learn is by doing.

Use a book to introduce you to the language, but learn it practically.

凉世弥音 2024-07-20 05:51:33

我绝对推荐学习《C 编程语言》(K&R)。 这是一本非常简洁且有用的 C 参考书。如果您发现从 K&R 学习有点困难,我会毫不犹豫地买一本关于该语言的更温和的书,但 K&R 是您会回来阅读的书当有一些事情你不确定的时候。

另外,值得指出的是,线程编程打开了一个充满潜在问题的全新世界,因此我绝对建议您买一本书来学习如何正确地做到这一点。

I would definitely recommend getting The C Programming Language (K&R). It is a very concise and useful reference to C. If you find learning from K&R a bit hard I wouldn't hesitate to get a gentler book on the language, but K&R is the book you'll be coming back to when there's something you're not sure about.

Also, it's worth pointing out that threaded programming opens a whole new world of potential problems, so I'd definitely recommend getting a book to learn how to do that properly as well.

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