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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

The cost of forsaking C

292 点作者 Halienja超过 8 年前

33 条评论

Nursie超过 8 年前
Ah, C, the love of my life...<p>Want minimal syntactic sugar and a language that&#x27;s not prone to feature-of-the-week hipsterism? C<p>Want to make tiny binaries for some obscure system with virtually no storage or RAM? C.<p>Want to know where every last cycle goes and explicitly control everything? C<p>Want to trivially import any of the huge array of existing libraries? You guessed it...<p>Want to do something you really shouldn&#x27;t, and any &#x27;sensible&#x27; language might attempt to stop, but is called for right here and now...<p>It&#x27;s not the safest language, it&#x27;s not the most expressive, but the syntax is small enough to hold in your head and the body of existing, available work is HUGE. I&#x27;ve been working in C for 15 years and, while I enjoy forays into other languages, it will always be my love.
评论 #12643249 未加载
评论 #12643382 未加载
评论 #12642605 未加载
评论 #12642869 未加载
评论 #12643170 未加载
评论 #12643592 未加载
评论 #12645954 未加载
评论 #12643983 未加载
noelwelsh超过 8 年前
I agree John Regher&#x27;s take on teaching C: <a href="http:&#x2F;&#x2F;blog.regehr.org&#x2F;archives&#x2F;1393" rel="nofollow">http:&#x2F;&#x2F;blog.regehr.org&#x2F;archives&#x2F;1393</a> In summary, it&#x27;s a useful skill to have but you&#x27;re not doing your duty as an instructor if you don&#x27;t make your students aware of its many shortcomings.<p>I particularly want to take issue with the claim in the original post that &quot;C helps you think like a computer&quot;. C&#x27;s machine model might have been a good model for the machines at the time at which it was developed, but it hasn&#x27;t been an accurate model for a long time. A simple example is C&#x27;s assumption that memory is flat and all locations have an address. With multiple layers of caching and nearly a couple hundred registers in current CPUs this is far from the truth. If you think programming in C is programming at the machine level you are deluding yourself.
评论 #12642510 未加载
评论 #12642775 未加载
评论 #12642475 未加载
评论 #12645157 未加载
评论 #12642999 未加载
评论 #12643736 未加载
rvense超过 8 年前
It&#x27;s hard to over-estimate the historical importance of C, and the amount of groundbreaking work and important knowledge codified in C codebases.<p>Also, it can&#x27;t be denied that there will always be areas where the exact control of memory layout that C gives you is not just nice-to-have for performance reasons, but a prerequisite for a good implementation or understanding of some algorithm.<p>Neither of those points, however, mean that C is the only suitable language imaginable for doing low-level work, or that the past forty years of programming language research are irrelevant to the spaces that C excels in. I think Rust shows quite succintly the immense value of the combination of an expressive type system and C-like zero-overhead abstractions.<p>Learning C, like learning some assembly languages, to some extent is probably necessary if you&#x27;re serious about understanding computers, just to understand what&#x27;s going on. But when it comes to actual use in production systems, I am glad that we are seeing serious alternatives to a language so prone to simple bugs as C. Think of all the time and money that have been lost to buffer overflows and segmentation faults.
评论 #12642276 未加载
评论 #12642178 未加载
评论 #12642234 未加载
dreta超过 8 年前
There’s a lot of problems with C, like the fact you have to break out of case statements, or string concatenation, or overuse of the static keyword. These are actual problems, which C++ doesn’t even begin to try and solve, instead introducing useless features and bloat. C is still one of the few popular languages that allows you to talk to the machine directly. It’s a language that doesn’t rely on hidden run-time logic, or hidden implementation costs. It doesn’t enforce any particular programming style on you, and lets you do anything a process is capable of doing.<p>Software engineers these days are so lost in abstractions and design patterns that they forget that at the end of the day a program is just data, and a set of operations that transform that data. There’s huge value in writing code that does everything explicitly from top to bottom, both from a readability, and from a debugability standpoint. Instead, these days, software is designed using UML diagrams and OOP concepts while pretending that objects are ideas that float in some abstract disconnected space. All in the name of concepts envisioned by people who write books instead of programming, and who never saw even a glimpse of a problem you’re trying to solve.<p>Languages like C will never become obsolete. There’s always a new frontier of hardware that needs fast, tailored software. Few years ago that was phones, and watches, next it might be tiny implants. Anybody who thinks languages like C is obsolete should ask themselves “why was my Comodore64 more responsive than a PC i bought in 2016?”, or &quot;why is my dual-core Android smartphone with 1GB of RAM barely usable after a year”. Modern languages and programming practices have this amazing ability to completely negate the massive progress hardware has made.
评论 #12643591 未加载
评论 #12643027 未加载
评论 #12643106 未加载
评论 #12643171 未加载
Animats超过 8 年前
The industry took a giant step backwards when C displaced Pascal. The original Macintosh apps were in Pascal and the MacOS API were all Pascal-oriented.<p>C has three fundamental issues:<p>1) How big is it?<p>2) Who owns it?<p>3) Who locks it?<p>C&#x27;s lack of help in dealing with all three is the main cause of most memory-related program bugs. I once tried to fix #1 in a backwards compatible way. See [1]. After much discussion on some mailing lists, there was general agreement that this was technically feasible but not politically feasible.<p>(I once had hope that Rust would replace C, but Rust has gotten too fancy, with too much input from the functional programming people, the template enthusiasts, and the type theorists. Rust isn&#x27;t bad, but it&#x27;s at least as complex as C++.)<p>[1] <a href="http:&#x2F;&#x2F;www.animats.com&#x2F;papers&#x2F;languages&#x2F;safearraysforc43.pdf" rel="nofollow">http:&#x2F;&#x2F;www.animats.com&#x2F;papers&#x2F;languages&#x2F;safearraysforc43.pdf</a>
评论 #12644995 未加载
评论 #12645272 未加载
评论 #12644000 未加载
评论 #12648204 未加载
评论 #12647459 未加载
评论 #12645358 未加载
评论 #12644069 未加载
delegate超过 8 年前
The author uses C and C++ interchangeably, but these are two distinct languages.<p>Although technically a superset of C, C++ has constructs and paradigms which make you think in totally different ways.<p>In fact C++ introduces many language features which (should) protect programmers from &#x27;C&#x27; mistakes in their C++ code.<p>For example, in modern C++ you shouldn&#x27;t manage memory directly, but use smart pointers and containers. You can, but you shouldn&#x27;t.<p>And there are dozens of such recommendations. Which is the right approach, imho. You can still do the low-level dangerous stuff if you feel brave, but officially you should stick to the &#x27;safe&#x27; paradigms that the language now offers.<p>However, the paradigms that C enforces on you are the paradigms of how to do things <i>fast</i>. You wear no protection so you are much more nimble, but much more vulnerable at the same time. Which is good for some types of projects, but not for all.
评论 #12642731 未加载
评论 #12642962 未加载
MrBuddyCasino超过 8 年前
&gt; C helps you think like a computer<p>I recently bought K&amp;R, doing a bit of micro-controller stuff without the Arduino abstractions, and this I can agree with. I now have an idea how code really gets executed on a CPU, and how the contract between the bare metal and the assembler code for doing so looks like.<p>That the concept of a stack is built into x86, and why calling conventions are important, all of this stuff I had no idea doing Java development for all these years. What do I need a linker for? Object files, what?<p>I don&#x27;t really like it, but there is something strangely beautiful about it - if you look hard enough, you can see the machine shining through the unforgiving cold blue ice that is C.
评论 #12642739 未加载
评论 #12642820 未加载
Manishearth超过 8 年前
TLDR: Goto last line of this comment<p>&gt; It is still one of the most commonly used languages outside of the Bay Area web&#x2F;mobile startup echo chamber;<p>Fair.<p>&gt; C’s influence can be seen in many modern languages;<p>Saying that that&#x27;s a reason to learn C is a non sequitur. Why?<p>&gt; C helps you think like a computer; and,<p>So does C++. And Rust. And D. All the stuff about databases can be done in any of these languages, C doesn&#x27;t have a monopoly over letting you be close to the metal. It&#x27;s one of the only languages that pretty much <i>forces</i> you to be close to the metal, but that&#x27;s not a plus point.<p>&gt; Most tools for writing software are written in C (or C++)<p>True. Hacking on your tools is great. But hacking on your tools rarely requires proficiency in a language (unless you&#x27;re doing something major, which you&#x27;re not), I&#x27;ve hacked on tools written in all kinds of languages that I don&#x27;t know.<p>And the justification behind this point follows the same flimsy reasoning as the previous one, the reasoning that C is the only low level language out there. The post gives &quot;browsers, operating systems and languages&quot; as examples, but all three of these exist in Rust (Servo, redox&#x2F;intermezzos&#x2F;a bunch more, and rustc). I&#x27;m sure that D is up to the task for such software too, if it doesn&#x27;t have them already. C++ of course has all of these.<p>Sure, you need to know <i>some</i> C when doing low level programming and&#x2F;or FFI. But nobody&#x27;s arguing against that. &quot;Everyone “has been meaning to” learn Rust or Go or Clojure over a weekend, not C.&quot; is a false dichotomy. With Rust for example it&#x27;s pretty easy to learn enough C to manage once you&#x27;ve learned Rust (there are tons of folks in the Rust community who have done this). You&#x27;re not <i>forsaking</i> C, you&#x27;re just focusing on something better. You can learn enough C to be able to read code and do FFI, and you&#x27;re pretty much set for writing databases or operating systems or networking stacks or whatever. Reading C isn&#x27;t too hard and if you speak another low level programming language you can pick this up over a weekend.<p>The only valid argument I see here is that C is is still <i>used</i> a lot in existing codebases, and you should be proficient if you want to be able to contribute significantly to them. Of course. But cut all the crap about C being the <i>only</i> language that can handle these use cases.
评论 #12642162 未加载
评论 #12642212 未加载
评论 #12642304 未加载
kensai超过 8 年前
Although there is little need for C to evolve (apart from certain security holes), I think there is space. Thankfully, there are still persons that care about its evolution.<p>The K&amp;R is a classic, but it shows its age, especially as we have reached C11 by now. And C2x might be right around the corner. A third edition of the book won&#x27;t be that bad.<p><a href="http:&#x2F;&#x2F;www.open-std.org&#x2F;jtc1&#x2F;sc22&#x2F;wg14&#x2F;www&#x2F;docs&#x2F;n2021.htm" rel="nofollow">http:&#x2F;&#x2F;www.open-std.org&#x2F;jtc1&#x2F;sc22&#x2F;wg14&#x2F;www&#x2F;docs&#x2F;n2021.htm</a>
评论 #12642559 未加载
adrianN超过 8 年前
Isn&#x27;t K&amp;R&#x27;s book littered with code examples that were canonical in the 80&#x27;s but have glaring security holes? I wonder whether it&#x27;s a good idea to have students work through &quot;the bible&quot;. Hopefully they provide extensive exegesis in the lectures.
评论 #12642207 未加载
评论 #12642141 未加载
评论 #12642473 未加载
nickpsecurity超过 8 年前
Most of this just says C was a popular implementation language following UNIX’s fame. So, many things are written in C. So, knowing C will help you understand how they work. People doing cutting-edge work that pick C are usually clear that they pick it for compiler and talent availability, not technical superiority for problem at hand. Now for the No’s. You don’t need to know it for systems programming as plenty of better languages exist for that. It barely contributed anything to good programming languages compared to ALGOL, Simula, Modula, or LISP. Many key designs pushing OS’s forward were not in C: Burrough’s ALGOL, IBM’s PL family, MULTICS in PL&#x2F;0 &amp; BCPL (UNIX started as MULTICS subset), VMS in BLISS, LISP machines in LISP, Smalltalk-80 in Smalltalk-80, Oberon systems in Oberon dialects, Spin in Modula-3, JX in Java, and recently unikernels in Ocaml.<p>So, C is a necessary evil if you want to understand or extend legacy systems whose authors preferred C. It’s also trendy in that people keep it mostly like it is while defending any problems it has. That’s a social thing. Like COBOL and PL&#x2F;I are with the mainframe apps for companies using them. It’s not the best language for systems programming along a lot of metrics. One doing clean-slate work on a platform can use better languages to do better in the long-term. Short-term benefits matter, though, so such projects often compile to C or include C FFI to benefit from legacy stuff.
Annatar超过 8 年前
While everything that the author wrote is true, and I will forever love C, sometimes I wonder if I didn&#x27;t get short changed by never having been taught ANSI Common LISP at the university.<p><i>LISP is worth learning for a different reason — the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot.</i><p><a href="http:&#x2F;&#x2F;www.catb.org&#x2F;~esr&#x2F;faqs&#x2F;hacker-howto.html" rel="nofollow">http:&#x2F;&#x2F;www.catb.org&#x2F;~esr&#x2F;faqs&#x2F;hacker-howto.html</a><p>Functional language? Check. Stateless? Check. Reentrant? Check. Has a compiler which can generate machine code ELF binary executables? Check.<p>That&#x27;s not to say one shouldn&#x27;t learn C - after all, C is the contemporary portable assembler. But if one should also learn C, one should learn assembler too, preferably on a processor with an orthogonal instruction set architecture, like a Motorola 68000. Understanding both, we come back to the author&#x27;s point - without understanding how the machine works, fast, small, efficient and elegant software will remain forever elusive.
partycoder超过 8 年前
Ada and Pascal are not dead and are viable alternatives to C. If you don&#x27;t know them, check them out.<p>The C philosophy &quot;the programmer knows what they&#x27;re doing&quot; does not necessarily scale. It works when your team is strong or well supervised, but if that is not the case due to location, budget or whatever reason, unless you can afford a static analysis tool like Klocwork that can weed out mistakes while not sacrificing productivity, by going low level you have picked a hard battle.<p>C gives you a lot of power, but also a lot of rope to hang yourself with. I don&#x27;t even want to imagine what kind of apocalypse I would see if you give multithreading and memory management powers to the caliber of people I&#x27;ve seen recently.
fauigerzigerk超过 8 年前
C has one quality that no other language has. You can write libraries in it that can easily be used from all other languages on every platform.
评论 #12642839 未加载
评论 #12643243 未加载
anta40超过 8 年前
&gt;&gt; Learning about operating systems would be much harder without C. The operating systems that we use are mostly written in C, the C standard library is tightly coupled to the syscall interface, and most resources dealing with operating systems concepts assume knowledge of C.<p>I wonder what if Kernighan, Ritchie et all decided to write UNIX in Pascal, not in C.<p>Hmmm.... :D
评论 #12642183 未加载
评论 #12642588 未加载
评论 #12642236 未加载
评论 #12642847 未加载
评论 #12642230 未加载
jimjimjim超过 8 年前
if anything c is more popular now than 5-10 years ago. not c++ but normal c. especially with the pendulum swing away from oo<p>it&#x27;s almost an ideal hipster language.
评论 #12642397 未加载
ninjakeyboard超过 8 年前
Contrast with <a href="http:&#x2F;&#x2F;chrisdone.com&#x2F;posts&#x2F;dijkstra-haskell-java" rel="nofollow">http:&#x2F;&#x2F;chrisdone.com&#x2F;posts&#x2F;dijkstra-haskell-java</a>
评论 #12643516 未加载
quantum_state超过 8 年前
Besides the reasons already listed, one more is C can be used to program almost all of the micro controllers, an essential electronic element in modern life.
评论 #12650801 未加载
评论 #12648186 未加载
musha68k超过 8 年前
Nobody is &quot;forsaking&quot; C.<p>As mentioned in the article it is still a good way to learn about computers and it&#x27;s the true &quot;lingua franca&quot; of our times - that said it needs to be put to rest for infrastructure software <i>now</i>.<p>I for one welcome our new Rust writing overlords.
conjectures超过 8 年前
While K&amp;R is a nice book, it&#x27;s really not sufficient to become productive with C. IIRC it doesn&#x27;t cover things like make, valgrind and libraries. There&#x27;s a book 21st Century C which does the job of addressing that.
评论 #12645064 未加载
ArkyBeagle超过 8 年前
&quot;Most of our students use interpreted languages with popular implementations written in C.&quot;<p>Well, guess what? Most of the &#x27;C&#x27; code I&#x27;ve written in the last ten years pretty much reflects the selfsame reality - next to nothing is done directly in &#x27;C&#x27; but rather as posts of &quot;transactions&quot; to an interface. These may or may not be in text form but it&#x27;s not much work to make &#x27;em be in text form.<p>By the way - &#x27;C&#x27; is excellent for text manipulation, even using the crufty old library calls.<p>If you do this and you do it carefully, all the horrors of &#x27;C&#x27; become at least manageable. Done carefully enough, you don&#x27;t even need all the new &quot;safety&quot; furniture.<p>I blame nobody for not wanting to do this, but can we at least self-identify as &quot;will&quot; or &quot;won&#x27;t&quot; and behave accordingly? &#x27;C&#x27; is no bugbear and your favorite interpreter can&#x27;t save you from a bugbear that doesn&#x27;t exist. When problems occur, it&#x27;s because people didn&#x27;t take the fifteen minutes or fifteen seconds to prevent them.<p>I just find myself gobsmacked that people feel so utterly powerless against the language.
Marazan超过 8 年前
C helps you think like a <i>certain 1970&#x27;s abstraction of</i> a computer.<p>I really hate the &quot;C is how a computer really works&quot; argument in favour of learning C.
评论 #12645268 未加载
bryanlarsen超过 8 年前
Do you teach assembly language too? It&#x27;s a lot better at #3 (teaching you to think like a computer) than C is, and it makes it a lot easier to fully grok C concepts like the strange equivalence between pointers and arrays, between character arrays and strings, et cetera.<p>C is trivially easy to learn if you know Assembly Language plus any other imperative language.<p>My school taught assembly language as a full semester course (along with other low level concepts). That and an intro to computers course that used either Pascal or Fortran were requirements for the 200&#x2F;300 level courses on operating systems etc. that used C but didn&#x27;t actually teach it. They made seminars available for those who wanted to be taught C rather than having to learn it themselves. I believe that this is the right approach.<p>Of course, soon after I went through they fell victim to the hype wagon and switched to Java.
评论 #12642803 未加载
AstralStorm超过 8 年前
To an extent, so does C++ help think like the machine, but you can skip a lot of syntactic red tape. Until you get to advanced uses of templates.<p>It is also useful in order to show how those &quot;smart&quot; things in higher level languages work, using standard library as examples.
kensai超过 8 年前
C + Lua == 21st Century &quot;C Programming&quot;<p>There is no silver bullet for everything, obviously, but for me the above combination is a match made in heaven. Lua is small and adds only the necessary tools to take care of higher abstrations in many different paradigms.<p>Even if these two are different languages, they are amazingly complementary. I feel that a good introductory CS course could simply teach in one semester C and the next Lua. By the end of the year students will be able to tackle a huge amount of problems, as well as learned a useful systems and scripting language.
评论 #12652052 未加载
sargun超过 8 年前
So, I quite like C. I don&#x27;t use it very often, but I think that it&#x27;s like a sharp knife.<p>I don&#x27;t quite see the point of C++ though. Can someone explain me why we should continue to bow into it?
评论 #12649909 未加载
评论 #12643045 未加载
评论 #12642777 未加载
评论 #12643128 未加载
drvdevd超过 8 年前
So I dropped out of college long ago and it is actually so ironic and yet also refreshing to me to hear this viewpoint from a college professor. What a beautifully explained rationale for a subject that I find so hard to articulate to my colleages in our echo chamber. I&#x27;ll definitely be pointing to this in the future.
mankash666超过 8 年前
Quick question: would the c loving crowd like an AWS lambda type offering supporting coding in C? You know, to quickly supplement your embedded projects with some intelligence and data processing on the server side, without having to learn a new language or fussing with server infrastructure and scaling
评论 #12648107 未加载
zeveb超过 8 年前
&gt; It is still one of the most commonly used languages outside of the Bay Area web&#x2F;mobile startup echo chamber<p><i>Is</i> C all that commonly used these days? I rather suspect that it&#x27;s an unforced error to start a new project in C, and that many wise organisations are replacing buggy C software with slightly-less-buggy software in safer languages.<p>&gt; C’s influence can be seen in many modern languages<p>True, but … is this actually that important in a learning situation? Knowing Java will help learning Go (or vice-versa) about as much as learning C would, I think.<p>&gt; C helps you think like a computer<p>Like <i>a</i> computer, sure, just not like <i>the</i> computer actually running on one&#x27;s desk or in a data centre. Modern computers really aren&#x27;t anything like the C model.<p>&gt; Most tools for writing software are written in C (or C++)<p>I suppose that&#x27;s true, because lots of people have used C, and that really is a good reason to know enough to get around in it, but … maybe one should teach students to use better tools in better languages (Lisp &amp; SmallTalk come to mind).<p>Seriously, in 2016 it&#x27;s obvious that C is just wrong.
评论 #12645286 未加载
评论 #12644571 未加载
CocoaGeek超过 8 年前
&#x27;C&#x27; stickers do exist: <a href="http:&#x2F;&#x2F;www.unixstickers.com&#x2F;stickers&#x2F;coding_stickers&#x2F;c-programming-language-shaped-sticker" rel="nofollow">http:&#x2F;&#x2F;www.unixstickers.com&#x2F;stickers&#x2F;coding_stickers&#x2F;c-progr...</a> 8)
kabdib超过 8 年前
Is C really this disparaged in Silly Valley?
评论 #12645213 未加载
jorangreef超过 8 年前
&quot;Early in the morning he [Jesus] came again to the temple. All the people came to him, and he sat down and taught them. The scribes and the Pharisees brought a woman who had been caught in adultery, and placing her in the midst they said to him, “Teacher, this woman has been caught in the act of adultery. Now in the Law, Moses commanded us to stone such women. So what do you say?” This they said to test him, that they might have some charge to bring against him. Jesus bent down and wrote with his finger on the ground. And as they continued to ask him, he stood up and said to them, “Let him who is without sin among you be the first to throw a stone at her.” And once more he bent down and wrote on the ground. But when they heard it, they went away one by one, beginning with the older ones, and Jesus was left alone with the woman standing before him. Jesus stood up and said to her, “Woman, where are they? Has no one condemned you?” She said, “No one, Lord.” And Jesus said, “Neither do I condemn you; go, and from now on sin no more.”<p>The Bible is useful certainly not just for historical value, but for making you wise for salvation. The Bible is God&#x27;s master plan for forgiving you, and restoring you to friendship with himself, through Jesus&#x27; suffering, death and resurrection explicitly on your behalf. &quot;Believing&quot; in Jesus is not believing whether he exists, or whether God exists. &quot;Believing&quot; in Jesus means not claiming to be without sin, but rather acknowledging your sin, and trusting Jesus&#x27; work on the cross alone to save you from it.
评论 #12644205 未加载
评论 #12643993 未加载
评论 #12648201 未加载
justinlardinois超过 8 年前
&gt; The <i>most recent</i> edition of the canonical C text (the excitingly named <i>The C Programming Language</i>) was published in 1988; C is so unfashionable that the authors have neglected to update it in light of 30 years of progress in software engineering.<p>This is an odd argument. C has hardly changed or evolved since 1988, so there&#x27;s not really a need for a new edition.
评论 #12642242 未加载