Code Suggestions / Improvements For Me

Background
Hello everyone! A few months ago (as well as more recently) I looked into a JSON parser for C++. In short, I found it too difficult and used an alternative solution thanks to dutch's comment here: http://www.cplusplus.com/forum/beginner/256646/. Note that I wrote my own code instead of using theirs.

Anyways, I've finally finished & improved upon some code that will basically look at JSON files then simplify them and output the new file data to new files in a particular directory.

Reason for This Post
Would anyone be willing to take a look at my code and tell me how I could improve for readability, organization, and performance? Please Note: I'm not looking for anything super complicated or completely different from my original code. I meant smaller improvements or if I was doing something that is bad practice, then pointing that out and why it is bad.

My Full Code can be seen here:
https://github.com/pinkpig3777/json_file_simplifier

Don't worry, it is only one file of actual code and that file is only 354 lines (much of which is comments). I provided the link because it also allows you to view the main page which explains a bit about the program if you'd like to know more about what it is intended to do.


Thank you very much, for anyone who takes a look and gives suggestions! :)

Please Note: While I hope to reply within 24 hours, it may take me a few days to reply depending how busy I am.
Last edited on
obviously ...
printInstructionsAndGetInput() does two things. A function should do only one thing.
openFiles() Does not open files. It iterate thou a directory. read and write files.
readInputFile() what does this function do? Hmmmmm It parse a json file?!
writeToOutputFile() yes ... write json as txt?

void writeToOutputFile(std::string &outputEntryStr < This variable should be const. It should be called "fileName".
The write function should not correct filename extension. The caller of the write() function should do this.

Don't use string manipulation on filenames. We have the std::filesystem; for this task. You know of std::filesystem because you already used it.

You forgot a const reference
1
2
for (std::string str : alphaNums) {
for (const std::string& str : alphaNums) {


There is no need for the {} part.
1
2
std::vector<std::string> alphaNums = {};
std::vector<std::string> alphaNums;


And lot more. But no worry, you did a great job. I had no problems to read your code and understand what it does :)
Thomas Huxhorn wrote:
obviously ...
printInstructionsAndGetInput() does two things. A function should do only one thing.
openFiles() Does not open files. It iterate thou a directory. read and write files.
readInputFile() what does this function do? Hmmmmm It parse a json file?!
writeToOutputFile() yes ... write json as txt?

void writeToOutputFile(std::string &outputEntryStr < This variable should be const. It should be called "fileName".
The write function should not correct filename extension. The caller of the write() function should do this.

Don't use string manipulation on filenames. We have the std::filesystem; for this task. You know of std::filesystem because you already used it.

You forgot a const reference

1
2



for (std::string str : alphaNums) {
for (const std::string& str : alphaNums) {




There is no need for the {} part.

1
2



std::vector<std::string> alphaNums = {};
std::vector<std::string> alphaNums;




And lot more. But no worry, you did a great job. I had no problems to read your code and understand what it does :)

Thanks for the feedback and kind words. :) I will make the changes you mentioned!
Registered users can post here. Sign in or register to post.