[CMake] repeating conditional clauses

Brandon Van Every bvanevery at gmail.com
Mon Mar 3 11:56:20 EST 2008


On Mon, Mar 3, 2008 at 4:55 AM, Sylvain Benner <benner at virtools.com> wrote:
>
>  > I don't buy the "do it with comments" approach.
>  > Something changes, then the comments are wrong.
>
>  It's a fact that the code must be self explanatory as much as possible
>  but it will never be as powerful as good and up to date comments.

Comments don't get updated.  They're correct for awhile, then they rot.

>  I don't buy the "duplication of code" approach.

It makes lots of sense when you have to scroll an entire screen to see
the next clause of the conditional.  Part of what trips people up
though, is that "else" really means "else_not".  And what does "endif"
refer to, the "if" or the "else_not" ?

if(blah_is_true)
  yadda(yadda)
else_not(blah_is_true)
  badabim(badabang)
endif(blah_is_huh???) # should be blah_was_used

I think it's easy to get used to this, if you write a lot of CMake
script.  But clearly, it is paradigmatic of CMake, and weird to anyone
else.  It's not great marketing material.  It leaves the newbie or
casual user cold, i.e. someone who only does periodic maintenance and
doesn't try to be a CMake expert.

Maybe we could just ask our program text editor to magically insert an
appropriate comment, based on the if(clause).  It would be a form of
pretty printing.  It would comment any conditionals that are more than
20 lines apart or whatever.

if(blah)
  yadda(yadda)
else #(NOT blah)
  badabim(badabang)
endif # see blah


Cheers,
Brandon Van Every


More information about the CMake mailing list