Logical Operators

Logical operators Logical operators apply to boolean values and yield a result of the same type as the operands. The left operand is evaluated, and then the right if the condition requires it. && conditional AND p && q is "if p then q else false" || conditional OR p || q is "if p … | Continue reading


@boldlygo.tech | 2 months ago

Introducing Go 1.22!

Join me in less than an hour, when I’ll be live streaming again! I’ll be continuing to add SQLite support to Kivik, using Test-Driven Development.Go 1.22 was released on February 7. So I’m a bit behind on talking about the changes introduced to the spec. But better late than neve … | Continue reading


@boldlygo.tech | 2 months ago

Comparison operators, conclusion

Comparison operators …Slice, map, and function types are not comparable. However, as a special case, a slice, map, or function value may be compared to the predeclared identifier nil. Comparison of pointer, channel, and interface values to nil is also allowed and follows from the … | Continue reading


@boldlygo.tech | 2 months ago

Comparison operators, part IV

Comparison operators …Struct types are comparable if all their field types are comparable. Two struct values are equal if their corresponding non-blank field values are equal. The fields are compared in source order, and comparison stops as soon as two field values differ (or all … | Continue reading


@boldlygo.tech | 2 months ago

Comparison operators, part III

Today we continue through the list of data types and how comparison and ordering works on each.Comparison operators …Channel types are comparable. Two channel values are equal if they were created by the same call to make or if both have value nil. Notice that channel comparison … | Continue reading


@boldlygo.tech | 2 months ago

Comparison operators, continued

Yesterday we started on comparison operators. Today we’ll continue, but there are a lot of types to cover, so I’ll break this down into a two or three parts, to keep each day’s email easily digestible.Recall that we had just been introduced to the concepts of ordered and comparab … | Continue reading


@boldlygo.tech | 2 months ago

Comparison operators

I’ll be livestreaming again today! I hope you can join me as I continue where I left off last week, adding some new features to my open-source library, Kivik!Let’s talk about a mundane detail… that actually has some interesting nuances: Comparisons!Comparison operators Comparison … | Continue reading


@boldlygo.tech | 2 months ago

String concatenation

Today we’re looking at a deceptively short section of the spec: String concatenation… String concatenation Strings can be concatenated using the + operator or the += assignment operator: s := "hi" + string(c) s += " and good bye" String addition creates a new string by concatenat … | Continue reading


@boldlygo.tech | 3 months ago

Floating-point operators

Floating-point operators For floating-point and complex numbers, +x is the same as x, while -x is the negation of x. The result of a floating-point or complex division by zero is not specified beyond the IEEE-754 standard; whether a run-time panic occurs is implementation-specifi … | Continue reading


@boldlygo.tech | 3 months ago

Integer overflow

Integer overflow For unsigned integer values, the operations +, -, *, and << are computed modulo 2n, where n is the bit width of the unsigned integer’s type. Loosely speaking, these unsigned integer operations discard high bits upon overflow, and programs may rely on “wrap around … | Continue reading


@boldlygo.tech | 3 months ago

Can you think of an use case for ^x?

Last week I talked about unary integer operators, including the ^ operator. A reader wrote back asking: Can you think of an use case for ^x? So today I’m going to answer this question! No! LOL Not very satisfying, is it? So I did some digging to find some examples. Note, none of … | Continue reading


@boldlygo.tech | 3 months ago

You're already running my Code

Last week I mentioned I’d be speaking at FOSDEM over the weekend. Well, the weekend is over, and the video of my presentation is now live, so you can catch it even if you weren’t in Belgium. You can also catch many of the other great Go-related talks (and more coming every day, a … | Continue reading


@boldlygo.tech | 3 months ago

FOSDEM 2024: You're already running my code in production

Boldly Go Open main menu Blog YouTube Hire Me Contact Daily Email Boldly Go Close menu Blog YouTube Hire Me Contact Daily Email FOSDEM 2024: You're already running my code in production February 3, 2024 How I became a Go contributor, and you can, too. My Content Boldly Go: Daily … | Continue reading


@boldlygo.tech | 3 months ago

Unary integer operators

We have a quick one today to finish up integer operators, before diving into a semi-hairy topic next…Integer operators …For integer operands, the unary operators +, -, and ^ are defined as follows:+x is 0 + x -x negation is 0 - x ^x bitwise complement is m ^ x with m = "all bits … | Continue reading


@boldlygo.tech | 3 months ago

Divide by zero, and shifting

Integer operators …If the divisor is a constant, it must not be zero. If the divisor is zero at run time, a run-time panic occurs.I’m sure you expected that. Division by zero is pretty universally not allowed.var a = 3 var b = 0 var c = a / 0 // Won't compile var d = a / b // run … | Continue reading


@boldlygo.tech | 3 months ago

Integer operators

Today we continue our discussion of arithmetic operators, with a topic that is likely not new to you at all: Integer operators.Integer operators For two integer values x and y, the integer quotient q = x / y and remainder r = x % y satisfy the following relationships:x = q*y + r … | Continue reading


@boldlygo.tech | 3 months ago

Join me at FOSDEM

Do you have plans to be in Brussels this weekend? If so, join me at FOSDEM 2024! I’ll be speaking in the Go Devroom on Saturday morning on my journey to becoming a Go contributor. Not going to be in Brussels? Follow me on Mastodon where I’ll be live micro-blogging from the event, … | Continue reading


@boldlygo.tech | 3 months ago

Arithmetic operators

Arithmetic operators Arithmetic operators apply to numeric values and yield a result of the same type as the first operand. The four standard arithmetic operators (+, -, *, /) apply to integer, floating-point, and complex types; + also applies to strings. The bitwise logical and … | Continue reading


@boldlygo.tech | 3 months ago

Operator precedence

I hope we all know what operator precedence means… but just in case it’s fuzzy, I’ll illustrate with a simple example from junior high school. What does this mean? 1 + 2 * 3 It’s either 9 or 7, right? It depends on the order in which we apply the + and * operations. I’m sure most … | Continue reading


@boldlygo.tech | 3 months ago

Shift operators

Operators …The right operand in a shift expression must have integer type or be an untyped constant representable by a value of type uint.A bunch of examples demonstrating this follow in the spec, so I won’t provide my own.… If the left operand of a non-constant shift expression … | Continue reading


@boldlygo.tech | 3 months ago

Operators

Operators Operators combine operands into expressions.Nice. I love a concise description/definition. Especially after the confusion that was yesterday’s post about loose and exact unification.Expression = UnaryExpr | Expression binary_op Expression . UnaryExpr = PrimaryExpr | una … | Continue reading


@boldlygo.tech | 3 months ago

Exact & loose type unification

Type unification … Unification uses a combination of exact and loose unification depending on whether two types have to be identical, assignment-compatible, or only structurally equal. The respective type unification rules are spelled out in detail in the Appendix. The precise de … | Continue reading


@boldlygo.tech | 3 months ago

Reviewing an open-source project

Oops! I went on a vacation last week. But so did my deployment pipeline. Which means that the emails I had queued up to send to you didn’t go through. So this week enjoy what I wrote for last week. And I hope you enjoyed a short vacation from me in your inbox, too. I just publish … | Continue reading


@boldlygo.tech | 3 months ago

Type unification

A couple of days ago we saw the spec reference the concept of “type unification”. Today we start through that explanation…. Type unification Type inference solves type equations through type unification. Type unification recursively compares the LHS and RHS types of an equation, … | Continue reading


@boldlygo.tech | 3 months ago

Successful type inference

Today we finish up the discussion on type inference. So we’ve now Type inference … If the two phases are successful, type inference determined a type argument for each bound type parameter: Pk ➞ Ak A type argument Ak may be a composite type, containing other bound type parameters … | Continue reading


@boldlygo.tech | 3 months ago

Error handling in Go web apps shouldn't be so awkward

A quick interruption to our trek through the Go spec, to mention a new long-form article I just wrote. Jump straight to the full articleIn this post I’m going to describe an error-handling pattern I’ve found to be fairly elegant when writing REST, gRPC, or other services in Go. I … | Continue reading


@boldlygo.tech | 3 months ago

Precedence of type inference

Type inference …Type inference gives precedence to type information obtained from typed operands before considering untyped constants. Therefore, inference proceeds in two phases:The type equations are solved for the bound type parameters using type unification. If unification fa … | Continue reading


@boldlygo.tech | 4 months ago

The many type equations

Type inference …Type inference supports calls of generic functions and assignments of generic functions to (explicitly function-typed) variables.So just to call out this point, made in passing: You cannot assign the result of a generic function to a generic, non-instantiated type … | Continue reading


@boldlygo.tech | 4 months ago

Error handling in Go web apps shouldn't be so awkward

Updated 2024-01-10 to include Domain-specific errors and limitations sections. In this post I’m going to describe an error-handling pattern I’ve found to be fairly elegant when writing REST, gRPC, or other services in Go. I have three goals in writing this post: To explain the pa … | Continue reading


@boldlygo.tech | 4 months ago

Bound type parameters

Type inference …Given a set of type equations, the type parameters to solve for are the type parameters of the functions that need to be instantiated and for which no explicit type arguments is provided. These type parameters are called bound type parameters. For instance, in the … | Continue reading


@boldlygo.tech | 4 months ago

Type equations

I don’t have a lot to expand on in this section, except to offer a pre-amble about some technical terms and symbols that won’t be familiar to everyone: ≡ is a symbol from mathematics that means “identical to”. It’s similar to = which we’re all famliar with, but “stricter”. The sp … | Continue reading


@boldlygo.tech | 4 months ago

Type inference

We just covered instantiations, and learned that it is often possible to infer generic types. Nowe we’ll examine how that mechanism works. This bit gets a bit into the weeds. You’ll be forgiven if you choose to skip over this.Type inference A use of a generic function may omit so … | Continue reading


@boldlygo.tech | 4 months ago

Partial type argument lists

Instantiations … A partial type argument list cannot be empty; at least the first argument must be present. The list is a prefix of the full list of type arguments, leaving the remaining arguments to be inferred. Loosely speaking, type arguments may be omitted from “right to left … | Continue reading


@boldlygo.tech | 4 months ago

When function instantiations can be inferred

A quick update on my livestream: It’s on hold until February, as my family and I made a bit of a last-minute trip to visit family for the month of January, so I won’t be in my studio for a while. Instantiations … When using a generic function, type arguments may be provided expli … | Continue reading


@boldlygo.tech | 4 months ago

How could you improve with a personal Go mentor?

I started Boldly Go: Daily in early January of this year. This means that if you’re reading this, you’re one of the hundreds of people who have joined this daily list in 2023. Thanks! I sincerely hope you’re learning from it.It’s my mission to make Go approachable to people of al … | Continue reading


@boldlygo.tech | 4 months ago

Instantiations

Instantiations A generic function or type is instantiated by substituting type arguments for the type parameters. Instantiation proceeds in two steps:Each type argument is substituted for its corresponding type parameter in the generic declaration. This substitution happens acros … | Continue reading


@boldlygo.tech | 4 months ago

Passing slices to variadic functions

Passing arguments to ... parameters …If the final argument is assignable to a slice type []T and is followed by ..., it is passed unchanged as the value for a ...T parameter. In this case no new slice is created.Given the slice s and calls := []string{"James", "Jasmine"} Greeting … | Continue reading


@boldlygo.tech | 4 months ago

Passing arguments to ... parameters

If you’ve been a reader for a while, you may recall back in April when I first talked about variadic functions. Now we’re ready to dig in a bit further to the details of how these mysterious creatures work.First we’ll see how they work “from the inside”. That is, from the perspec … | Continue reading


@boldlygo.tech | 4 months ago

Refresher on methods

In yesterday’s email, I failed to include the example included in the spec, which doesn’t make sense to include otherwise. I’ve updated the web version of the email in case you’re super curious to see what I left out.We’ve already covered these details, but they’re logically ment … | Continue reading


@boldlygo.tech | 4 months ago

Special case: Multi-value arguments to functions

You may recall that when we started the section on function calls, we were told about a “special case”… well here it is!Calls …As a special case, if the return values of a function or method g are equal in number and individually assignable to the parameters of another function o … | Continue reading


@boldlygo.tech | 4 months ago

nil functions

Calls …Calling a nil function value causes a run-time panic.So, calling a nil function causes a panic. Sensible enough. But when would you ever run across a nil function?Let’s look at some examples.This is probably the most obvious example, and perhaps one that popped to your min … | Continue reading


@boldlygo.tech | 4 months ago

Evaluation of function parameters

Calls If f denotes a generic function, it must be instantiated before it can be called or used as a function value.We’ve seen this rule applied to methods and other types. It should be standard by now, so I won’t dwell on it.In a function call, the function value and arguments ar … | Continue reading


@boldlygo.tech | 4 months ago

Test-driven development: Love it or hate it

Denis Čahuk and Adrian Stanek have invited me to join them in their livestream today to discuss Test-Driven Development. I hope you’ll be able to join in on the conversation! For some it’s a bane they’d rather not hear about at work. For other it’s a core tool that they force the … | Continue reading


@boldlygo.tech | 4 months ago

The type of a function call expression

Calls … The type of the expression is the result type of F. A method invocation is similar but the method itself is specified as a selector upon a value of the receiver type for the method. math.Atan2(x, y) // function call var pt *Point pt.Scale(3.5) // method call with receiver … | Continue reading


@boldlygo.tech | 4 months ago

Calls

Calling all gophers!It’s time to talk about… Calls!Calls Given an expression f with a core type F of function type,f(a1, a2, … an) calls f with arguments a1, a2, … an.This basic syntax is common to many languages, so should not feel at all strange if you have any programming expe … | Continue reading


@boldlygo.tech | 4 months ago

Type assertion values

By now you’ve guessed there was no live stream today. Illess has been hitting my family hard. I’ll try to pick it up again after the new year.Type assertions …If the type assertion holds, the value of the expression is the value stored in x and its type is T. If the type assertio … | Continue reading


@boldlygo.tech | 5 months ago

Type assertions of interface types

Type assertions … If T is an interface type, x.(T) asserts that the dynamic type of x implements the interface T.This simple sentence has some pretty profound implications.Let’s start with a simple example:type Fooer interface { Foo() } type thing int func (thing) Foo() {} var x … | Continue reading


@boldlygo.tech | 5 months ago

Type assertions of non-interface types

Yesterday we started on type assertions. Today we’ll look at some of the specific details, as they relate to type assertions to non-interface types. Tomorrow we’ll look at interface types.Type assertions …More precisely, if T is not an interface type, x.(T) asserts that the dynam … | Continue reading


@boldlygo.tech | 5 months ago