Hacker News new | ask | show | jobs
by dale_glass 299 days ago
But that's an implementation issue. Do you really want to say, work on a project where somebody renamed "if" to "wenn" because they thought writing code in German would be neat?

If you want to make a special use tool, you can write a function like custom_if(cond, then_callback, else_callback) in most languages.

Maybe I'm just getting old, but as time goes by I like it more and more when things are obvious and non-magical.

2 comments

I would rather risk the possibility of dealing with a project where someone did something unorthodox and clearly wrong than work with a language that tries to forbid a priori everything it considers unorthodox. Not that I'm out to defend C's awful clumsy macros, but it's no better when the alternative is nothing at all.
> Do you really want to say, work on a project where somebody renamed "if" to "wenn" because they thought writing code in German would be neat?

Ha, no, I wouldn't. Because to me it is important, that anyone can read the code, not just me or a German speaking developer. Just like I wouldn't translate "if" to Chinese. The point is, that this translation serves no purpose. Or rather its benefit, if any, is not sufficient to justify it being done and deviating from the standard. Macros can be useful and justified. But these string substitution macros ... Meh, rather rarely, I guess. Maybe for when you don't have "true" and "false" or something.

Some useful examples of macros are: Threading/pipelining, timing, function contracts. Things where the order of evaluation needs to change. Things one cannot easily do with functions alone. Your example of "custom_if" is actually a good one, depending on what "custom_if" does. If it needs its arguments to not be evaluated, unless an earlier argument meets some criteria, it would be a good candidate for a macro. Those things are not done using string substitution macros.