From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4c42ac518eba0bbe X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,4c42ac518eba0bbe X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,4c42ac518eba0bbe X-Google-Attributes: gid1014db,public From: Mark Wilden Subject: Re: Coding for Obscurity Date: 1997/11/26 Message-ID: <347C232E.2A8C@mWilden.com>#1/1 X-Deja-AN: 292843196 References: <343fbb5a.0@news.iprolink.ch> <34466EB4.3381@dynamite.com.au> <6275dt$agm$3@news.on> <344BCED0.2D51@dynamite.com.au> <62tpap$7gh$1@darla.visi.com> <3470EF6E.F74@lysator.liu.se> <64qsf0$ccc@dfw-ixnews11.ix.netcom.com> <3474BF28.2F9F@dynamite.com.au> <34741AAF.1C7@CWA.de> <34788101.7367@scitex.com> <01bcf8fc$e918e0a0$0644a3cd@jimj.jumpmusic.com> <3479F8FB.2D7F@mWilden.com> <65fr08$vtu$1@flood.weeg.uiowa.edu> Organization: The Mark Wilden Company Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1997-11-26T00:00:00+00:00 List-Id: Robert S. White wrote: > > In article <3479F8FB.2D7F@mWilden.com>, Mark@mWilden.com says... > > >But ?: is not an idiom; it's a part of the language definition. I'll > >give you the benefit of the doubt and assume that when you think it > >through, you understand it. > > I _understood_ it in 1983. I was talking about understanding a line of code and you're talking about understanding a syntax element, but never mind. > But right now in thinking about > it, I'll say that it would have been better from a code maintenance > point of view, that K&R had never thought of it as a convenient > typing shortcut. IMHO YMMV I don't look at it like that at all. I certainly would never use it instead of an if-statement just to save some typing (in fact, I don't use it very often at all). C/C++ is naturally a terse language, however, and one of the advantages of terseness, used appropriately, is the ability to let the reader "chunk" in order to understand the code faster. Terseness also can have maintenance benefits, in reducing duplication. For example, here's a case where I used the conditional operator recently: EnableMenuItem(hGameMenu, ID_NEWLIFE, (CanBeReborn() ? MF_ENABLED : MF_GRAYED) | MF_BYCOMMAND); I think this is easier to read and maintain than either // redundant--bad for maintenance if (CanBeReborn()) EnableMenuItem(hGameMenu, ID_NEWLIFE, MF_ENABLED | MF_BYCOMMAND); else EnableMenuItem(hGameMenu, ID_NEWLIFE, MF_GRAYED | MF_BYCOMMAND); or // wordy--takes longer to read and understand // reader may wonder if flag is used further down unsigned flag; if (CanBeReborn()) flag = MF_ENABLED; else flag = MF_GRAYED; EnableMenuItem(hGameMenu, ID_NEWLIFE, flag | MF_BYCOMMAND);