>From studying Go I learned:
there is no need of if/else unless there is a statement after it which 
depends on it

if
else
statement  //depends on if/else branch/path

Isn't it so?

On Sunday, July 30, 2017 at 4:22:00 PM UTC-4, Eric Brown wrote:
>
> What is the standard way to construct|format the following code snippet? 
>  I think the first is more readable; however, is there any accepted syntax 
> I should be using working my way up the ladder as a senior developer?
>
> block, err := aes.NewCipher(key)
> if err != nil {
>  return err, nil, nil
> }
>
> nonce = make([]byte, 12)
> if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
>  return err, nil, nil
> }
>
> aesgcm, err := cipher.NewGCM(block)
> if err != nil {
>  return err, nil, nil
> }
>
> return nil, nonce, aesgcm.Seal(nil, nonce, plainText, nil)
>
>
> or
>
> block, err := aes.NewCipher(key)
> if err != nil {
>  return err, nil, nil
> } else {
>  nonce = make([]byte, 12)
>  if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
>   return err, nil, nil
>  } else {
>   aesgcm, err := cipher.NewGCM(block)
>   if err != nil {
>    return err, nil, nil
>   } else {
>    return nil, nonce, aesgcm.Seal(nil, nonce, plainText, nil)
>   }
>  }
> }
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to