0 Means No Error

Supposed you have a function for instance :

insertAll(arr: Vec<i32>)

What is the return value should be ?

it's up to you as the developer what you see best fit.

it could be returned as true, number, or array itself.

One of my regret is returning 1 as a success, and 0 is failure.

You could say it's logical to return 1 because there is a notion that 1 is bigger number so it means better value. thus 1 is success.

But, we might not realize or we might not paying attention that in some system exit code 0 means no error.

So 0 Means No Error.

In C programming language, there is a standard library function in 'stdlib.h'

void exit(int status);

The status args is an integer value. The value of 0 generally indicates the program completed successfully or there is --- 0 ERROR ---

In Java is also the same

System.exit(0) Generally used to indicates no error on terminating.

Even on early days of computing, or we could say 'boomer programmer' has already use 0 to indicate success exit code.

So we should do the same for the sake of consistency.

Here is my take, do whatever you want. But, do it responsibly. write some documentation and test so future you or other people read your code can understand it.


You'll only receive email when they publish something new.

More from Rifky Adni Putra
All posts