Services

Resources

Company

🌲

Tree code feedback

Think of the feedback below as PR comments on your code. I have reviewed the Tree implementation written by many developers and condensed my common PR comments below. When you implement tree 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 eitherflag.Args() from Golang standard library or Cobra. Go is suitable for writing CLI applications and provides good support for 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 tree command inside your code? Have you thought about centralizing various flags in a struct called TreeConfig? If you centralize all the flags in a single struct, you can easily pass that struct to the tree method instead of passing each of the flags as separate parameters. Refactor your code to use a centralized config struct to represent all configuration options of the tree command.

  • Ideally, you should have a function that parses all arguments and converts them into an internal TreeConfig struct that you can pass to other methods. Otherwise, you’ll end up with tree method with multiple arguments for tree command options (-f, -d, -L, -t, etc)

  • The TreeConfig struct should contain bool and ints as data type for the fields in it (to represent whether to print only directories, how many levels to print, etc). If you use just raw strings, you’re not creating an abstraction and might as well not create this struct.

  • Create value as boundaries. Watch https://www.destroyallsoftware.com/talks/boundaries this talk to understand more. Datatypes should be close and accurate, e.g., bool in TreeConfig. There should be two separate structs - one for representing TreeConfig internally (via bool and int) and the other for representing how we accept CLI args for tree, e.g., TreeArgs. TreeArgs struct should have short and long descriptions of the arg as a string property.

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 eitherflag.Args() from Golang standard library or Cobra. Go is suitable for writing CLI applications and provides good support for 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 tree command inside your code? Have you thought about centralizing various flags in a struct called TreeConfig? If you centralize all the flags in a single struct, you can easily pass that struct to the tree method instead of passing each of the flags as separate parameters. Refactor your code to use a centralized config struct to represent all configuration options of the tree command.

  • Ideally, you should have a function that parses all arguments and converts them into an internal TreeConfig struct that you can pass to other methods. Otherwise, you’ll end up with tree method with multiple arguments for tree command options (-f, -d, -L, -t, etc)

  • The TreeConfig struct should contain bool and ints as data type for the fields in it (to represent whether to print only directories, how many levels to print, etc). If you use just raw strings, you’re not creating an abstraction and might as well not create this struct.

  • Create value as boundaries. Watch https://www.destroyallsoftware.com/talks/boundaries this talk to understand more. Datatypes should be close and accurate, e.g., bool in TreeConfig. There should be two separate structs - one for representing TreeConfig internally (via bool and int) and the other for representing how we accept CLI args for tree, e.g., TreeArgs. TreeArgs struct should have short and long descriptions of the arg as a string property.

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 eitherflag.Args() from Golang standard library or Cobra. Go is suitable for writing CLI applications and provides good support for 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 tree command inside your code? Have you thought about centralizing various flags in a struct called TreeConfig? If you centralize all the flags in a single struct, you can easily pass that struct to the tree method instead of passing each of the flags as separate parameters. Refactor your code to use a centralized config struct to represent all configuration options of the tree command.

  • Ideally, you should have a function that parses all arguments and converts them into an internal TreeConfig struct that you can pass to other methods. Otherwise, you’ll end up with tree method with multiple arguments for tree command options (-f, -d, -L, -t, etc)

  • The TreeConfig struct should contain bool and ints as data type for the fields in it (to represent whether to print only directories, how many levels to print, etc). If you use just raw strings, you’re not creating an abstraction and might as well not create this struct.

  • Create value as boundaries. Watch https://www.destroyallsoftware.com/talks/boundaries this talk to understand more. Datatypes should be close and accurate, e.g., bool in TreeConfig. There should be two separate structs - one for representing TreeConfig internally (via bool and int) and the other for representing how we accept CLI args for tree, e.g., TreeArgs. TreeArgs struct should have short and long descriptions of the arg as a string property.

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 eitherflag.Args() from Golang standard library or Cobra. Go is suitable for writing CLI applications and provides good support for 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 tree command inside your code? Have you thought about centralizing various flags in a struct called TreeConfig? If you centralize all the flags in a single struct, you can easily pass that struct to the tree method instead of passing each of the flags as separate parameters. Refactor your code to use a centralized config struct to represent all configuration options of the tree command.

  • Ideally, you should have a function that parses all arguments and converts them into an internal TreeConfig struct that you can pass to other methods. Otherwise, you’ll end up with tree method with multiple arguments for tree command options (-f, -d, -L, -t, etc)

  • The TreeConfig struct should contain bool and ints as data type for the fields in it (to represent whether to print only directories, how many levels to print, etc). If you use just raw strings, you’re not creating an abstraction and might as well not create this struct.

  • Create value as boundaries. Watch https://www.destroyallsoftware.com/talks/boundaries this talk to understand more. Datatypes should be close and accurate, e.g., bool in TreeConfig. There should be two separate structs - one for representing TreeConfig internally (via bool and int) and the other for representing how we accept CLI args for tree, e.g., TreeArgs. TreeArgs struct should have short and long descriptions of the arg as a string property.

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

Performance and core recursive walking logic

Performance and core recursive walking logic

Performance and core recursive walking logic

Performance and core recursive walking logic

Handling JSON, XML, and normal tree printing

Handling JSON, XML, and normal tree printing

Handling JSON, XML, and normal tree printing

Handling JSON, XML, and normal tree printing

Others (Misc)

Others (Misc)

Others (Misc)

Others (Misc)