Counting if err != nil in source codes written in Go

I wonder whether if err != nil is actually use in source code of a popular project written in Go programming language.

So I obtained runc including libcontainer from github:

git clone https://github.com/opencontainers/runc.git

I counted these following things:

  1. Number of source code files
    $ find runc -name '*.go' | wc -l
    359
    
  2. Number of lines
    $ find runc -name '*.go' | xargs -I '{}' cat '{}' | wc -l
    61209
    
  3. Number of “if err”
    $ find runc -name '*.go' | xargs -I '{}' cat '{}' | grep 'if err' | wc -l
    1684
    
  4. And finally, number of “if err != nil”
    $ find runc -name '*.go' | xargs -I '{}' cat '{}' | grep 'if err != nil' | wc -l
    1006
    

1006 of “if err != nil” from 359 files with 61209 lines. So I suppose that using if err != nil in Go-based project is common.

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s