Go Desperately Needs Lousy Types of Security | Java code geeks

I show You how To Make Huge Profits In A Short Time With Cryptos!

If you have worked with Go before, you’ve probably seen this runtime error.

1

panic: runtime error: invalid memory address or nil pointer dereference

The current solution is to check thevar != nil before using var, but if you forget to do so, your program will crash. This means that this simple programmer error could shut down your entire server. Hope you catch these errors with testing before they hit production. However, we are not machines, so inevitably we will not catch some until our end users encounter a production error.

Go should have types that can never be zero

Jelte Fennema already proposed a solution more than 3 years ago:

The idea is very simple and is also used by Rust and C ++: add a pointer type which can never be zero.

Jelte compares Go to Rust, saying Safe Rust doesn’t have zero capacity pointers.

However, I think comparing Go to Swift is more appropriate as Go will never get rid of null pointers.

Fast

Swift has two types of variables: Optional and non-optional. Optional means nullable.

Variables that are not optional in Swift are guaranteed to never be zero. Your function no longer needs to check its arguments for nil if you declare your non-optional arguments. Imagine removing all these duplicates if myarg == nil in all your functions with the guarantee that your entries will never be null!

Conclusion

Go2 a many open proposals for non-zero types, but nothing seems decided yet. Hopefully they don’t dismiss this lightly. In my opinion, this is the only thing stopping Go from competing with Rust, Swift, TypeScript, and other languages ​​with non-nullable types.



Source link

Leave a Reply

Your email address will not be published.