News for hackers. Stuff that matters.
Re:How to win the coding interview by fenomas on Tuesday May 31, 2016 @12:13AM (#11804519)
Couldn't help but chuckle at this:

    'use strict'; // avoid ambiguity and sloppy errors
If the line that starts (or ought to start) virtually every JS file you ever write can't stand without explanation, one wonders what can!
Re:How to win the coding interview by twblalock on Tuesday May 31, 2016 @12:20AM (#11804544)
n++; // increment n
Re:How to win the coding interview by hvidgaard on Tuesday May 31, 2016 @02:36AM (#11805048)
I've had students that did this. It's a real pain to read code like that, and the 2nd time they handed it in, it was an automatic fail. Comments explain assumptions, and often "the why", never "the what" unless it's obscure because of optimizations.
Re:How to win the coding interview by BinaryIdiot on Tuesday May 31, 2016 @04:28AM (#11805403)
> It's a real pain to read code like that, and the 2nd time they handed it in, it was an automatic fail

That seems incredibly heavy handed and not helpful in the learning process. I was a professor's aid for several programming courses and many students simply made comments like that constantly because it helped them drill it into their head what it did. It's a little annoying but it doesn't hurt the readability.

Automatically failing them on a second turn-in seems very anti-student and anti-learning to me. Teaching through negative reinforcement is the worst way to teach.

Re:How to win the coding interview by kagamine on Tuesday May 31, 2016 @06:43AM (#11805775)
I felt when I was a student that some teachers just wanted everyone to know how clever they were and sometimes that could be achieved by putting someone else down. Someone who wasn't in a position to talk back. The good teachers gave criticism, pointed to the code standards for the course and were fair in their marking. The best teachers asked questions that made the students produce better work and took time to explain and discuss. They all knew which category they were in.
Re:How to win the coding interview by hvidgaard on Tuesday May 31, 2016 @08:17AM (#11806083)
You can see my reply to the parent comment. I always sit down and talk with the students, but for us to talk about the code, we need to be able to read the code. Unneeded comments make it significantly harder to read code.

First time we talk about why I don't want "the what" comments, only "the why" comments. If they still do it in the next handin it's a fail unless they've explicitly provided me with a reasonable reason to do it.

Re:How to win the coding interview by tamana on Tuesday May 31, 2016 @11:00AM (#11806885)
In science, there is no such thing as why, there are only deeper levels of what. And those levels are subjective and relative to personal experience.

Your comment merits a failing mark, downvotes, because you made the same subjectively wrong statement twice.

Re:How to win the coding interview by hvidgaard on Wednesday June 01, 2016 @02:32AM (#11812438)
Programming is not a science. "Pad to multiple of 256 otherwise libX will fail" is exactly what a comment is for, and it is the "why", no the "what" - the what is already readable in the code.
Re:How to win the coding interview by crispyambulance on Tuesday May 31, 2016 @09:48AM (#11806462)
I think folks are getting hung up on nitpicking the comments. I never heard of anyone getting rejected strictly because of a stray unnecessary comment in a code test for hiring.

Any interviewee is going to make assumptions about what the interviewer wants. Some of these assumptions will be wrong and some will not be worth the time to ask about (like commenting style). If the interviewee solved the problem and/or displayed a desirable level of competence that's good enough. Interviewers do the coding exercise merely to screen out people that have grossly misrepresented their skills.

On the internet folks like to imagine they're in a position to "immediately reject" a job applicant because of a single "red-flag" that indicates some profound shortcoming. This is rarely the case.

Re:How to win the coding interview by hvidgaard on Tuesday May 31, 2016 @08:10AM (#11806063)
I sit down with them individually and talk about the handin. For any meaningful feedback to happen, we need to see the code. This is not programming 101, but courses that require you to have passed advanced programming, so I expect them to hand in without comments like this:

   i++ //increment variable because used clicked
It's harmful for readability and takes a lot longer to read. If they hand me a second handin with such comments, after our first session, I'm not going to tell them again.
Re:How to win the coding interview by vkjv on Tuesday May 31, 2016 @09:42AM (#11806433)
While I might not agree with the GP that this should be an automatic failure, I do think it is very important to emphasize to students that when the code is working, they are not done. They still need to go back, re-format, clean things up, and possibly add tests.

Working is the lowest bar of quality.

Re:How to win the coding interview by MustardTiger on Tuesday May 31, 2016 @10:36AM (#11806737)
> It's a little annoying but it doesn't hurt the readability.

I find it absolutely destroys readability. It is incredibly hard to follow code written twice.

Re:How to win the coding interview by rickdale on Tuesday May 31, 2016 @10:37AM (#11806741)
I agree with the other commenters that say thats a bit harsh to completely fail them. I was in my third CS class in college and I left out a semi colon on a test and my teacher said, none of the code would work from here, so the answer is just 100% wrong. Even though the rest was 100% correct. I made the argument that if I was sitting at a computer, that would have been less than a 5 second mistake, or something I would have noticed in the syntax highlight, but he insisted it was a complete fail. I never understood that, but I think it relates back to the days when the professor learned on punch cards and one small error was more costly than today.

Another thing is, when I was learning to program, commenting was something I used to keep things light. Sometimes inside jokes or random bits of code that were terrible that would make me laugh once I had the final solution. In my opinion, unless the assignment was designed to teach proper comments, why not let students be creative with their comments, even if its redundant to you.

Re:How to win the coding interview by hvidgaard on Wednesday June 01, 2016 @05:32PM (#11818362)
Failing for missing semi colon seems harsh, but in reality, when students are told to run their code before handing it in, a missing semi colon tells you exactly that the students didn't run the code. If a student fails to meet simple basic requirements, they cannot expect some leeway.

That said, in a test when hand writing code it should only be pseudo code. Expecting learners to write syntax correct code by hand is stupid.

    > why not let students be creative with their comments, even if its redundant to you.
Because I have to read every comment, decide if it's relevant or not, and delete it if it isn't. "End of line comments" on every single line is not helping anyone - "using for loop to iterate over the array" is bloody useless, because it's right there in the code. Keep in mind this is CS students at least 2 years in.
Re:How to win the coding interview by rickdale on Wednesday June 01, 2016 @08:03PM (#11819347)
Keep in mind this is CS students at least 2 years in.

I wasn't keeping that in mind. Thats makes a lot of difference. Pretty sure I studied under the same rules.

Re:How to win the coding interview by hvidgaard on Thursday June 02, 2016 @02:22AM (#11820717)
I wasn't exactly clear on that, to be fair.
Re:How to win the coding interview by vsl on Wednesday June 01, 2016 @02:52AM (#11812509)
Because he's trying to teach them how to write good, readable, maintainable code.
Re:How to win the coding interview by di4na on Tuesday May 31, 2016 @05:16AM (#11805550)
As someone that was a student until last year, the real hard problem is that we have teachers that want this type of comments. Having different standards for different teachers the same day is a lot of context switching...

A better idea would be to get a standard code style for all course...

Re:How to win the coding interview by ogsharkman on Tuesday May 31, 2016 @08:50AM (#11806220)
My school actually had standard coding styles for each language they taught. Naturally, they all wanted a metric fuckton of comments (luckily the TAs didn't care as much about the comments part of those guides).
Re:How to win the coding interview by heartbreak on Tuesday May 31, 2016 @11:03AM (#11806896)
Particularly with beginners, I think there's a lot of "What were they thinking when they wrote this??" going on when a professor or TA reads code that is completely unintuitive (Take a look at /r/learnprogramming for some examples). Having comments everywhere makes it easy to say, "Oh! S/he was trying to reset all of the variables in the program by calling main(null); (actual example from the subreddit). How would you ever know that without a comment explaining why main(null); is called in the middle of a class?
Re:How to win the coding interview by scrabble on Tuesday May 31, 2016 @07:25AM (#11805894)
I have had a teacher that said you needed to comment every single line because that's how code is written in the real world.

I told him he was wrong and argued with him on more than one occasion. In the end, I just did it his way because there wasn't a good alternative.

Re:How to win the coding interview by pklausler on Tuesday May 31, 2016 @12:36PM (#11807574)
> In the end, I just did it his way because there wasn't a good alternative.

Ironically, that is quite a bit like the real world.

Re:How to win the coding interview by jfoutz on Tuesday May 31, 2016 @10:01AM (#11806530)
Sounds like a job for a perl(or whatever) script.

Might be fun to do some light ad hoc parsing.

Also, with that rule, I can't resist

    // this line left intentionally blank.
Re:How to win the coding interview by kevhito on Tuesday May 31, 2016 @11:01AM (#11806887)
Ahem:

    // this line left intentionally non-blank.
Re:How to win the coding interview by dagw on Tuesday May 31, 2016 @06:51AM (#11805798)
Did you sit down with student and try to understand why they wrote comments like that, explain exactly why comments like that where bad and try to show them a better way, or did you just fail them and hope they'll work out all those things by themselves?
Re:How to win the coding interview by hvidgaard on Tuesday May 31, 2016 @08:11AM (#11806065)
Always after the first such handin. The second, not so much.
Re:How to win the coding interview by kriro on Tuesday May 31, 2016 @10:21AM (#11806655)
Why not run a parser that removes all comments over all code that is turned in. It's easier to read the code with no comments and if there are no comments the sections that should be commented really pop out (you can then check to see if there are indeed comments in the original file).

Simplistic comments actually help a lot when learning (even if they are just a reinforcement). Quite often our students write the comments first and then fill in the code which is perfectly fine.

It's also more interesting to let them freeflow it and then explain later why it might not be a good idea. The learning effect is stronger if they can go back and read their own overcommented code.

Re:How to win the coding interview by heartbreak on Tuesday May 31, 2016 @11:04AM (#11806906)
Sometimes the comments are valuable, even when every line is commented. A syntax highlighter scheme that had lower contrast for the comments would be a better workaround.
Re:How to win the coding interview by fao_ on Tuesday May 31, 2016 @06:56AM (#11805810)
For my course it is part of the criteria. They want every single line commented.

It's a nightmare of irritation.

Re:How to win the coding interview by Merad on Tuesday May 31, 2016 @07:18AM (#11805875)
Having been a TA for CS1 classes, I can understand the rationale behind it to some degree. It's ridiculous how many students go online and ask for someone to do their homework or even copy chunks of code off of stack overflow. Forcing them to explain every line is one way of judging how well they actually understand what they're writing (if they do at all). Of course it's going to be annoying to anyone who already has the slightest experience... but what can you do?
Re:How to win the coding interview by mathgeek on Tuesday May 31, 2016 @08:38AM (#11806170)
> It's ridiculous how many students go online and... copy chunks of code off of stack overflow.

You could easily replace "students" with "coders" and that statement is still true. Just an observation.

Re:How to win the coding interview by hvidgaard on Tuesday May 31, 2016 @08:18AM (#11806092)
For the first programming courses I can understand the commenting, but I've been TA for advanced courses where many of the students have passed the compiler class. They don't need comments anymore, and it really detract from the readability of the code.
Re:How to win the coding interview by bbcbasic on Tuesday May 31, 2016 @12:27AM (#11804564)
and return the original value
Re:How to win the coding interview by twblalock on Tuesday May 31, 2016 @01:17AM (#11804750)
++n; // don't touch this unless you know what you are doing
Re:How to win the coding interview by bbcbasic on Tuesday May 31, 2016 @01:42AM (#11804843)
n = ++n; // Extra thread safety
Re:How to win the coding interview by ry_ry on Tuesday May 31, 2016 @02:52AM (#11805096)
$.incrementNumber(n, 1); // From stack overflow
Re:How to win the coding interview by bbcbasic on Wednesday June 01, 2016 @05:42PM (#11818455)
Confession. Have written many comments stating "copied from stackoverflow http://..."