In Conversation with Go-Lang’s DataTypes | Part2

  • The first type is bool, for Boolean. This is a simple true, false value and the only two values that you can assign are true and false.
  • String types are collections of characters. A variable with the type of string contains a series of characters. We’ll be talking about strings a lot.
  • Integers come in a variety of flavors. These are the fixed integer types. They each declare either an unsigned or assigned integer and the numeric value in the name is the number of bits. That affects the range or the highest and lowest values that you can assign. There’s also a set of type aliases, the byte, the unsigned int, the int and the unsigned int pointer. The int and unsigned int data types are interesting. They reflect either a 32 or a 64 bit value depending on what operating system you’re running on. On macOS and on 64 bit windows these are the same as an int64 and a uint64. But, if you run exactly the same code in the Go playground those become 32 bit values because of the underlying operating system.
  • There are two floating types, float32 and float64. And, once again, the numeric values in the names indicate the number of bits used for storage and therefore, the range that’s available to you.
  • There are some complex types, complex64 and complex128. A complex number contains two parts, real numbers and imaginary numbers.
  • And then there are also built-in types for data collections. There are Arrays and Slices to manage order data collections and Maps and Structs to manage aggregations of values.
  • In Go, a function is a type and that’s what makes it possible to take a function and pass it into another function as an argument.
  • Interfaces and Channels are also types in Go’s and Go also supports pointers, reference variables that point to an address in memory to refer to another value. These are the built-in types in Go but they’re just the beginning point, because again, you can create your own data types in this language.
  • bufio
  • os
  • That’s yet another way in Go-Lang to receive-in the values for the variables.
  • Underscores are used to ignore errors returned by reader.ReadString()
  • We get the input from the console using the bufio packages, new reader function and a reader object and the OS.standard in object to get data specifically from what the user types in. These values always come to you as strings.
  • We may need to convert them to other types. To do this, I’ll need another package that’s a part of the Go library called strconv for string conversion. And I’m also going to need a package named strings. This package contains all sorts of functions for manipulating strings.
  • Now, the user can type-in space characters at the beginning or the end of the string and therefore it won’t parse correctly. So I’m going to use a function from the string package called TrimSpace. And that removes any leading or trailing whitespace.
  • We also need to pass-in the bit size. Pass-in 32 if you want to float 32 value or 64 for float 64. I’m working on a 64 bit operating system. So I’ll parse in 64.

--

--

--

Software Engineer for Big Data distributed systems

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How Can I Install Rockspace Wifi Extender Via re.rockspace.local?

How to write programming articles effectively?

Open-sourcing ABC: Import MongoDB, SQL, JSON, CSV, Firestore, Redis Data Into Elasticsearch

Some thoughts on a Philosophy of Software Design

[LeetCode]#27. Remove Element

What we should know

Advanced Unit Tests: 5 Pitfalls and How To Avoid Them

Comic: two software engineers staring at a red screen, one saying: “it’s almost green, just some broken tests”

Declaration of Homestead

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
aditya goel

aditya goel

Software Engineer for Big Data distributed systems

More from Medium

Go-Lang Hands-On| Part-3

Learning Go from Documentation #3 (Error handling)

Consuming an API with Golang