Syntax of functions...unc (receiver) identifier(parameters) (returns) { code }

The format specifier. It’s the first required argument of type string. It describes how the other arguments shall be formatted. The syntax of the specifier is described in the packages documentation.

An error that can happen when writing into a file.

3 Likes

So in:
func Printf(format string, a …interface{}) (n int, err error)
is n int the format specifier? Looks like the first argument.
Please forgive my ignorance.
I spent 27 minutes just forming this question

2 Likes

No, as it is neither of:

  • string
  • an argument

format is the first required argument of fmt.Printf(), and it is of type string, so it is the format specifier.

It specifies the format that shall be applied on the optional arguments when printing, thats why its called like this.

n on the other hand is the first return value. In this case it is an int and tells you how many bytes have been written.

2 Likes

If we refer back to this example, @NobbZ refers to that "DEBUG: %s, the return value is %d.\n" string. Essentially, it its telling Printf how to form the final string I wanted to see.

                  name                    money
                   🡣                       🡣
fmt.Printf("DEBUG: %s, the return value is %d.\n", name, money)
2 Likes

So, is DEBUG: %s, the return value is %d.\n the first argument, or the format specifier? or is name? Or what? Sorry if I’m frustrating anyone.

2 Likes

If I replace the function as:

fmt.Printf("format specifier", verb1, ...)

Will that be clearer for you?


p/s: I think you need a break not to grasp too firm with the meta-definition. I sense a burn-out symptom. =(

1 Like

YES!

Does it necessarily have to be a string?

The word format has been shrouded in mystery for me ever since the days when we used to format discs and I had no clue what that meant.

The first definition I found
A format program is a type of software that prepares a disk for reading and writing data on a system.
Is this what we are talking about?

https://en.wikipedia.org › wiki › Programming_style

Interesting article written on my level.
Software has long been available that formats source code automatically, leaving coders to concentrate on naming, logic, and higher techniques. As a practical point, using a computer to format source code saves time,

Now I understand this.

Now I understand this.

1 Like

This is different’ thing and outside of scope. Similar to other threads, stay focus.

I would suggest you read through the thread and documentation again to answer this question.

1 Like

Words can have multiple meaning in distinct different contexts.

In case of “format” all of the meanings loosely follow the metaphor of making something fit into a given or expected shape.

Randomly searching the web for single words therefore rarely brings up what you need. Even if you narrow down a bit by adding “computer” to the search, thats not helping much.

And in this special case you already know the canonical source of truth, the documenation of gos fmt package (which is short for format).

This package has the purpose of formatting strings into the terminal, files, or other strings.

Not more, not less.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.