this post was submitted on 29 Jul 2026
15 points (77.8% liked)

Programming

27926 readers
105 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 3 years ago
MODERATORS
 

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)

you are viewing a single comment's thread
view the rest of the comments
[–] fruitcantfly@programming.dev 6 points 2 days ago* (last edited 2 days ago)

Here are a few random thoughts based on skimming the source:

  • I'd advice againsts using -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.
  • A couple of your check functions may reach the end of the function without returning, if type is not on of the expected values. That is undefined behavior. One simple way to avoid this, is to move the common return out of the ifs.
  • That const std::string type argument in the above functions should be enums, since you are just checking againts one of three fixed values ("name", "ext", and "date").
  • Speaking of which, I can't think of any situation where you'd want to have an const std::string argument. 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 new std::string if you call the function with a C-string and it can be sliced cheaply.
  • You have const std::string &df = df_str; in a couple of places, where df_str is a std::string passed by value. That is of course utterly pointless, and you should simply change df_str to be passed by const reference or as a string view.
  • You define main with an int return type, but use std::exit to exit the function. Those std::exit calls could all be replaced with return, which does the same thing in main.
  • Don't do work before you need the results. For example, in check_type you perform two checks (saved as starts_with_dot and has_dash), that are not used if name == "name".
  • Nobody who sees a function named check_exists would 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 in main.cpp via is_directory, but unlike that check check_exists doesn't actually verify that the path is a directory.
  • is_founded is Engrish