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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Deep C

375 点作者 FrancescoRizzi超过 13 年前

40 条评论

Maro超过 13 年前
While knowing the standards makes you a better programmer, it's still bad programming practice to write non-excplicit, cryptic code.<p>I think the boy's initial "I would never write code like this" response is spot on. I also agree with the boy's implied annoyance and "who cares what this badly written program actually does" stance.<p>These are fairly terrible interview questions. They test knowledge of standards and various obscure behaviour, but it's far more important what kind of code (readable, explicit, maintainable, simple, architected, commented, performant, bug-free, etc.) the person writes. In real life, the boy may actually be a better programmer than the girl. It's just not a good, comprehensive test.<p>Nevertheless the examples are fun, but I would never ask them in an interview. Interview time is precious and not to be wasted on stuff like this, unless you're interviewing for a compiler job...<p>EDIT: Most of the above applies to the first, C part of the interview. In the second, C++ part, the stuff the girl says is mostly basic knowledge that is useful on a daily basis.
评论 #3094244 未加载
评论 #3094014 未加载
评论 #3094105 未加载
评论 #3094403 未加载
评论 #3094933 未加载
wccrawford超过 13 年前
While it's tremendously fun to go through and learn, I question whether she would be a better programmer.<p>For the first half, the boy is making all the right decisions. He's not taking changes and using little compiler tricks to do things. He's not being clever. (For the second half, they appear to deliberately make him stupid. I'm not sure why.)<p>She, on the other hand, has a lot more tools in her toolbox. At the very least, she'll be tempted to use them. And if anyone else is working on the code, they'd better know those tools as well as she does. That's a dangerous situation.<p>Of course, it depends on what they're working on. If they're working with Carmack on his new 3D engine, she's the obvious choice. He would never keep up to Carmack.
评论 #3093928 未加载
评论 #3093545 未加载
评论 #3093607 未加载
Cushman超过 13 年前
This seems like a false dichotomy to me. The "shallow" character seems completely uninformed about the basics of computer science, maybe having worked through a C tutorial or two, while the "deep" character seems to have an encyclopedic knowledge of every C spec and compiler implementation that's ever been written. How many interview candidates really fall into one of those camps?<p>I don't really know C that well -- certainly nothing spec- or compiler-specific -- but I got "deep" answers for most of the questions just because I know that generally C compiles straight to machine instructions, and I know how computers work. (I got 5/5 on the little quiz, and the tutorial on sequence points was completely new to me.)<p>C isn't hard. Thinking like a computer, in any language, is hard. The ability to predict what code will do, while important, is less crucial than the ability to figure out what's really going on when you get one wrong. I feel like calling that ability "deep knowledge" is putting the cart before the horse.<p>To put it another way, "I don't know the answer to that question, but here's a guess" and "I know the answer to that question, here it is" are both less impressive answers than "I don't know the answer, but give me a second and I'll figure it out for you."<p>Or maybe I'm missing the point.
zvrba超过 13 年前
And here's a link to the PDF: <a href="http://www.pvv.org/~oma/DeepC_slides_oct2011.pdf" rel="nofollow">http://www.pvv.org/~oma/DeepC_slides_oct2011.pdf</a><p>I hate slideshare requiring registration or facebook login before it allows me to download it in some decent format.
评论 #3093955 未加载
评论 #3093580 未加载
评论 #3093614 未加载
macavity23超过 13 年前
I think this slideshow would be better titled 'Standards Compliant C'.<p>At least for the first printf example, I would employ the boy rather than the girl. The boy gave a correct answer - what was missing, what would happen. The girl spouted a bunch of standards that added no value (with the exception of the 'return 3' which does indeed demonstrate deep knowledge).<p>In particular, the 'you should add a blank line at the end of your code' comment would immediately make me suspect her to be a finicky letter-of-the-law PITA who would be a nightmare to work with.<p>Standards are all well and good, but if your code compiles with no warnings and runs without errors according to the spec you were given, nobody of any consequence is going to give a damn.
评论 #3093939 未加载
评论 #3093694 未加载
评论 #3093759 未加载
wisty超过 13 年前
It's not a commentary on interview questions. It's a tutorial on C language rules, with a silly little story to make it more interesting.<p>What <i>everyone</i> is missing is how interesting the tutorial is, despite it being about a really dreary topic. I'm reading a book called "Why Don't Students Like School", which goes into some detail about this kind of thing. It's quite good (and really should be, given that it's about how to make education interesting).
评论 #3095531 未加载
zwieback超过 13 年前
Not sure why there are so many negative comments, the exact detail of the questions and answers aren't as important as the overall message and the guy and girl are archetypes.<p>We're interviewing some candidates for embedded C programming right now and these are the types of questions (although generally easier) I ask to find out the level of C expertise. For embedded systems with a focus on stability I want candidates who have a very good grasp of the fundamentals like the difference between normal globals, statics, volatile, etc. Also I'd like people who understand enough about the linker to know about data segments, zero init and stuff like that. For embedded you generally have to be able to implement interrupt handlers so the exact translation of a line of C code to assembly is important, as is knowing what's atomic and what isn't.<p>I'm continually surprised how many programmers have worked on embedded systems in C without being able to answer almost any of my questions. Many seem exactly like the guy in the examples, none like the girl.
评论 #3094768 未加载
forgotAgain超过 13 年前
Unless I asked for more information I would have been turned off by the girl because she was pedantic. The last thing a team needs is someone who gives a never ending answer to a simple question. If I prodded for more and she delivered it and the guy didn't then she wins hands down. Otherwise I want a simple answer to a simple question and move on to the next thing.<p>Edit: I only went through the first twenty or so slides. After disagreeing with the initial premise I didn't think the author earned any more of my time.
jrockway超过 13 年前
This is important for two reasons:<p>The first is to remedy the misconception that "C is a really simple language". It's not.<p>The second is because while you'll never write any code like this, you'll probably have to debug code written by someone who did. That means that in order to use your time efficiently, you need to know what matters and what doesn't. Writing a regex to replace all "static int foo" with "static int foo = 0" is going to waste your time and not expose the cause of the bug. If you didn't know that, your time would be wasted.
评论 #3096755 未加载
Jun8超过 13 年前
The title reminded me of <i>Expert C Programming: Deep C Secrets</i> bu Peter van der Linden. If you don't have this book buy it today. It's one of the best C books I've read and AFAIK the only book that combines C and humor! His description of how to make Oobleck is alone worth the price (for those who are curious, it's a non-Newtonian fluid, <a href="http://en.wikipedia.org/wiki/Non-newtonian_fluid#Oobleck" rel="nofollow">http://en.wikipedia.org/wiki/Non-newtonian_fluid#Oobleck</a>, and also a Dr. Seuss character).<p>(OK, if you don't want to buy the book, here are the directions: <a href="http://books.google.com/books?id=4vm2xK3yn34C&#38;pg=PA347&#38;lpg=PA347&#38;dq=van+der+linden+oobleck&#38;source=bl&#38;ots=Ho49SfVMbY&#38;sig=eLAcykZEqg-241ONcsKzTFzsjkk&#38;hl=en&#38;ei=0BCTTtC7M6fLsQLckPibAQ&#38;sa=X&#38;oi=book_result&#38;ct=result&#38;resnum=1&#38;ved=0CBoQ6AEwAA#v=onepage&#38;q&#38;f=false" rel="nofollow">http://books.google.com/books?id=4vm2xK3yn34C&#38;pg=PA347&#...</a>)
评论 #3094698 未加载
ak217超过 13 年前
<i>Would it be useful if most of your colleagues have a deep understanding of the programming language they are using?</i><p>Not if by "deep understanding" he means "knowing trivia about underspecified corners of the language that have nothing to do with getting the job done".
评论 #3095532 未加载
pacala超过 13 年前
<p><pre><code> static int a; ++a; </code></pre> I don't care what the standards say, please just type the initialization value you need. It's inconsistent to pick a special case, 0, out of 4,294,967,296 possible values, and type something different in the special case.
评论 #3095263 未加载
评论 #3094843 未加载
haberman超过 13 年前
I don't think it's super-important to know eg. what value an uninitialized static variable will have. If you use it, you should initialize it explicitly, end of story. If you write code that counts on such detailed minutiae of the standard, you make your code harder to read for no good reason.
评论 #3096155 未加载
pwaring超过 13 年前
I'm a bit surprised by the suggestion that optimisation somehow makes the compiler work harder (e.g. catching uninitialised variables), isn't that what -W flags are for? I'm not sure that optimiser flags will catch anything with gcc that -Wall and -Wextra would miss.
评论 #3094504 未加载
评论 #3094420 未加载
snorkel超过 13 年前
It's articles such as this that scare developers away from C. You honestly do not have to mind meld with the C compiler to be a safe and productive C developer. If you're not sure what's going to happen if you don't initialize a variable then that's OK, because most developers realize that being explicit is better than allowing the implicit case to occur in every language.
评论 #3094726 未加载
monochromatic超过 13 年前
Didn't get very deep into this slide deck, but I did notice that both of those candidates neglected to complain about using smart-quotes in source code. Sloppy, wouldn't hire either.
评论 #3095541 未加载
评论 #3094814 未加载
评论 #3095458 未加载
kabdib超过 13 年前
Some of the stuff /she/ talks about seem to be "how a badly written program might behave." This is utterly uninteresting.<p>Q: "What does this buggy program print."<p>A: (hits first person with a stick)<p>"Right!"
评论 #3096547 未加载
评论 #3097445 未加载
polarist超过 13 年前
I took something different to many of the comments here. I found the most important takeaway was hidden in the later part of the slideshow, and referred to the difference in the attitudes and approaches to learning for two. Clearly the girl understood that in coding, there's usually a correct way to do things, and was always in search of that answer.<p>That correctness has varying levels of importance depending on the industry/application, but for a sufficiently large and complex project, the benefits to writing correct code is extremely valuable.<p>For instance, if it were a team environment and I had to write some functionality using the code supplied by the girl, I could simply assume standard conventions and immediately attempt to use her classes in my code. If written correctly, that code might work without further effort my on end.<p>If the code were supplied by the guy, I would likely have to go in to the implementation and ensure that the behavior conformed my expectations. And having to go through and read the code could require a significant time investment.<p>And of course, reading code often takes significantly (10x++) more time than writing it, so minimizing the necessity for it is essential in maximizing productivity. I would suspect that in most programming teams that reading other people's code is what eats up the most time, yet this time can be significantly reduced by following such a standard.<p>When the slideshow begins to refer to C++ conventions and the "rule of three," the guy shows that he doesn't take into account that others may need to work with his code. This can be dangerous as this single new team member can actually cause the total productivity of the team to <i>decrease</i>.<p>While this guy is just a made-up character, I wouldn't be surprised if most programmers think/act like him. At the very least, the majority of the ones that I've worked with, do.<p>On another note, the minutia details of C do come up if you work with and read enough source code. Being able to understand it is the more important issue at hand. Also, in response to many comments stating that writing code that works based on such minutia is poor practice, I think the girl would likely agree.
ipsin超过 13 年前
I really appreciated the slides, and they have a direct impact on my current C++ side project. I breezed through the bits that were not about C or C++, but here's what I took away:<p>1) Add "-Wall -Wextra -Weffc++" and fix the problems found 2) Have some insights into the various C/C99/C++ language contracts, including what sequence points are, how data is packed, and how expressions are evaluated. 3) Learn when to use delete or delete[], when to declare a destructor virtual.<p>If anything in this summary piques your interest, you may want to check out the full presentation.
andrewcooke超过 13 年前
this is great, but also embarrassing. not only am i a worse c programmer than i thought (i thought i was pretty good), but i burnt lunch because i forgot what was on the stove while reading it :o)
grout超过 13 年前
C is an incredibly sharp industrial-strength tool. There is absolutely nothing about C that can't trip you up and break your program if you don't know it by heart. But if you <i>do</i> know it by heart, forwards and backwards, it has no equal.<p>Or, if you prefer: It is a crazy girlfriend: serving your whim one second, burning your clothes the next. Pay it close attention or be ready to buy a new wardrobe regularly.
评论 #3097292 未加载
mace超过 13 年前
This is brilliant. It contains simple and direct explanations of C's (and C-based languages) rough edges that many programmers encountered or been bitten by but few have taken the time and effort understand.<p>I appreciate the presentation style too. The characters clearly represent the difference between deep understanding and casual knowledge of the subject. Good stuff.
akmiller超过 13 年前
These slides makes it look like you have to be one type or the other. I'd suggest that the boy is an excellent candidate for the job and that you could help provide him the lower level understanding that you would like your programmers to have.<p>The key to me is how the candidates gain the understanding of whatever languages they use. Meaning, is programming something that they really enjoy and are learning on their own time and solving some of their own problems. Or, are they simply picking up programming to try to get a better paying career (aka the types of people that are often drawn to those 6 week learn to program type of schools). Therefore, for me and the interviews I have done in the past asking candidates about books they've read or programs they've worked on (for themselves or others outside of their employment) are often times much more enlightening.
robot超过 13 年前
Ironically, the examples provided for illustrating your 'deep C' knowledge, are in fact superficial.<p>I don't really care if &#60;stdio.h&#62; has a printf definition, or whether C99 behaves differently. You might care more if you are an app programmer.<p>What I care about is the universal properties of the language that applies everywhere. Also that's where the strength of C comes out. For example, what is a function? What does it compile into? Why are there arguments, return values? How do they get represented? These are far more important questions than how C99 dictates entering the program from int main(). That's least of my worries. Programs I write usually enter a C program from _start
oscardelben超过 13 年前
I really enjoy this presentation. If you want to learn C programming from scratch I also recommend to study Zed's book "Learn C the hard way".<p><a href="http://c.learncodethehardway.org/book/" rel="nofollow">http://c.learncodethehardway.org/book/</a>
tjpp超过 13 年前
Someone mentioned Expert C Programming: Deep C Secrets as a good book to learn the C standards. Are there any other books that or resources one would recommend to learn this sort of material?
评论 #3094705 未加载
评论 #3095144 未加载
botj超过 13 年前
Thanks! I needed a reminder why I hate C so much.<p>You must be a language lawyer in order to do anything moderately complex and then be met with "the standard doesn't say anything about that!" when you realized the standard library doesn't include the most basic of things (yeah comp.lang.c, I'm looking at you...).<p>Yeah, I know. C++0x will be the grand unifying standard to rule them all...sure.
burgerbrain超过 13 年前
Is this articles note about needing to place a newline at the end of a standards compliant C program actually accurate?<p>When I write out a file containing "aaaaa" with nano (to avoid any unusual tricks vim might use), and then hexdump it, I get "6161 6161 0a61". In other words, nano slapped on an ending newline when I saved. It is my impression that everything does this.
评论 #3095257 未加载
sehugg超过 13 年前
"Well, whatever. Lousy compilers." I feel ya bro.
toksaitov超过 13 年前
I recommend students to take OS development course at university. Many concepts of C are discussed and viewed in practice in this class: the relation of the static storage class in C and the .bss section of the object/executable file, the stack and calling conventions of different processor architectures, and so on.
dblock超过 13 年前
Let me brag first: I could be that girl in the interview. Yay me. But am I the only one to think these are obsolete skills? Isn't there more to software than knowing C++ at this level? Would I want to spend 10 years on learning it as well as I know it now, today in 2011?
评论 #3096481 未加载
cefarix超过 13 年前
This is the most mind-tickling thing I have seen/read/watched in a long while! I am going through all the slides and now I know how to interview other coders. Thanks for sharing this!
Ideka超过 13 年前
Slide 231:<p>Q: <i>So why doesn't the compiler reorder the members in the structure to optimize memory usage, and execution speed?</i><p>A: <i>Some languages actually do that, but C and C++ don't.</i><p>And that's because...?
评论 #3094967 未加载
sktrdie超过 13 年前
I love how a simple slideshow made out of cartoon characters got me knowing about the C and C++ standards more than a written reference ever did.
0x12超过 13 年前
Long time C coder here. Knowing this stuff just shows you've had more interaction with your C compiler(s) than with humans, which is fine (I knew quite a few of the details except for some of the C++ differences because, well, I code C, not C++).<p>That said, <i>relying</i> on obscure stuff is where the problem lies. Long time C hackers almost always agree on one thing (if maintainable code is their goal and they're not engaging in some silly contest on how to squeeze a certain program into a ridiculous number of bytes or on how to write a program that you can't understand on purpuse): If you want your code to be maintainable in the long run try to be as transparent as possible about what the code does, don't rely on obscure or implementation dependent features.<p>So the 'girl' probably has huge experience, but the 'boy's answer is equally valid from a novice's point of view, because it (probably) gets the job done with a minimum of fuss (at least wrt to the initial set of questions). At some point he'll have to expand his knowledge.<p>If you had to sit through an exposition like that for every silly simple question the days wouldn't be long enough to get any work done. Literal answers like the girl gives are rarely productive, but it is good to have the knowledge that allows you to give those answers. It isn't a must for every position though, and even 'lesser' programmers have to learn somewhere (but when you're hiring you want to hire the best you can at the right price).<p>Oh, and please, do initialize your local variables before first use ;) Even if you are compiling with the debug options on, not initializing your locals before first use is a really bad idea, no matter how much you know about your compiler.<p>Later on in the series the differences get more interesting, keep clicking :)<p>What is probably frightening off many people from C is that there is a lot of arcane knowledge that the 'girl' is exposing that can actually be helpful during the debugging stage of writing a program, and that there isn't really a manual that you can read that will tell you all that stuff.<p>The only way that I know to come by it is to write code for many years and to run into those issues. I've had a couple of all-night debugging sessions that are still pretty vivid after many years and it is interesting that those bugs taught me lots about how compilers optimize, possibly more than I learned from reading books on the subject.<p>C bugs can be pretty subtle. The 'girls' knowledge can be helpful while doing hardcore stuff.<p>Given the choice between the two candidates I'd probably pick the girl (assuming she wants the same salary, which is very unlikely) and put a daily time limit on exposition ;), the 'boy' simply doesn't have that much experience yet.<p>Oh, and you can declare your 'main' fuction to be int main(void) all you want, argc and argv and envp will still be passed to it.<p>Keeping your globals 'static' in the file they are declared in (instead of (gasp!) having a bunch of globals that are declared 'extern', try to avoid that if you can) is good practice.<p>And so on. In short, there is a lot to know about any programming language, you can use questions like these to gage experience levels, don't rely on obscure stuff, explicit is better than implicit, don't expose more than you have to and so on.
DannoHung超过 13 年前
Why does C allow so much bullshit to work?
评论 #3097046 未加载
testz3453超过 13 年前
Slides don't work in Opera web browser after 54 page. In Chrome they work.
评论 #3094731 未加载
评论 #3096872 未加载
bandushrew超过 13 年前
That was a brilliant read, thanks.<p>where can I find more discussions like that?
loup-vaillant超过 13 年前
1) The girl sounds so much like Hermione that I don't want to be her.<p>2) I hate C++.<p>3) Oh, crap, I already knew 98,5% of all this (thanks to the C++ FQA in part, but still). I guess I'm a language lawyer now…
评论 #3099918 未加载
billpg超过 13 年前
Takes me back to my days reading comp.lang.c.