Skip to content

Question about code #35

Answered by johningve
Hang95 asked this question in Q&A
Feb 22, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi!

There are a few reasons to do this in Go:

  1. To make a field immutable (at least to other packages)
  2. To be able to use it in an interface

As for Block.Hash(), the main reason is to make the hash field immutable. Also, the Hash() method was previously used to calculate the hash the first time it was called, but I moved that to NewBlock.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Hang95
Comment options

Answer selected by Hang95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants