News for hackers. Stuff that matters.
Re:The most dangerous code in the world by rolux on Wednesday October 24, 2012 @08:25PM (#4695733)
When it comes to API design, a good rule of thumb is that parameters that can be either 0, 1 or 2 will cause bugs.
Re:The most dangerous code in the world by jrockway on Wednesday October 24, 2012 @08:49PM (#4695818)
More generally: "when it comes to API design, a good rule of thumb is that parameters will cause bugs."
Re:The most dangerous code in the world by rolux on Wednesday October 24, 2012 @09:01PM (#4695854)
No, I was actually trying to be specific. There's usually nothing wrong with 0/1 or 1-9.

Empirically, 0/1/2 either means no/yes/yes-and-something-obscure-on-top-of-that, or, worse, as in this case, no/kind-of-but-not-really/yes.

Re:The most dangerous code in the world by prodigal_erik on Wednesday October 24, 2012 @11:46PM (#4696280)
It's akin to http://c2.com/cgi/wiki?ZeroOneInfinityRule. If you started out thinking it was just a switch, you should be very reluctant to add a third state without rethinking what you really need to express, or you end up with my favorite from TheDailyWTF:

  enum Bool { 
      True,
      False,
      FileNotFound
  };
This would have been much safer as separate AUTHENTICATE_CERT (which checks the CA sig and expiry and revocation) and VERIFY_CERT_COMMON_NAME options, both of which default to true.
Re:The most dangerous code in the world by adgar2 on Wednesday October 24, 2012 @08:59PM (#4695847)
Your more general adage is useless. The one you responded to is useful. A more useful, also general adage would be "the more choice in selecting parameters to an API, the more likely there will be bugs consuming that API."
Re:The most dangerous code in the world by Genmutant on Thursday October 25, 2012 @02:20AM (#4696608)
In this case I think it wouldn't cause bugs if the effect of 1 and 2 would be switched. Then everybody would use it like a boolean and that would be fine, only the few people who really want the name-check disabled would use that option.