Remove menu selector based switch statement in SetLanguage #5

Closed
opened 2024-08-29 16:24:31 +02:00 by lash · 3 comments
Owner

One should never switch on menu selectors in aux code, because the VM code and the aux function will have to be manually synced.

Instead use dedicated VM nodes, and e.g. use the sym name to decide the case. In this case perhaps; setlang_default setlang_swa and string split _ use idx 1.

One should never switch on menu selectors in aux code, because the VM code and the aux function will have to be manually synced. Instead use dedicated VM nodes, and e.g. use the sym name to decide the case. In this case perhaps; setlang_default setlang_swa and string split _ use idx 1.
lash added the
Priority
High
label 2024-08-29 16:24:31 +02:00
lash added the
smell
label 2024-08-29 16:26:17 +02:00
Alfred-mk added a new dependency 2024-09-17 14:34:40 +02:00
Member

Does this change work towards solving the code smell?

func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
sym, _ = h.st.Where()
code := strings.Split(sym, "_")[1]
switch code {
case "default":
	res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
	res.Content = "eng"
case "swa":
	res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
	res.Content = "swa"
default:
}

languageSetFlag, err := h.flagManager.GetFlag("flag_language_set")
if err != nil {
	return res, err
}
res.FlagSet = append(res.FlagSet, languageSetFlag)

return res, nil
Does this change work towards solving the code smell? func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result sym, _ = h.st.Where() code := strings.Split(sym, "_")[1] switch code { case "default": res.FlagSet = append(res.FlagSet, state.FLAG_LANG) res.Content = "eng" case "swa": res.FlagSet = append(res.FlagSet, state.FLAG_LANG) res.Content = "swa" default: } languageSetFlag, err := h.flagManager.GetFlag("flag_language_set") if err != nil { return res, err } res.FlagSet = append(res.FlagSet, languageSetFlag) return res, nil
Author
Owner

@carlos yes the whole issue is about the case criteria, they shouldnt be the selectors used for input. case "default" for example looks fine.

@carlos yes the whole issue is about the case criteria, they shouldnt be the selectors used for input. `case "default"` for example looks fine.
Author
Owner

done

done
lash closed this issue 2024-10-07 16:13:47 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Depends on
Reference: urdt/ussd#5
No description provided.