TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

As a system programming language, C still deserves learning today

153 点作者 nanxiao将近 6 年前

25 条评论

lifthrasiir将近 6 年前
My view strongly aligns with John Regehr&#x27;s [1] (emphases original):<p>&gt; My main idea is that we need to teach C in a way that helps students understand why a very large fraction of critical software infrastructure, including almost all operating systems and embedded systems, is written in C, while also acknowledging the disastrously central role that it has played in our ongoing computer security nightmare. [...]<p>&gt; We’d like students to be able to answer the question: <i>Is C an appropriate choice for solving this problem?</i> [...] The second big thing each student should learn is: <i>How can I avoid being burned by C’s numerous and severe shortcomings?</i><p>[1] <a href="https:&#x2F;&#x2F;blog.regehr.org&#x2F;archives&#x2F;1393" rel="nofollow">https:&#x2F;&#x2F;blog.regehr.org&#x2F;archives&#x2F;1393</a>
评论 #20323319 未加载
评论 #20323582 未加载
评论 #20323744 未加载
fit2rule将近 6 年前
In my opinion, as a programmer who learned C when it was still in its infancy as a language, and who has used it in nearly every single project in 30+ years of professional development, what we need to do is not just teach the C LANGUAGE, but also the C RUNTIME, EXECUTION ENVIRONMENT, and .. most important of all .. the C COMPILER.<p>Each of these aspects of the &quot;C ecosystem&quot; needs to be well understood in order to be a productive, high-quality C developer. Its not enough to just type a bunch of stuff and then throw it at the compiler and see if it works - you have to understand what the compiler is doing with your language constructs and how this will be executed in the target execution environment.<p>So many times I&#x27;ve had to debug &quot;professional C developers&quot; who have no clue what the compiler is doing to their code, no idea what a TEXT SEGMENT is, absolutely zero responsibility for the HEAP, let alone runtime loading and linking. Its all just &#x27;voodoo&#x27; behind the &#x27;black box&#x27; of the compiler.<p>But even just having a basic understanding of these components can mean a huge difference in quality C code.<p>Another thing every C developer needs to know: how to debug code and read assembly language in the context of the operating&#x2F;execution environment. You don&#x27;t need to be able to WRITE assembly, but at least fire up the debugger and step through your program a few times to see how it behaves .. this can go a long way towards increasing a C developers understanding for what is happening and why its important to know all the other components. Too many times I&#x27;ve solved a major, delaying bug in a project by just re-ordering the linker commands or, even worse, cleaning up the linker commands to remove stuff that was glibly thrown at the wall by some other dev.<p>Also - all warnings are errors: no exceptions.
评论 #20327602 未加载
评论 #20323393 未加载
gilmi将近 6 年前
&gt; There are many ways of writing wrong C code, but you only need to make sure what you write is correct and in defined behavior, that’s all about C programming.<p>But this is a something that even experts fail to do.
评论 #20323056 未加载
评论 #20323480 未加载
评论 #20323245 未加载
评论 #20323558 未加载
评论 #20323800 未加载
qiqitori将近 6 年前
If a programmer can&#x27;t at least read (normal) C, I&#x27;d doubt they&#x27;re a fully qualified programmer. (Just my way of viewing things, I might be wrong. My reasoning is that if you don&#x27;t know C and pointers, you probably don&#x27;t know what a simple line like &#x27;foo = bar + &quot;abc&quot;&#x27; even entails.)<p>It&#x27;s a tiny language, has easy syntax, and &quot;undefined&quot; behavior (which you don&#x27;t normally run into) exists for a reason -- e.g. to avoid having to check for unlikely cases every time a heavily used function (e.g. memcpy) is called.
评论 #20323537 未加载
评论 #20322901 未加载
评论 #20324453 未加载
评论 #20323102 未加载
_hardwaregeek将近 6 年前
Hmm, I&#x27;m very skeptical of this premise. Basically every halfway decent CS program has a systems level class in C. While bootcamps usually don&#x27;t teach C, they&#x27;re not necessarily dismissing C as much as ignoring the entirety of systems programming.<p>I don&#x27;t want to be overly harsh on the writing, as English does not appear to be the author&#x27;s first language (you should see my Chinese). However, here&#x27;s some pointers (heh)<p>Especially with Go and Rust go viral right now =&gt; Especially with Go and Rust having gone viral<p>No matter you never touched C or you are a veteran =&gt; Whether you are a C novice or a C veteran ^[1]<p>and not as primitive =&gt; and is not as primitive<p>Regardless of you a system language programmer =&gt; Regardless if you are a systems language programmer<p>In general, I&#x27;d recommend using &quot;you&quot; a little less frequently and working in more. I.e. &quot;I highly recommend you read Modern C if you haven’t read it before&quot; could become &quot;I&#x27;d highly recommend Modern C to those who have not read it already&quot;.<p>But again, wonderful job all things considered. Please continue to write blog posts.<p>[1] I tried to rewrite this in the spirit of the original, but the double negative of &quot;No matter...never&quot; was too awkward to keep. Also feel free to remove the C&#x27;s
评论 #20324068 未加载
评论 #20323646 未加载
keithnz将近 6 年前
I think if you are interested in systems or embedded programming C is definitely a good language to learn still. I programmed in C ( and C++ ) most of the 90s, focused on C++ and other languages for the 00s, then came back to it 2010ish, and I found it refreshing using modern techniques in C. However, I&#x27;d still say avoid it if you don&#x27;t have to use it. But the key here is knowing exactly what you are trading off before choosing to avoid it. In most cases C++ is a viable alternative ( not always ). Rust is starting to look good in the embedded world, but I&#x27;d like to see more vendor support for it, and very few professional Rust devs in the embedded space. C is still often the better tradeoff. Also Electronics Engineers often only know C which lets them debug and diagnose hardware. So in the embedded world, you should know C, in the systems world, its a good idea, it will let you read a large majority of all open source system level software
PinkMilkshake将近 6 年前
I would rather resist the temptation if I can avoid it. I&#x27;m so frustrated with what we&#x27;ve come to tolerate with software.<p>Ada&#x2F;SPARK seems to be trying to make a comeback, something I welcome. They are interacting with the &#x27;maker community&#x27; [1] and the online learning resources have improved a ton.[2] SPARK is even taking some inspiration from Rust. [3]<p>[1] <a href="https:&#x2F;&#x2F;www.makewithada.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.makewithada.org&#x2F;</a> [2] <a href="https:&#x2F;&#x2F;learn.adacore.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;learn.adacore.com&#x2F;</a> [3] <a href="https:&#x2F;&#x2F;blog.adacore.com&#x2F;using-pointers-in-spark" rel="nofollow">https:&#x2F;&#x2F;blog.adacore.com&#x2F;using-pointers-in-spark</a>
adzm将近 6 年前
What I find fascinating about C is how mature codebases develop their own meta language with copious macros. These in turn inspired future languages and their built-in capabilities.
评论 #20323036 未加载
评论 #20322996 未加载
评论 #20323211 未加载
评论 #20322903 未加载
noobermin将近 6 年前
One thing the internet as still not learned is how not to needlessly flame. A lot of the comments here are dissing the problems of C (fine) but are completely missing the author&#x27;s main point. For heaven&#x27;s sake, it&#x27;s even a lower bar this time, the title says it all and people are cursing about C. Their main point is simply:<p>&gt;Especially with Go and Rust go viral right now, C seems already forgotten by people. Nevertheless, IMHO, C is still a thing which is worth for you spending some time on it.<p>I happen to agree, especially if you have time to learn Go or Rust but don&#x27;t use it for anything[0], you have time to learn modern C. They didn&#x27;t make this point (they seem more on the side of you should in general) but if you don&#x27;t have the time, I&#x27;d think anyone could make a decision of what&#x27;s worth their time or not.<p>As an aside, this bit is partly true but partly isn&#x27;t:<p>&gt;Last but not least, because C is so “low-level”, you can leverage it to write highly performant code to squeeze out CPU when performance is critical in some scenarios.<p>The reality is C has been around a long time and compilers are written to make fast code from C programs. See this, &quot;C Is Not a Low-level Language; Your computer is not a fast PDP-11.&quot;[1]<p>[0] Point about Go or Rust is if you do intend to use it for something, then that isn&#x27;t learning for edifications&#x27; sake. Ditto C. If you refuse to learn C but it&#x27;s relevant to your job&#x2F;work then that&#x27;s simply neglect of your duties.<p>[1] <a href="https:&#x2F;&#x2F;queue.acm.org&#x2F;detail.cfm?id=3212479" rel="nofollow">https:&#x2F;&#x2F;queue.acm.org&#x2F;detail.cfm?id=3212479</a>
todd8将近 6 年前
I&#x27;ve programmed for many years and taught programming; my trajectory through the various programming languages and paradigms seems to have worked for me. But things have changed in big ways since I learned to program.<p>My first job after grad school was as an assembly language programmer. It&#x27;s humbling and teaches some good programming practices (like &quot;take a small bite and then run tests&quot;). Today, assembly language programming is not appropriate for most applications. Processors are very fast, memories are very large, and instruction sets include numerous complex features that optimizing compilers handle very well. Meanwhile there has been one new programming language after another gradually improving the high level programming tools available.<p>If I was designing a university curriculum for CS, I would introduce languages in this order:<p>First Python, its basics are easy to learn and it allows new programmers to actually tackle interesting assignments. Those that don&#x27;t go on in CS will have still acquired familiarity with a useful language for writing simple programs. It&#x27;s a good language to use as a lingua franca in subsequent courses.<p>Second simple Java and OO design, there are just so many jobs using this language.<p>Third C, introduced along with a study of data structures. Learning data structures as an undergraduate is mostly learning linked structures of one kind or another and C is the best language for this. C is close to what&#x27;s happening at the machine level whereas Python and Java have garbage collection and language features that already include lists, maps, etc. Studying data structures in C lets students see how these higher level abstractions are implemented and prepares them for seeing kernel code.<p>After this there are still some big important languages left out. Lisp&#x2F;Scheme can be introduced in an AI class. Javascript can be introduced in a web programming class. Assembly language can be introduced in a hardware class.<p>The go language would work well for an algorithms class and &quot;modern&quot; Java with collections, streams, modules, etc. for an undergrad compiler class or software engineering class.<p>Naturally SQL should be used in a database class. Git could be introduced after the first year and used for all assignments. LaTeX could be required for all writing assignments.<p>The important language left out here is C++. It&#x27;s just seems so difficult to learn that I don&#x27;t know when or whether it should be taught. C++&#x27;s new features are big improvements, but the historical baggage is a lot to take on as a new programmer. When should C++ (or Rust, or Haskell for that matter) be learned?
评论 #20325095 未加载
cheerioty将近 6 年前
In software development (web&#x2F;mobile) for about 10 years, I finally picked up learning C. 4 weeks in, I finished writing my first Gameboy (Color) game and started work on my first Neo Geo game with awesome progress already. Will share more soon, but the gist is that you can&#x27;t do this in JavaScript, Go or Rust. And don&#x27;t say GBStudio now :)
pjmlp将近 6 年前
There are two main reasons to learn C:<p>1 - Because C and UNIX were built for each other and we have plenty of UNIX clones around<p>2 - To avoid making the same mistakes regarding lack of safety in system languages.
ndesaulniers将近 6 年前
&gt; I highly recommend you read Modern C if you haven’t read it before.<p>I feel like I was pretty disappointed with Modern C, contrasted with Deep C Secrets which taught me a ton. Maybe I should write a book about all of the GNU C extensions and the situations in which they are useful (or the only possible solutions).
评论 #20322914 未加载
评论 #20322963 未加载
评论 #20322925 未加载
azhenley将近 6 年前
I wasn’t very interested in systems level stuff until the last few years with this new wave of systems languages. I’m itching to learn Zig whenever I get some free time!<p>I know most people will say Go isn’t a systems language but it certainly taught me to think differently than when I use C# or Python.
评论 #20322887 未加载
评论 #20323017 未加载
评论 #20323394 未加载
评论 #20323413 未加载
nercury将近 6 年前
It is worth learning C because there is a lot of code written in C.
评论 #20322931 未加载
评论 #20322953 未加载
forrestthewoods将近 6 年前
Every JavaScript&#x2F;python programmer that writes horrifyingly slow string&#x2F;array code that needlessly allocates should be forced to take remedial C.
verisimilitudes将近 6 年前
I disagree. The C programming language is directly responsible for countless damning flaws in modern software and can be credited for the existence of the majority of the modern computer security industry.<p>You can write system software in many languages, including Lisp. For a less outlandish example, Ada is specifically designed for producing reliable systems worked on by teams of people in a way that reduces errors at program run time.<p>I find it amusing to mention UNIX fundamentals as a reason to learn C, considering UNIX is the only reason C has persisted for so long anyway. Real operating systems focused largely on interoperation between languages, not funnelling everything through a single one; Lisp machines focused on compilation to a single language, but that language was well-designed and well-equipped, unlike C.<p>&gt;Last but not least, because C is so “low-level”, you can leverage it to write highly performant code to squeeze out CPU when performance is critical in some scenarios.<p>It’s actually the opposite. The C language is too high-level to correspond to any single machine, yet too low-level for compilers to optimize for the specific machine without gargantuan mechanisms. It’s easier to optimize logical count and bit manipulations in Common Lisp than in C, because Common Lisp actually provides mechanisms for these things; meanwhile, C has no equivalent to logical count and its bit shifting is a poor replacement for field manipulations. Ada permits specifying the bit structures of data types at a very high level, while continuing to use abstract parts, whereas large C projects float in a bog of text-replacement macros.<p>Those are my thoughts on why C isn’t worth learning, although this is nothing against the author.
评论 #20322961 未加载
评论 #20322950 未加载
评论 #20323010 未加载
saagarjha将近 6 年前
I tend to treat C like English: you don&#x27;t <i>have</i> to learn it, and you can certainly get by without it if you stay within a certain semi-isolated community where it&#x27;s not really used. However, it is certainly something that&#x27;s a nice thing to know, if for nothing else that a lot of <i>other</i> people will know it too.
FraKtus将近 6 年前
For me, the advance in thread and memory sanitizers in XCode made it much safer to use C. Its almost fun to create memory leaks now and see the sanitizer spotting them :-)
评论 #20323350 未加载
adamnemecek将近 6 年前
The main problem with C and C++ is the development model. There is a standard committee that meets for a couple of days three times a year. At this meeting, they discuss proposals. They have been talking about ranges since maybe around 2000 and they still aren&#x27;t quite in the language. It would be impossible for me to contribute to any standard even if I wanted to.<p>Rust&#x27;s development happens all on github. I can see all the discussions as they are happening and potentially even meaningfully contribute. Rust already has essentially all the things the C++ standard committee wants to standardize in the next couple of years and then some more.<p>Besides the language itself, the lack of a package manager is a huge hurdle.<p>Is this about knowing C or developing in C? Nothing wrong with knowing C, but developing in C is a bad idea (also immoral &#x2F;s).
评论 #20323176 未加载
评论 #20322934 未加载
valzam将近 6 年前
I don&#x27;t have a traditional CS background and learned several high level languages (interpreted and compiled) before buying Learn C the Hard Way earlier this year. I admittedly stopped short of implementing the larger projects at the end of the book (got too frustrated with the Makefile setup constantly breaking in weird ways for bigger projects...) but I still think I got a lot of value of out implementing some basic algorithms like lists or hashmaps from scratch and having to deal with how memory is used exactly. I agree with the sentiment that C is syntactic sugar for assembly. I would never date to write anything non-trivial in C but can highly recommend anyone to at least spend a couple of months fighting with it.
评论 #20325551 未加载
enriquto将近 6 年前
While C is undoubtedly necessary as a systems programming language, where it really shines is in scientific computing. All the modern scientific stacks (R, julia, numpy, torch, tensorflow, octave, ...) are based mostly on C and, to a lesser extent, on Fortran.
评论 #20323781 未加载
lprd将近 6 年前
I don&#x27;t do any systems programming, but I think it would be valuable to learn C for educational purposes. Could I get some recommendations on books or online material that could get me started?
mastazi将近 6 年前
&gt; Especially with Go and Rust go viral right now<p>Is Go really a system programming language? Are there any notable examples of projects made in Go that can be considered system programming?
评论 #20322927 未加载
评论 #20323024 未加载
meitham将近 6 年前
&gt;&gt;&gt; Especially with Go and Rust go viral right now, C seems already forgotten by people.<p>I hope the Author realise that golang isn&#x27;t a system language!
评论 #20322837 未加载
评论 #20322935 未加载