Hacker News new | ask | show | jobs
by EliRivers 3539 days ago
As an aside, I also dislike hackerrank; for me, it's the sheer ham-fisted ineptitude of some of the alleged learning exercises.

Look at this mess: https://www.hackerrank.com/challenges/preprocessor-solution

This purports to be teaching use of the preprocessor. It's horrific. It's someone's amusing "look at how you can create your own programming language by abusing the preprocessor" mess; fair enough, it's always fun to see someone do something this painful, but this is being genuinely presented as a preprocessor learning exercise.

One day I'll have to work with people who learned from this (and others like it), and it will be a long painful road to help them unlearn.

1 comments

  One day I'll have to work with people who learned from
  this (and others like it), and it will be a long painful road
  to help them unlearn.
Quoting from the link you've mentioned:

  #define add(a, b) a + b
I couldn't agree with you more.

--

To elaborate:

  add(1, 8) * add(5, 1)
wouldn't yield 9 * 6 = 54, but

  1 + 8 * 5 + 1
which is 42. One might say that it's correct, since it's the Answer to the Ultimate Question of Life, the Universe and Everything.
Which is why anyone who has experience programming in C would instead write:

  #define add(a, b) ((a) + (b))
One may also do:

  add(x, foo(x))
Which is why anyone who has experience programming in C would use (an inline) function instead.