Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing argument to a function

Is it a bad programming principle to pass arg to a function which isn't "exact match" type wise but has trivial or user defined conversion to this type? For example:

void f(bool option);

and later in main (this is highly hypothetical so please don't give advise on that code):

int a = getSomeValue();

f(a);//here instead of bool I'm passing int - is it a bad programming practice or not?
like image 596
There is nothing we can do Avatar asked Dec 05 '22 23:12

There is nothing we can do


1 Answers

I think most people will consider this bad practice. Writing f(a !=0) is much clearer and expresses the intent concisely.

like image 98
Alexander Gessler Avatar answered Dec 07 '22 12:12

Alexander Gessler