in

Go – Unused Code and the Blank Identifer

Unused Code in Go (Golang)

In the Go language (Golang) there is a concept that threw me for at first.  In other languages, you can have unused code sitting around.  By unused I don’t mean comments, instead I mean code that isn’t actively being consumed by the application.  For example, if I declared two variables (a and b) but only initialized variable a, even though the variable assignment for b is valid – it will not compile, as variable b is not getting consumed.

This language requirement keeps the code useful.

Blank Identifiers in Go (Golang)

The underscore is the blank identifier.  It is used to stand in place of a variable assignment. For example, if you had a call to http.Get you’ll get back the response or an error.  Instead of writing the catch code to handle an error, you could call:

resp, _ : = http.Get(….)

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Written by Admin

I work for a Telecom company writing and testing software. My passion for writing code is expressed through this blog. It's my hope that it gives hope to any and all who are self-taught.

Golang – Variable Declaration, Assignment and Initialization

Form Fuzzing with Python