uvic-auvic / RedHerring

Red Herring Project Code
1 stars 6 forks source link

Added read-config.cpp which reads and parses config files Fixes #17 #108

Closed adaln closed 7 years ago

adaln commented 7 years ago

Draft of config parser. Problems with finding ";" (lines 45-94)

asinha94 commented 7 years ago

So Good job so far, you did manage to get most of the way there, I just have a couple of comments.

General Code Structure

So you see above the 2nd while loop you have big list of variables (Line 21-31). those are called flag variables and are generally considered not great practice for a few reasons. The main one being that flags keep track of some kind of state and as your program grows, so do the number of states and the ability to debug gets really difficult. In this case our program probably won't be extended that much, but even as-is we can both see it's a bit hard to debug.

So I think it's probably worth re-writing the structure of a few sections/applying a bit different logic.

New Structure (inside the first while loop)

Flags

So we can't get rid of all flag variables but I think we should limit it to 2-3 max. Those being beginning and end (which we will use as iterators which you can do a lot more with).

auto begin = str.begin(); auto end = str.end();

Structure (i.e. what order we should parse in)

So doing it that way eliminates all those variables (expect begin and end) and the need for 2nd loop. I may have forgotten a few things, so feel free to modify this structure as needed

Pedantic stuff

}

else {

}


because the 2nd else can be condfused for an if, if you are skimming
- Make sure you're indentation is all in-sync e.g line 20-21 are indented for some reason.

- So you kinda have a spaces mixed up with tabs there. It doens't really matter which ones you use, but Im not a fan of tabs. They always look weird in the editors I use. So if you could replace them with spaces that would be appreciated. You can do that in gedit by `search->replace` and searching for `\t` and replacing with a space

# Other Stuff
- Make sure you compile with c++11
- Store everything as a string. dont try and convert it.
- I wasn't sure about which map would be best, but if you want to then you can research on it. What we are looking for is something that has fast reads more than anything else. I think hashmap has the best running time `O(1)` but it doesn't really matter
adaln commented 7 years ago

I made the changes you suggested and now the code seems to do what it's supposed to. The config map stores the key and value together - the only problem that may occur is if a key has 2 values in the config file, one of the values may get overwritten. I couldn't remember if you had mentioned adding a CMakeList file or something else but anyway I made a basic CMakeList.txt file just in case. Sorry it took so long to put together, let me know if there are any other changes that need to be made!

asinha94 commented 7 years ago

Looks a lot better. Just a few minor things I need you to fix

  1. Your code asks for a filename but then just uses the name "Read.txt" file anyway (line 12), so just fix that up.
  2. Remove all the print statements that aren't errors (Lines 19, 37, 72)
  3. Pedantic but It really bugs me, replace the double spaces with 4 spaces. If you use gedit you can do that with a find and replace (replace " " with " "). This might double a few other spaces so just fix those up.

Other than that looks good to go. thanks!

adaln commented 7 years ago

Fixed the things and added error checking of the file name input. Hopefully good to go now!

asinha94 commented 7 years ago

Perfect. Thanks!

asinha94 commented 7 years ago

Also remember you have to rebase your repo/clone again. Its a weird thing with Github how because I technically merged your code into this repo, your repo is missing this merge, even though you have all the same code. So just rebase your clone with this again

asinha94 commented 7 years ago

closes #17