once i setup a project ,i need set codes to describe the operations result which return to client.
so the code be like these:
100 'succeed
200 'failed
201 'failed because the require object doesn't exist
...
or like these:
43100 'shop buy item succeed
43201 'shop buy item failed because user doesn't have enough money
43202 'shop buy item failed because the item sold out.
...
but in real development,the return code thing didn’t go well, teammates must use dictionary to look up what’s the meaning of a code.nobody remember any of them.
so i thought why must we use number as return code? only because in our experience many protocols return digital code ,like the most famous http protocol 404,403,500,etc..
so my question is why they use number?isn’t string is better for human reading?
like ‘FileNotFound’ replace 404. or ‘success.cart.order’ which means in module ‘cart’ sub function ‘order’ the operation is success.
Well, I do not know the definitive answer. For software, however, numbers have a few advantages:
switch/ jump-tables for decades (faster processing too).FileNotfoundinstead ofFileNotFound.