Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Conversation

@akutz
Copy link
Contributor

@akutz akutz commented Jul 18, 2022

This patch adds support for specifying the guest operating system's ID and family.


package v1alpha1

// VirtualMachineGuestOSDescriptor is used to specify information about the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental deletion of text?


const (
VirtualMachineGuestOSFamilyWindows VirtualMachineGuestOSFamily = "windowsGuest"
VirtualMachineGuestOSFamilyLinux = "linuxGuest"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to specify VirtualMachineGuestOSFamily type for all these consts, or is this Golang magic that automatically assigns them the types? Either way, I would vote for being explicit in the name of readability. (Same for Guest OS Identifiers)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not. I actually think repeating it makes it harder to follow. Go supports implicit typing in const blocks by referring to the last, non-empty, explicit type in that local const block. It is how iota and enums work in Go.

I'm tired of you being right so much lately 😃 The above is what I was going to say, and then I decided to triple-check. It turns out all the blogs I've ever read about iota get typing wrong. The above language spec refrence never states that types are implicit from the previous, non-empty type in the local const block. I even verified this in this Go playground:

package main

import "fmt"

type myEnumType string

const (
	typedHello myEnumType = "hello"
	typedWorld            = "world"
)

const (
	untypedHello = "hello"
	untypedWorld = "world"
)

func main() {
	fmt.Printf("%[1]T=%[1]s\n", typedHello)
	fmt.Printf("%[1]T=%[1]s\n", typedWorld)
	fmt.Printf("%[1]T=%[1]s\n", untypedHello)
	fmt.Printf("%[1]T=%[1]s\n", untypedWorld)
}

I expected the first two lines of output to indicate the type was main.myEnumType, but...

main.myEnumType=hello
string=world
string=hello
string=world

So yeah, I'll add it. Obviously 😃

p.s. 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-D
I actually tried this in playground by checking the type of two consts, before leaving the comment. I still thought you knew something that I didn't about Golang internals (as you often do).

This patch adds support for specifying the guest operating
system's ID and family.
@akutz akutz force-pushed the feature/vmguestdescriptor branch from dc9e91b to fe7838f Compare July 18, 2022 20:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants