Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning structs as NullObjects #40

Open
zolia opened this issue Mar 24, 2021 · 1 comment
Open

Returning structs as NullObjects #40

zolia opened this issue Mar 24, 2021 · 1 comment

Comments

@zolia
Copy link

zolia commented Mar 24, 2021

NOTE: In many scenarios, invoking a panic will actually be preferable to indicate that there is an error check missing.

I cannot think of a situation when this is not the case. Basically golang users should always check for errors. Returning noop empty struct basically asks for trouble and the user might not instantly realize that imported library function works not as expected. Fail as soon as possible. If there is an error, all other parameters should be ignored by the user.

@Pungyeon
Copy link
Owner

I don't necessarily disagree... I think that I'm more in favour of defensive program, than it seems that the lanugage developers of Go intended. I prefer to avoid panics and nil references.

the user might not instantly realize that imported library function works not as expected

Similar, the user might not realise a panic could happen and this ends up crashing a critical system at some point.

I think my opinion of this is that, the general advise is to avoid using panic, other than in startup / setup. So, why wouldn't we want to avoid a potential panic everywhere else in the code?

I hope you understand, I'm not trying to be stubborn ☺️ I just want to make sure we get each of our points across, I'm completely open to changing my opinion on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants