- cross-posted to:
- linux@lemmy.world
- cross-posted to:
- linux@lemmy.world
wrote CLI in C++ to sort files. it’s very simple, just download and use. if you a photographer, video editor or just need to sort some files, you welcome (link in post)
wrote CLI in C++ to sort files. it’s very simple, just download and use. if you a photographer, video editor or just need to sort some files, you welcome (link in post)
Here are a few random thoughts based on skimming the source:
-Weverything. Many of the warnings it enables are not very useful, and you are going to get a lot of them. And if you enable warnings, then fix them, or you’ll just miss it when your changes cause new warnings.typeis not on of the expected values. That is undefined behavior. One simple way to avoid this, is to move the commonreturnout of the ifs.const std::string typeargument in the above functions should be enums, since you are just checking againts one of three fixed values ("name","ext", and"date").const std::stringargument. Either use a const reference (const std::string&) or a string_view (const std::string_view). The latter has the advantage that it doesn’t create a newstd::stringif you call the function with a C-string and it can be sliced cheaply.const std::string &df = df_str;in a couple of places, wheredf_stris astd::stringpassed by value. That is of course utterly pointless, and you should simply changedf_strto be passed by const reference or as a string view.mainwith anintreturn type, but usestd::exitto exit the function. Thosestd::exitcalls could all be replaced withreturn, which does the same thing inmain.check_typeyou perform two checks (saved asstarts_with_dotandhas_dash), that are not used ifname == "name".check_existswould expect it to create a directory, so it should be renamed to something more descriptive. It is also redundant, since you already check that the directory exists inmain.cppviais_directory, but unlike that checkcheck_existsdoesn’t actually verify that the path is a directory.is_foundedis Engrish