Closed adaln closed 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.
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.
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();
end = begin + find;
std::string substring(begin, end)
a;a;
anything smaller is either empty or invalid. If it is invalid fprintf()
an error message then continue
(i.e skip to the next while loop iteration).count
function included in <algorithm>
to find the number of semi-colons
int num_semicolons = std::count(begin, end)
if the number of semicolons is not equal to 2, then there's an error, so fprintf
and continue
again<map>
std::map<std::string, std::string> configs;
configs["key"]=key;
configs["value"]=value;
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
if (true) {
//stuff
} else {
// more stuff
}
This I feel is a bit easier to read than this
if () {
}
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
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!
Looks a lot better. Just a few minor things I need you to fix
Other than that looks good to go. thanks!
Fixed the things and added error checking of the file name input. Hopefully good to go now!
Perfect. Thanks!
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
closes #17
Draft of config parser. Problems with finding ";" (lines 45-94)