INDAPlus21 / INDAPlus21/melg-hash

Pass

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

**Very well done Marcus!**

I miss instructions! Your application also has some crasch tendensies:
```
PS C:\[...]\melg-hash> go run customdatabase
Loading database...
Loading database vales from file C:\[...]\melg-hash\data.data

Enter a command
LIST
panic: interface conversion: interface {} is string, not *main.HashTable

goroutine 1 [running]:
main.command_list(0xc000050370, 0x1, 0x1)
C:/Users/viola/Documents/INDA_2021/tasks/plus-hash/melg/melg-hash/customdatabase.go:152 +0x3d9
main.get_input()
C:/Users/viola/Documents/INDA_2021/tasks/plus-hash/melg/melg-hash/customdatabase.go:51 +0x36e
main.main()
C:/Users/viola/Documents/INDA_2021/tasks/plus-hash/melg/melg-hash/customdatabase.go:26 +0x9c
exit status 2
```

I also spot some code pattern duplication, necessary for user friendly application of course, for example:

_Your code_:
```go
func command_add(values []string) {
if /*...*/ {/*...*/} else {
name := default_database
if len(values) == 4 {
name = values[3]
_, ok := get_value_table(database, name)
if !ok {
fmt.Println("Invalid table name, there is no table with name", name)
return
}
}

//...
}
}

func command_remove(values []string) {
if /*...*/ {/*...*/} else {
name := default_database
if len(values) == 3 {
name = values[2]
_, ok := get_value_table(database, name)
if !ok {
fmt.Println("Invalid table name, there is no table with name", name)
return
}
}

//...
}
}

func command_get(values []string) {
if /*...*/ {/*...*/} else {
name := default_database
if len(values) == 3 {
name = values[2]
_, ok := get_value_table(database, name)
if !ok {
fmt.Println("Invalid table name, there is no table with name", name)
return
}
}

//...
}
}

func command_list(values []string) {
if /*...*/ {/*...*/} else {
name := default_database
if len(values) == 2 {
name = values[1]
_, ok := get_value_table(database, name)
if !ok {
fmt.Println("Invalid table name, there is no table with name", name)
return
}
}

//...
}
}
```

_Refactorised code_:
```go

func get_database(args []string, arg_i int) string {
name := default_database
if len(args) == arg_i {
name = args[arg_i - 1]
_, ok := get_value_table(database, name)
if !ok {
fmt.Println("Invalid table name, there is no table with name", name)
}
}
return name
}

func command_add(values []string) {
if /*...*/ {/*...*/} else {
name := get_database(values, 4)

//...
}
}

func command_remove(values []string) {
if /*...*/ {/*...*/} else {
name := get_database(values, 3)

//...
}
}

func command_get(values []string) {
if /*...*/ {/*...*/} else {
name := get_database(values, 3)

//...
}
}

func command_list(values []string) {
if /*...*/ {/*...*/} else {
name := get_database(values, 2)

//...
}
}
```

[![](https://inotgo.com/imagesLocal/202111/10/20211110140150158I_0.png.jpg)](https://insights.stackoverflow.com/survey/2021#section-top-paying-technologies-top-paying-technologies)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing `go run customdatabase`, then run `LIST` and inspect `customdatabase.go` around `command_list` line 152 and the input flow in `get_input`. Check how database values are loaded and typed before the lookup. Done means `LIST` no longer panics, missing usage instructions are addressed, and the repeated database-name validation is consolidated as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.