Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There are degrees of conciseness.

I've seen real code that looks like

    if(bool_var == false) {
      other_bool_field = true;
    } else if(bool_var == true) {
      other_bool_field = false;
    }
Which I suppose could be called anti-concise.


Yes, even the "unconcise" first draft of anyone who cares enough to be here on HN is much better than some of the code out there.

There's a basic level of concision you'll have by default if you actually understand the problem and the tools. You won't go away out of the way to complicate things. Maybe it's still a far cry from optimal, and definitely not code golf, but enough that I'd be worried if I saw even a first draft without it.


When I see code like that, I wonder whether a beginner is trying to fix a bug where they unexpectedly copied by reference rather than value.


yes, when writing this as other_bool_variable=!bool_var you make it much better because the code speaks for itself ("other_bool_variable is the opposite of bool_variable").

The risk is that you may end with such concise code that nobody understands what it does. I went that dark path with perl 20 years ago, form "oh what a cool language for someone who comes from C" to "let's squeeze that in half a line, and either do no understand what it does, or add three lines of comments to explain".

But yes, there is a good middle-groud somewhere


I wouldn't consider if (bool) or x = !bool to be concise coding. That's just regular code.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: