Blef-team / blef_game_engine

The game engine API service for the game of Blef
GNU Affero General Public License v3.0
1 stars 0 forks source link

Refactor code so that checks for errors do not indent the rest of the code #61

Closed maciej-pomykala closed 4 years ago

maciej-pomykala commented 4 years ago

Current if and else statements reduce clarity

adrian-golian commented 4 years ago

Instead of this:

if (!checkA & !checkB & !checkC) {
  core function code
}
else if (checkA)  errorA
else if (checkB) errorB
else if (checkC) errorC

do

if (checkA) errorA
if (checkB) errorB
if (checkC) errorC
core function code

_Originally posted by @adrian-golian in https://github.com/Blef-team/blef_game_engine/pull/60#issuecomment-615933859_

adrian-golian commented 4 years ago

Btw, there are some weird things happening in https://github.com/Blef-team/blef_game_engine/blob/9cc0062754d68e0353b2a80e4e8c5e4498eae475/api/endpoints.R#L164

    game_path <- get_path(game_uuid)

    if(file.exists(game_path)) {
      current_r <- readRDS(game_path)$round_number
      if (round == -1 | round == current_r) {
        r <- current_r
        game <- readRDS(get_path(game_uuid))
      } else {
        r <- as.numeric(round)
        game <- readRDS(get_path(game_uuid, r))
      }

Why assign game_path when you're not using it. You can just do file.exists(get_path(game_uuid))

maciej-pomykala commented 4 years ago

From what I udnerstand, you would have been pleased to look at this commit

Edit: the commit changes the join endpoint, I'll do the same thing for the state endpoint and the other endpoints