📙
Word count code feedback
Think of the feedback below as PR comments on your code. I have reviewed word count implementation written by many developers and condensed my common PR comments below. When you implement wc in Go, these are some things you should look into. These will help you evaluate whether your solution is good enough.
Argument Parsing and configuration
How are you parsing the CLI arguments? Are you parsing them manually by doing string splitting and using a giant switch case statement? If yes, then please use either
flag.Args()
from Golang standard library or Cobra. Go is suitable for writing CLI applications and supports typical tasks like parsing flags and arguments passed to the command. Make use of these packages and refactor your code accordingly. When you use Cobra, it will force a certain structure to your code. Read more about Cobra documentation and samples to find out. By the way, Docker, Kubernetes, and many other tools use Cobra for parsing arguments. When in doubt, for real-world projects, use Cobra.
How do you represent flags passed to the wc command inside your code? Have you considered centralizing the three flags (-l, -w and -c) in a struct called
WcFlags
? If you centralize all the flags in a single struct, you can easily pass that struct to the internal method instead of passing each of the flags (booleans) as separate parameters. Refactor your code to use a centralized config struct to represent all configuration options of the wc command.
Ideally, you should have a function that parses all arguments and converts them into an internal
WcFlags
struct that you can pass to other methods. Otherwise, you’ll end up withwordCount
method with multiple arguments for the wc command options.
Argument Parsing and configuration
How are you parsing the CLI arguments? Are you parsing them manually by doing string splitting and using a giant switch case statement? If yes, then please use either
flag.Args()
from Golang standard library or Cobra. Go is suitable for writing CLI applications and supports typical tasks like parsing flags and arguments passed to the command. Make use of these packages and refactor your code accordingly. When you use Cobra, it will force a certain structure to your code. Read more about Cobra documentation and samples to find out. By the way, Docker, Kubernetes, and many other tools use Cobra for parsing arguments. When in doubt, for real-world projects, use Cobra.
How do you represent flags passed to the wc command inside your code? Have you considered centralizing the three flags (-l, -w and -c) in a struct called
WcFlags
? If you centralize all the flags in a single struct, you can easily pass that struct to the internal method instead of passing each of the flags (booleans) as separate parameters. Refactor your code to use a centralized config struct to represent all configuration options of the wc command.
Ideally, you should have a function that parses all arguments and converts them into an internal
WcFlags
struct that you can pass to other methods. Otherwise, you’ll end up withwordCount
method with multiple arguments for the wc command options.
Argument Parsing and configuration
How are you parsing the CLI arguments? Are you parsing them manually by doing string splitting and using a giant switch case statement? If yes, then please use either
flag.Args()
from Golang standard library or Cobra. Go is suitable for writing CLI applications and supports typical tasks like parsing flags and arguments passed to the command. Make use of these packages and refactor your code accordingly. When you use Cobra, it will force a certain structure to your code. Read more about Cobra documentation and samples to find out. By the way, Docker, Kubernetes, and many other tools use Cobra for parsing arguments. When in doubt, for real-world projects, use Cobra.
How do you represent flags passed to the wc command inside your code? Have you considered centralizing the three flags (-l, -w and -c) in a struct called
WcFlags
? If you centralize all the flags in a single struct, you can easily pass that struct to the internal method instead of passing each of the flags (booleans) as separate parameters. Refactor your code to use a centralized config struct to represent all configuration options of the wc command.
Ideally, you should have a function that parses all arguments and converts them into an internal
WcFlags
struct that you can pass to other methods. Otherwise, you’ll end up withwordCount
method with multiple arguments for the wc command options.
Argument Parsing and configuration
How are you parsing the CLI arguments? Are you parsing them manually by doing string splitting and using a giant switch case statement? If yes, then please use either
flag.Args()
from Golang standard library or Cobra. Go is suitable for writing CLI applications and supports typical tasks like parsing flags and arguments passed to the command. Make use of these packages and refactor your code accordingly. When you use Cobra, it will force a certain structure to your code. Read more about Cobra documentation and samples to find out. By the way, Docker, Kubernetes, and many other tools use Cobra for parsing arguments. When in doubt, for real-world projects, use Cobra.
How do you represent flags passed to the wc command inside your code? Have you considered centralizing the three flags (-l, -w and -c) in a struct called
WcFlags
? If you centralize all the flags in a single struct, you can easily pass that struct to the internal method instead of passing each of the flags (booleans) as separate parameters. Refactor your code to use a centralized config struct to represent all configuration options of the wc command.
Ideally, you should have a function that parses all arguments and converts them into an internal
WcFlags
struct that you can pass to other methods. Otherwise, you’ll end up withwordCount
method with multiple arguments for the wc command options.
Argument Parsing and configuration
How are you parsing the CLI arguments? Are you parsing them manually by doing string splitting and using a giant switch case statement? If yes, then please use either
flag.Args()
from Golang standard library or Cobra. Go is suitable for writing CLI applications and supports typical tasks like parsing flags and arguments passed to the command. Make use of these packages and refactor your code accordingly. When you use Cobra, it will force a certain structure to your code. Read more about Cobra documentation and samples to find out. By the way, Docker, Kubernetes, and many other tools use Cobra for parsing arguments. When in doubt, for real-world projects, use Cobra.
How do you represent flags passed to the wc command inside your code? Have you considered centralizing the three flags (-l, -w and -c) in a struct called
WcFlags
? If you centralize all the flags in a single struct, you can easily pass that struct to the internal method instead of passing each of the flags (booleans) as separate parameters. Refactor your code to use a centralized config struct to represent all configuration options of the wc command.
Ideally, you should have a function that parses all arguments and converts them into an internal
WcFlags
struct that you can pass to other methods. Otherwise, you’ll end up withwordCount
method with multiple arguments for the wc command options.
Code formatting and tooling
Code formatting and tooling
Code formatting and tooling
Code formatting and tooling
Code formatting and tooling
Unit testing and error handling
Unit testing and error handling
Unit testing and error handling
Unit testing and error handling
Unit testing and error handling
Power of interfaces
Power of interfaces
Power of interfaces
Power of interfaces
Power of interfaces
Performance (when running wc on many large files)
Performance (when running wc on many large files)
Performance (when running wc on many large files)
Performance (when running wc on many large files)
Performance (when running wc on many large files)
Handling Results
Handling Results
Handling Results
Handling Results
Handling Results
Others (Misc)
Others (Misc)
Others (Misc)
Others (Misc)
Others (Misc)