Live data from Hacker News

Interviewing programmers: coding test example explained

solipsys.co.uk

31–40 of 178 posts

Re: Interviewing programmers: coding test example explained

#31
post #10
post #8

Am I OCD when I cringe when I see 'p_rite' where he (I think) means 'p_write'? That alone would knock a few points off a candidate doing this test when he's interviewing with me. 'rite' can mean 'write' or 'right' or even 'allright' - why the unnecessary confusion?

You're not alone in feeling the OCD twinge, but are almost certainly alone in being willing to demerit a candidate writing that.

I haven't been in the position of hiring programmers, but I've mentored a few FreeBSD developers, and I would not allow one of my mentees to commit code like that.

Re: Interviewing programmers: coding test example explained

#32
post #2

So when do we get to read part 3? I want to see what "creative" solutions people came up with.

Currently working on that. It's safe to say that your two solutions were the most creative. In my graph of solution proximity, they are both a long way away from all the other solutions.

Awww. I was hoping that with an audience of hackers and such a trivial problem I wouldn't be alone in my creativity. :-/

Re: Interviewing programmers: coding test example explained

#33
post #27

'\0' is null-terminated NOT zero-terminated, no ? By definition, a string in C is always null-terminated.

'\0' is a character, not a string. The string is "\0".

Also, C strings are NUL-terminated, not NULL-terminated. (char)(0) is the NUL character; (void * )(0) is the NULL pointer (usually).

Re: Interviewing programmers: coding test example explained

#34
post #8

Am I OCD when I cringe when I see 'p_rite' where he (I think) means 'p_write'? That alone would knock a few points off a candidate doing this test when he's interviewing with me. 'rite' can mean 'write' or 'right' or even 'allright' - why the unnecessary confusion?

As long as it's not a blatant misspelling, I think shorthand is fine.

Re: Interviewing programmers: coding test example explained

#36
post #10

Earlier quoted context omitted.

You're not alone in feeling the OCD twinge, but are almost certainly alone in being willing to demerit a candidate writing that.

Why would he be alone? Why is spelling less important in code than in normal writing? I would argue it is considerably more important.

If you truly think the market for C developers is so favorable to employers that someone who can write the in-place-whitespace-removal function off the top of their heads is easy to find, then by all means, ding candidates for their spelling during interviews. Thanks for making it that much easier for the rest of us to hire.

In the industry I work in --- computer software --- it is ludicrously hard to find people competant in C programming, and I'm inclined to ignore idiosyncratic spelling in source code.

Re: Interviewing programmers: coding test example explained

#37
I'm sure RiderOfGiraffes doesn't want a third entry from me at this point, so I figure I might as well just post it here:

  #define C	char
  #define F	for
  #define R	condense_by_removing
  #define V	void

  V R(C*A,C B){F(C*J=A;*J=*A++;J+=*J!=B);}
or without #defines:

  void condense_by_removing(char*A,char B){for(char*J=A;*J=*A++;J+=*J!=B);}

Re: Interviewing programmers: coding test example explained

#38
post #17

hmm, is it normal to assume all strings in C are \0 terminated? What are the memory usage implications for that? I won't pretend to know C but suppose you have a string that is 'ab{100}\0' and you wanted to remove all of the bs, you'd end up with 'a\0b{99}\0' in memory correct?

Yes, C strings are \0 terminated and that is what you'd end up with. Memory management is between you, malloc() and free(). Assuming this were malloc()d memory, if you wanted to free up the unused bytes, you'd probably: char *condensed = strdup(z_terminated); if (condensed) free(z_terminated); else // out of memory

Using realloc would be better, since it allows the memory allocator the option of not copying the string.

Re: Interviewing programmers: coding test example explained

#39

I'm sure RiderOfGiraffes doesn't want a third entry from me at this point, so I figure I might as well just post it here: #define C char #define F for #define R condense_by_removing #define V void V R(C*A,C B){F(C*J=A;*J=*A++;J+=*J!=B);} or without #defines: void condense_by_removing(char*A,char B){for(char*J=A;*J=*A++;J+=*J!=B);}

By all means send it in - it will be interesting to compare it against the others.

Re: Interviewing programmers: coding test example explained

#40
post #27

'\0' is null-terminated NOT zero-terminated, no ? By definition, a string in C is always null-terminated.

As it happens, '\0' translates to 0. Since they are composed of characters, C programmers tend to do the c == '\0' check instead of the shorted c == 0 check, just to make sure everyone knows we are still treating the char like a character in a string; it is just style.

  char c = 65

is equivalent to and just as legal as

  char c = 'A'

So yes, C strings ARE zero-terminated. In fact, it is a bit weird to say they are null-terminated. It is technically true, given that NULL often translates to 0, but NULL is a pointer value in the same way that zero is a number.

For some reason, I vaguely remember some security hack in one OS where NULL went to a special place in memory that was marked as invalid (1, 63, or something), so in that case, NULL was not defined as 0. Since the memory is vague, though, don't quote me on it.

Post reply on HN