Data structure code review

107 views
Skip to first unread message

Miss Adorable

unread,
Mar 3, 2024, 4:25:48 PM3/3/24
to golang-nuts
Hi! I wrote my first data structure in Go. I wonder how idiomatic my code is to enhance it. Previously, I had C# and Java experience.


Steven Hartland

unread,
Mar 3, 2024, 4:55:25 PM3/3/24
to Miss Adorable, golang-nuts
Some feedback:
Instead of errors.New(emptyDataStructureMessage("stack")) use an emptyDataError type, where it implements the error interface by adding an Error() string method, for example:

type emptyDataError string

func (e emptyDataError) Error() string {
    return fmt.Sprintf("not empty %s expected", name)
}


Don't ignore errors like you have here as that can lead to unexpected behavior, in your case a panic if you use those methods..
pushCommand, _ := ....


On Sun, 3 Mar 2024 at 21:25, Miss Adorable <emilygrace...@gmail.com> wrote:
Hi! I wrote my first data structure in Go. I wonder how idiomatic my code is to enhance it. Previously, I had C# and Java experience.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/34b9d900-7571-45d1-ae75-21a021d4c75fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages