Date: Fri, 23 Feb 2001 14:30:20 -0600 From: "Michael C . Wu" <keichii@iteration.net> To: j mckitrick <jcm@FreeBSD-uk.eu.org> Cc: freebsd-chat@freebsd.org Subject: Re: bad programming practice? Message-ID: <20010223143019.E32113@peorth.iteration.net> In-Reply-To: <20010223180321.A33329@dogma.freebsd-uk.eu.org>; from jcm@FreeBSD-uk.eu.org on Fri, Feb 23, 2001 at 06:03:33PM %2B0000 References: <20010223180321.A33329@dogma.freebsd-uk.eu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Feb 23, 2001 at 06:03:33PM +0000, j mckitrick scribbled: | | I recently posted an example showing a simple C rule my company uses that | eliminates a simple error. | | if(var == CONST) | | can generate a bug if you forget an equals sign. | | But using | | if(CONST == var) | | will create an error if you forget an equals sign. | | Obviously, this is just a trick to prevent a sloppy coding error, but why is | it so disdained? What is wrong with using such tricks to make our job | easier? When you have a very lengthy boolean expression, it causes headaches to read the code. However, I do teach new students of C or C++ to use the if (CONST == var) formatting just so that they do not mess up. Then I explain to them why it is a bad idea when they advance into a better programmer. (This has backfired on me once from a student, people who attended BSDCon2k know the story of the student in my OS class.) Personally, I think most C/C++ programmers eventually learn to always watch for == vs. = mistakes right when they type the boolean expression. Hence, the trick becomes useless as one advances. -- +------------------------------------------------------------------+ | keichii@peorth.iteration.net | keichii@bsdconspiracy.net | | http://peorth.iteration.net/~keichii | Yes, BSD is a conspiracy. | +------------------------------------------------------------------+ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010223143019.E32113>