You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In all the source code there are a lot of places where pointers are not needed or are declared all over the place.
When we first create a struct, we don't know it's memory address so using pointer semantic is pointless ( pun intended :D ).
Something like this:
mW:=&mockWhatever{}
These things are confusing and are hard to read. This means you will have a cognitive load whenever you see this variable passed around because you have to remember that it will be an address. Instead the & adds readability. Which means it should be used at places where it denotes sharing. Like on a return:
mW:=Whatever{}
......return&mW
This is now easy to read, you can see that it will return an address. Where as this:
mW:=&Whatever{}
...// Long methodreturnmW
Here you have to remember that you returned an address after reading a 100-200 line long method which was doing stuff all over the place.
Use & when it's needed. And make sure a pointer exists because it need to be a pointer and not for the convenient way of checking for nil upon a db lookup. We should use the ok pattern for that.
The text was updated successfully, but these errors were encountered:
In all the source code there are a lot of places where pointers are not needed or are declared all over the place.
When we first create a struct, we don't know it's memory address so using pointer semantic is pointless ( pun intended :D ).
Something like this:
These things are confusing and are hard to read. This means you will have a cognitive load whenever you see this variable passed around because you have to remember that it will be an address. Instead the
&
adds readability. Which means it should be used at places where it denotes sharing. Like on a return:This is now easy to read, you can see that it will return an address. Where as this:
Here you have to remember that you returned an address after reading a 100-200 line long method which was doing stuff all over the place.
Use
&
when it's needed. And make sure a pointer exists because it need to be a pointer and not for the convenient way of checking fornil
upon a db lookup. We should use theok
pattern for that.The text was updated successfully, but these errors were encountered: