mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-17 10:41:17 +00:00
first
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"question": "Why would you name your interface's method's parameters?",
|
||||
"answers": [
|
||||
"Readability and clarity",
|
||||
"Execution speed",
|
||||
"Memory savings"
|
||||
]
|
||||
}
|
||||
23
course/5-interfaces/exercises/6a-naming_args/readme.md
Normal file
23
course/5-interfaces/exercises/6a-naming_args/readme.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Name Your Interface Arguments
|
||||
|
||||
Consider the following interface:
|
||||
|
||||
```go
|
||||
type Copier interface {
|
||||
Copy(string, string) int
|
||||
}
|
||||
```
|
||||
|
||||
Based on the code alone, can you deduce what *kinds* of strings you should pass into the `Copy` function?
|
||||
|
||||
We know the function signature expects 2 string types, but what are they? Filenames? URLs? Raw string data? For that matter, what the heck is that `int` that's being returned?
|
||||
|
||||
Let's add some named arguments and return data to make it more clear.
|
||||
|
||||
```go
|
||||
type Copier interface {
|
||||
Copy(sourceFile string, destinationFile string) (bytesCopied int)
|
||||
}
|
||||
```
|
||||
|
||||
Much better. We can see what the expectations are now. The first argument is the `sourceFile`, the second argument is the `destinationFile`, and `bytesCopied`, an integer, is returned.
|
||||
Reference in New Issue
Block a user