Is it a bad practice to rely on implicit default values, like:
class Node
{
int red;
int green;
int blue;
bool grayscale;
Node next;
}
Instead of explicitly setting them:
class Node
{
int red = 0;
int green = 0;
int blue = 0;
bool grayscale = false;
Node next = null;
}
A DEFAULT value clause in a data type specification explicitly indicates a default value for a column. Examples: CREATE TABLE t1 ( i INT DEFAULT -1, c VARCHAR(10) DEFAULT '', price DOUBLE(16,2) DEFAULT 0.00 ); SERIAL DEFAULT VALUE is a special case.
A default value is the value that is inserted into a column when an explicit value is not specified in an INSERT statement. A default value can be a literal character string that you define or one of the following SQL constant expressions: USER.
The BLOB , TEXT , GEOMETRY , and JSON data types cannot be assigned a default value.
A function default value is a value that can be used for a parameter if the calling statement does not pass an argument. If an argument is provided, the default value is ignored.
No, I think it's OK to rely on default values. Explicitly assigning them will just clutter up the code. Also, it has the advantage of making it easier to distinguish fields you assign non-default values to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With