Type switching to non-implementing types

More live coding today! Join me in just a few hours for some more Go TDD work on my kivik library. Today we’re continuing to disect this paragraph: Type switches … Cases then match actual types T against the dynamic type of the expression x. As with type assertions, x must be of … | Continue reading


@boldlygo.tech | 17 hours ago

Type switching on a non-interface value. Sorta.

Type switches … Cases then match actual types T against the dynamic type of the expression x. As with type assertions, x must be of interface type, but not a type parameter, and each non-interface type T listed in a case must implement the type of x. The types listed in the cases … | Continue reading


@boldlygo.tech | 3 days ago

Type switches

Back in December we looked at type assertions, which allow us to assert whether an interface type is of a specific underlying type. In that conversation, I promised we’d get to the more flexible type switches. And now, at long last, we have arrived! Type switches A type switch co … | Continue reading


@boldlygo.tech | 4 days ago

Expression switches conclusion

We have just two more points (and some examples) before finishing the topic of expression switches, so let’s get to it. Expression switches … The switch expression may be preceded by a simple statement, which executes before the expression is evaluated. You may recall the discuss … | Continue reading


@boldlygo.tech | 5 days ago

Fallthrough statements

Expression switches … In a case or default clause, the last non-empty statement may be a (possibly labeled) “fallthrough” statement to indicate that control should flow from the end of this clause to the first statement of the next clause. Otherwise control flows to the end of th … | Continue reading


@boldlygo.tech | 6 days ago

Case expressions

I’m back live streaming again! Join me in just over an hour! Bring your questions, too! Expression switches … If a case expression is untyped, it is first implicitly converted to the type of the switch expression. For each (possibly converted) case expression x and the value t of … | Continue reading


@boldlygo.tech | 7 days ago

Switch expressions

Expression switches … If the switch expression evaluates to an untyped constant, it is first implicitly converted to its default type. The predeclared untyped value nil cannot be used as a switch expression. The switch expression type must be comparable. In this paragraph, “switc … | Continue reading


@boldlygo.tech | 10 days ago

Expression switches

Expression switches In an expression switch, the switch expression is evaluated and the case expressions, which need not be constants, are evaluated left-to-right and top-to-bottom; the first one that equals the switch expression triggers execution of the statements of the associ … | Continue reading


@boldlygo.tech | 11 days ago

Switch statements

Yesterday we looked at if statements, which allows conditional execution of two branches. And we saw how by chaining else if we can extend that to an arbitrary number of branches. But there’s often a cleaner way to handle multiple branches: Switch statements “Switch” statements p … | Continue reading


@boldlygo.tech | 13 days ago

If statements

Today I’ll be live coding again. I hope you can join, and ask your Go-related questions as I continue to hack away on my open-source project, using TDD. Catch the stream on YouTube. Have you ever tried to explain an “if” statement in as few words as possible? It’s such a simple c … | Continue reading


@boldlygo.tech | 14 days ago

Assignability in Assignments

It hardly needs to be stated that in an assignment, a value must be assignable, but here we are… Assignment statements … In assignments, each value must be assignable to the type of the operand to which it is assigned… We’ve already talked about assignability, so we won’t go into … | Continue reading


@boldlygo.tech | 17 days ago

Assignment order

We’ve already talked about the order of evaluation in Go. And while that’s perfectly relevant here, it’s only one piece of the puzzle when it comes to ordering with assignment operations: Assignment statements … The assignment proceeds in two phases. First, the operands of index … | Continue reading


@boldlygo.tech | 18 days ago

Tuple assignments

Yesterday (as well as in earlier emails) I mentioned multiple-assignments in a single statement. Today we see how they’re defined to work. As such, there’s not really an new material here, but we’ll cover it just the same. Assignment statements … A tuple assignment assigns the in … | Continue reading


@boldlygo.tech | 19 days ago

I'm back!

Sorry for going silent without warning. I took a holiday, and due to a technical snafu, failed to send the announcement, so you’d know not to expect emails from me for a week and a half. Anyway, I’m back now… Let’s jump back into our tour through assignment statments, with an exp … | Continue reading


@boldlygo.tech | 1 month ago

Assignment statements

Assignment statements An assignment replaces the current value stored in a variable with a new value specified by an expression. Assignments should be familiar to you. They’re pretty fundamental to almost all programming languages. But there are a few aspects to Go’s assignments … | Continue reading


@boldlygo.tech | 1 month ago

IncDec statements

IncDec statements The “++” and “–” statements increment or decrement their operands by the untyped constant 1. As with an assignment, the operand must be addressable or a map index expression. IncDecStmt = Expression ( "++" | "--" ) . Most commonly you’ll see ++ and -- used on a … | Continue reading


@boldlygo.tech | 1 month ago

Send statements

Send statements A send statement sends a value on a channel. The channel expression’s core type must be a channel, the channel direction must permit send operations, and the type of the value to be sent must be assignable to the channel’s element type. SendStmt = Channel "<-" Exp … | Continue reading


@boldlygo.tech | 1 month ago

Expression statements

No livestream today. I wasn’t feeling well enough. No live stream next week either, as I’ll be traveling. Expression statements With the exception of specific built-in functions, function and method calls and receive operations can appear in statement context. Such statements may … | Continue reading


@boldlygo.tech | 1 month ago

Labeled statements

Today we’ll talk about labeled statements, which we’ve just recently mentioned in the context of terminating statements. Labeled statements A labeled statement may be the target of a goto, break or continue statement. LabeledStmt = Label ":" Statement . Label = identifier . Error … | Continue reading


@boldlygo.tech | 1 month ago

Labeled statements

Today we’ll talk about labeled statements, which we’ve just recently mentioned in the context of terminating statements. Labeled statements A labeled statement may be the target of a goto, break or continue statement. LabeledStmt = Label ":" Statement . Label = identifier . Error … | Continue reading


@boldlygo.tech | 1 month ago

Empty statements

Empty statements The empty statement does nothing. EmptyStmt = . I don’t think there’s much to say here. I suppose we could spend some time debating if/when an empty statement exists in our code. How many empty statements in the following? Is it one? Zero? An infinite number? How … | Continue reading


@boldlygo.tech | 1 month ago

Terminating statements conclusion

So we’ve made it through the list of 8 types of terminating statements. We conclude this section with a couple additional comments: Terminating statements … All other statements are not terminating. A statement list ends in a terminating statement if the list is not empty and its … | Continue reading


@boldlygo.tech | 1 month ago

Terminating labeled statements

Today’s live stream is starting an hour later than usual. Join me at 16:00, CEST, for some live Go coding using TDD. Terminating statements … A labeled statement labeling a terminating statement. Labeled statement’s are not used a lot in Go. Terminating labeled statements even le … | Continue reading


@boldlygo.tech | 1 month ago

Terminating select statements

Terminating statements … A “select” statement in which: there are no “break” statements referring to the “select” statement, and the statement lists in each case, including the default if present, end in a terminating statement. This is quite similar to the “switch” case we looke … | Continue reading


@boldlygo.tech | 1 month ago

Terminating switch statements

Terminating statements … A “switch” statement in which: there are no “break” statements referring to the “switch” statement, there is a default case, and the statement lists in each case, including the default, end in a terminating statement, or a possibly labeled “fallthrough” s … | Continue reading


@boldlygo.tech | 1 month ago

Terminating for loops

Terminating statements … A “for” statement in which: there are no “break” statements referring to the “for” statement, and the loop condition is absent, and the “for” statement does not use a range clause. Put another way, a for statement is terminating if it either never ends (a … | Continue reading


@boldlygo.tech | 1 month ago

Terminating if statements

Last week we saw that a block that ends in a terminaging statement is itself a terminating statement. Today we expand a bit on that idea: Terminating statements … An “if” statement in which: the “else” branch is present, and both branches are terminating statements. In other word … | Continue reading


@boldlygo.tech | 1 month ago

Happy April Fool's Day

I’ll be streaming some live coding again, on this April Fool’s day. No joke. I hope you’ll join me. It’s April Fool’s day. And I also recently learned of #AprilCools – the idea of doing something off-topic, but serious, rather than cringey on April first. So this year, I, eh… ext … | Continue reading


@boldlygo.tech | 1 month ago

Terminating blocks

Terminating statements … A block in which the statement list ends in a terminating statement. What exactly does this mean? It means that if you have an (explicit) code block that ends in a terminating statement, the block itself is considered a terminating statement. Confused? Ho … | Continue reading


@boldlygo.tech | 1 month ago

Don't panic!

Later today, at 15:00 UTC, I’ll be joining Denis Čahuk and Adrian Stanek on their regular Livestream, Our Tech Journey, to talk about TDD, Go, and do some live coding. Join us! The second in our list of terminating statements is… panic! Terminating statements … A call to the buil … | Continue reading


@boldlygo.tech | 1 month ago

Terminating statements

Terminating statements A terminating statement interrupts the regular flow of control in a block. The following statements are terminating: A “return” or “goto” statement. The return statement should be familiar to virtually everyone. And the fact that it interrupts the regular f … | Continue reading


@boldlygo.tech | 1 month ago

Statements

At long last, we have completed the section of the spec on expressions… and now we move on to: Statements Statements control execution. Statement = Declaration | LabeledStmt | SimpleStmt | GoStmt | ReturnStmt | BreakStmt | ContinueStmt | GotoStmt | FallthroughStmt | Block | IfStm … | Continue reading


@boldlygo.tech | 1 month ago

Order of evaluation and floating point numbers

Today I’ll be live streaming again! This time, picking up where we left off last week, and adding another feature to my new Go code rewriter and simplifier. Join me! Order of Evaluation … Floating-point operations within a single expression are evaluated according to the associat … | Continue reading


@boldlygo.tech | 1 month ago

Initialization dependencies

Here’s a thing you’ve likely never thought about: What if you have a compound assignment statement, where one of the variables depends on the other in the same statement. That’s what we’re looking at today. Order of Evaluation … At package level, initialization dependencies overr … | Continue reading


@boldlygo.tech | 1 month ago

Unordered evaluation

Yesterday’s spec quote included a sentence we breezed over. Today we’re going to dig in a bit more: Order of Evaluation … the order of those events compared to the evaluation and indexing of x and the evaluation of y and z is not specified, except as required lexically. What exac … | Continue reading


@boldlygo.tech | 2 months ago

Order of Evaluation

Let’s talk about… the order of evaluation! You might think you have a strong grasp on this concept, but many languages have their own nuanced take on evaluation order in some cases. And then JavaScript has “hoisting”, which kinda spits in the face of order of evaluation. Before w … | Continue reading


@boldlygo.tech | 2 months ago

Constant expressions, part III

Did you miss yesterday’s Ask-me-anything session? You probably did. I had about 10-15 people there. But even with a small group, we had a ton of great questions! The Q&A session lasted about an hour, and covered topics such as book recommendations for going deeper into Go, what p … | Continue reading


@boldlygo.tech | 2 months ago

Constant expressions, continued

Today I’ll be answering your questions on my weekly live stream. Have a question about Go? About CI/CD? About my favorite pizza toppings? Join me! Or submit your question early and catch the replay, if you can’t join live. Today we continue the section on Constant expressions, wi … | Continue reading


@boldlygo.tech | 2 months ago

Constant expressions

We made it through all the conversion rules! Let’s change gear and talk about… Constant expressions Constant expressions may contain only constant operands and are evaluated at compile time. Or framed differently: Any expression that contains non-constant operands, is not a const … | Continue reading


@boldlygo.tech | 2 months ago

Conversions from slice to array or array pointer

Conversions to and from a string type …Converting a slice to an array yields an array containing the elements of the underlying array of the slice. Similarly, converting a slice to an array pointer yields a pointer to the underlying array of the slice. In both cases, if the lengt … | Continue reading


@boldlygo.tech | 2 months ago

Converting integers to strings

Sorry I missed yesterday. The family road trip ended later than expected, and I was too shot to write anything. Conversions to and from a string type … Finally, for historical reasons, an integer value may be converted to a string type. This form of conversion yields a string con … | Continue reading


@boldlygo.tech | 2 months ago

Converting slices to byte or rune slices

No livestream today, as I’m traveling with my family. See you next week! Conversions to and from a string type … Converting a value of a string type to a slice of bytes type yields a non-nil slice whose successive elements are the bytes of the string. []byte("hellø") // []byte{&# … | Continue reading


@boldlygo.tech | 2 months ago

Converting rune slices to strings

Yesterday we started through the list of rules and special cases for converting to and from string types. Let’s continue… Conversions to and from a string type … Converting a slice of runes to a string type yields a string that is the concatenation of the individual rune values c … | Continue reading


@boldlygo.tech | 2 months ago

Conversions to and from a string type

Before I dive in to today’s spec discussion… are you enjoying this series? If so, would you do me a favor and help spread the word? Can you share a link to this message with a fellow Gopher, or on your work chat? Conversion to and from string types is a minefield of special cases … | Continue reading


@boldlygo.tech | 2 months ago

Conversions between numeric types

So we’ve gone through the high-level conversion stuff… now we dive into some particulars. Today, numeric conversions.Conversions between numeric types For the conversion of non-constant numeric values, the following rules apply:When converting between integer types, if the value … | Continue reading


@boldlygo.tech | 2 months ago

Type Conversion & struct tgs

We’ve already mentioned that struct tags are ignored when doing conversion between struct types. Now we see where that’s defined, along with an example:Conversions …Struct tags are ignored when comparing struct types for identity for the purpose of conversion:type Person struct { … | Continue reading


@boldlygo.tech | 2 months ago

Conversion of type parameters

Today I’ll be live-streaming again, doing TDD on an open-source project. I hope you can join! Conversions … Additionally, if T or x’s type V are type parameters, x can also be converted to type T if one of the following conditions applies: Both V and T are type parameters and a v … | Continue reading


@boldlygo.tech | 2 months ago

Non-constant conversions, part 2

Today we’ll finish the list of non-constant conversion rules that don’t relate to type parameters. Conversions … x’s type and T are both integer or floating point types. x’s type and T are both complex types. x is an integer or a slice of bytes or runes and T is a string type. x … | Continue reading


@boldlygo.tech | 2 months ago