6 ms·
The Hardest Test I Ever Gave (C++)
- rmserror 14y agoThis is crap. 1e: this is undefined behavior (-Wsequence-point) x can be literally anything. 3. a typical mistake that the compiler both warns about and that anyone who has taken a course on C should be able to immediately recognize bonus 1. void main(int)???
- DerekL 14y agoQuestion 1 asks about syntax. The behavior of the code is irrelevant.
- TwoBit 14y agoExcept for the the fact that the author writes: "for bonus points, if x is 1 before 1e, what is x after that line?"
- epidemian 14y agoThen wouldn't an answer like "x could be anything because of undefined behavior" be correct? This test is indeed quite evil, especially considering it was for freshman students. I have to admit, though, that the bonus question was great.
- adamnemecek 14y agoOh, you came up with a shitty test (testing I'm not even sure what) to stroke your ego while probably turning some kids away from programming? And then you thought that a recollection of this experience was worth sharing with the world? I sarcastically applaud your efforts. But seriously you are a douche.
- 10098 14y agoIf the object of the course is to study C++, I say this is a good test, and it's not even that hard tbh.
- adamnemecek 14y agoI did not say it was. But it's a shitty test regardless.
- 10098 14y agoAgain, it depends on what those kids were supposed to study. If it's a general programming/algorithms class then yes this is testing the wrong knowledge. If it's a C++ specific class, this is completely justified. How does one come out of a C++ class and not know this stuff?
- adamnemecek 14y agoIt was "an intro to programming course for incoming engineering freshman". Also I write C++ for living and I was not entirely sure if "y = x++3;" was valid or not (turns out it is an error but "y = x+ +3;" is fine, which I would have guessed but would not have been quite certain). Edit: Now that I think about, I believe that "x = (x++ == 3 + x % (x=x=3));" is undefined behavior. I guess the question is not asking about that but regardless, that's a stupid thing to ask.
- tolmasky 14y agoIf you set aside the fact that the deeper issue is probably that C++ in general is a bad intro language to begin with, then its not completely unreasonable to test on this syntactic stuff, especially as you go farther back when compilers/checkers were less friendly. For better or worse, one of the lessons of programming is the unforgiving nature of the computer to do exactly what you typed in, and not what you meant. I remember having a similar test or quiz to this when I was in high school (~12 years ago or so). Its not that big of a deal, the whole class is not just that, its just to kind of drill this into your head. We were using pretty terrible Borland compilers with rubbish error messages. At that particular point, being able to stare at code and determine what minor thing you mistyped was unfortunately a crucial skill. Again, this is arguably less important today (and arguably all written tests are bad for CS). Later in college, I remember hating the assembly tests where you had to keep track of what numbers were in what address, and whether you were adding what was on the stack or in some register or the address or what was in the address and making a mistake in the very beginning could ruin the whole problem. Not fun, not sure how useful, but certainly gave you an appreciation of what was going on.
- nhaehnle 14y agoIn fairness, the author does recognize that he failed in giving a good test. The thing is, those questions demonstrate a certain type of playfulness in dealing with the subject. It is not uncommon for good students to think of this type of questions when they design their first tests, precisely because those are the kinds of questions that they like to think about themselves. What they fail to recognize is that those questions are incredibly hard for others precisely because of their playfulness. So those questions are useful for quickly recognizing really good students (students that are so good that they transcend the requirements of the course and can deal with the subject on this playful level), but they should only make up a very small portion of any test. And teachers should probably warn their students about this type of question...
- chris_wot 14y agoNot really. To be honest, if anything it's good training. How many times have you seen an assignment operator in an if statement where a comparison operator was meant to be used? Actually, now I think of it... all the questions were related to operators, except the last one which was a trick question. If all the questions bar one were in regards to operators only, then this isn't a particularly good test.
- shin_lao 14y agoI disagree. Question#5 and bonus Question#1 are good questions. Production bugs are often close to these. It tests if a student is able to follow a program's logic with rigor. It tests if you don't interpret the code but actually read it "as is". Question#1 and Question#2 are less intelligent. Also, no template test? Are you testing C with classes or C++ ? ;)
- daemin 14y agoI found Question #1 to be bad, #2 is alright but coming close to just a 'trick' question. #5 is just a simple trick question, and I can see where people went wrong with it. Especially if they skimmed over the code, and in a high pressure test environment. The bonus question is reasonable and can be worked through, if it wasn't printing the string literals, which makes it just a mean trick question. I think that's the problem with a lot of first time test (or interview) makers, they make their questions into trick/puzzle questions where they want the test taker to guess what the writer had in their mind. --edited because I skimmed over the last question and assumed it was printing the values of the variables not the strings--
- _pmf_ 14y agoI'm truly sorry that learning a real language takes some more effort than Ruby-loving ADHD rockstar developers can muster.
- antihero 14y agoScrew that, I loved it when we'd get a "bonus test" that was actually really difficult.
- leoh 14y agoMeh. I thought this was pretty easy. Where are the solutions?
- 10098 14y agoYou can use a compiler to find the solutions. Except maybe for 1e bonus part, the output won't tell you much in that case.
- benihana 14y agoCan I ask what the point of this comment is? Obviously one can use a compiler to find the solutions. OP was most likely asking because he didn't want to do that.
- 10098 14y agoWhat, he was too lazy to copypaste those into codepad and click a button? Okay, I guess.
- leoh 14y agoI think being on a mobile device is a decent excuse ;-)
- chris_wot 14y agoNot only that, but you can set an assignment operator to x for 1e, then print the result to the screen. Hardly the point of the test. Though not sure the point of the test...
- jre 14y agoThis reminds me about an undergrad C course I had. One test was about printf formatting. We were given a serie of crazy format strings (using format specifier I've never encountered again since) and had to know what it would output. This was the most stupid test I've ever had. There was a similar one about pointers. We called it "Star Wars".
- gregorkas 14y agohttp://xkcd.com/138/ http://xkcd.com/138/
- chris_wot 14y agoA test about pointers is not stupid. A test about printf formatters is.
- _pmf_ 14y ago> A test about pointers is not stupid. A test about printf formatters is. Obviously you did not have the joy of working with people who write their own byzantine 1k LoC formatting code for cases that would have been perfectly covered by printf (and yes, this was on a system where a printf implementation was available).
- ankitml 14y agoYou are cruel!!
- tommys 14y agoNonsense test.
- rorrr 14y agoWithout a compiler, or google, haven't touched C++ in years: 1a) will give an error 2a) 2 2b) -10 2c) 4 2d) This is clever, haha. Answer: 5 2e) true (or 1) 5) "This is the answer." because of if (y = z) Bonus) jk
- raverbashing 14y ago1a) not so sure, because it could be x+(+3) But yeah, gcc throws an error If you put the parenthesis it works
- chris_wot 14y agoHe didn't put it into parenthesis.
- raverbashing 14y agoI know that, I'm using parenthesis to explain what the compiler "might think"
- chris_wot 14y agoNo decent compiler would attempt to correct that by adding parenthesis!
- rorrr 14y agoIt's not about a parenthesis. It's about the compiler not understanding all valid possibilities. x+ +3 works. x++3 doesn't.
- chris_wot 14y agoOK, I take it back. That's logical. Technically speaking though, the compiler could see it as x+ +3, but it could equally see it as x ++3, which has two compiler errors: firstly, that's not actually a valid expression, and secondly (at least as I checked in the C99 standard, under section 6.5.3.1 on postfix increment and decrement operators) the lvalue must be modifiable. All I guess I'm saying here is that it could technically be a typo which leads to invalid syntax, or it could be technically correct, so most compilers will treat it as a syntax error. Someone above said that gcc was being "closer to the standard", but the standard never attempts to cover this particular corner case. So the gcc devs have done something, to my mind, quite sensible. They treat it as a possible syntax error because it could either be: x+ +3; x++ 3; x ++3; I'm more interested in how it handles x+++x; - I'd imagine that it's a syntax error. It could be: x++ + x; x + ++x; x+ + +x; The C99 standard doesn't actually explain how to handle this. Perhaps they believe you shouldn't be so daft. I'll stand by original statement that it's a syntax error and most good compilers will treat it as such, even if it is logical to treat x++3 as x+ +3. Edit: scratch that ALL completely. I forgot about operator precedence. If you take x++3, then suffix increment is a higher operator than suffix decrement and addition. In other words, the compiler will always try to evaluate the expression as x++ 3; In other words, it's a syntax error. It can never evaluate to x + +3, because that's at a lower operator precedence. Thus, it's a syntax error. Take that, downvoter of my original comment. Edit x2: Definitive answer is here: https://news.ycombinator.com/item?id=5200523 https://news.ycombinator.com/item?id=5200523 Some days it just doesn't pay to get out of bed... :-)
- beambot 14y agoPerfect reminder of why I don't use C / C++ anymore. I had a teacher (highschool, IIRC) who made similar exams... He had the gall to call his course "computer science." I called it a waste of time, effort, and brainpower. I hate to think about how many computer-loving students he ruined. OP, you did your students a disservice. You should've just assigned a "practicum" exam instead.
- bnegreve 14y ago1. There is no such a thing as C / C++. "Real" C++ is closer to other OO languages than it is from C. 2. It is not because a language is not a good option for teaching that it isn't worth using. BTW After hours of debate, I still think that C is not a bad option for teaching purposes, mainly because it has a very simple syntax and almost NO api which generally introduce confusion.
- beambot 14y ago1. I learned the two languages contemporaneously. They were commonly referred to as C / C++. I used C mostly for embedded/systems programming. I don't know what "real" C++ means... but to be fair, the last time I really used it was pre-STL. 2. OK. (I didn't make that claim, did I?) C / C++ has it's uses. I use it when I have to (embedded systems, systems programming, and performance). But I don't use it willingly. I TA'd a course in C for EE's. It was fine. I think it probably helped them in many ways. Anecdote: My favorite course as an undergrad was building our own wire-wrapped 8086 computer. You quickly learn to appreciate assembly (versus manually loading registers), and then quickly learn to appreciate the C compiler.
- pimentel 14y agoI learned programming in C. I really think it is important to learn all the data structures internal functioning (coding your own linked lists or hash-tables), learning how memory in a program really works, what is the difference between a 4 byte-type variable versus a 1 byte one, etc
- olalonde 14y agoI would probably have assumed that "question #5" and "Bonus Question #1" had typos and failed those questions. if (y = z) and cout << 'j' << 'k';
- raverbashing 14y ago(a = b) inside an if (inside a test) is never a typo!! That get me to think "this is the evillest thing I can imagine" =)
- nhaehnle 14y agoYou should always either ask to clarify or, if that is not possible, go with the literal statement of the question, and explicitly say so on your test paper. Any professor worth his/her salt will accept that and think even more highly of you, because they will recognize that you are able to think about the question on a higher level than most students. If, on the other hand, you just silently "correct" the question in your mind, you will fail - especially in a course on programming, because the point is exactly that you have to learn to deal with computers that do not silently "correct" the program that you give them.
- Toenex 14y agoThese are great tests... for a compiler.
- deleted 14y ago[deleted]
- Sharlin 14y ago1c is cruel. One can hardly expect freshmen to understand the difference between a syntax error and a semantic error. Depending on the context, the line may be perfectly valid, or it may not.
- chris_wot 14y agoNot a single question about templates. Your test was not hard enough.
- friendly_chap 14y agoYou are one of the reasons why education sucks in general.
- aroman 14y agoJust so everyone's clear, I am not the author of this blog post. I had replaced the I in the title with [He], but a. Mod must have annoyingly edited it out. I hope people realize that.