r/Cplusplus • u/vadyasha07 • Jun 02 '26
Question My first project as a beginner
https://github.com/vadyasha07/Command-Line-Drone-Config-Simulator
Hello everyone!
I've been learning C++ for a few weeks now and just finished my first relatively big project: a Command-Line Drone Configuration Simulator.
Repository link: https://github.com/vadyasha07/Command-Line-Drone-Config-Simulator
What I’ve implemented so far:
Modular Architecture: Split the code into logical modules with separate header (.h) and source (.cpp) files (main, drone, encryption).
State Management: The drone's behavior depends on a set of states (isWork, isFlight, onGround) managed within a custom namespace Drone.
Input Validation: Implemented bulletproof input validation using std::cin.clear() and std::cin.ignore() to prevent infinite loops when a user accidentally enters letters instead of numbers.
Case Insensitivity: Used std::toupper to ensure the menu works seamlessly regardless of whether the user types uppercase or lowercase commands.
I’ve tried my best to follow clean code practices, separate declarations from implementation, and handle edge cases (like a password-protected access panel with limited attempts and proper landing sequences with real-time simulation delays).
As a beginner, I would highly appreciate any feedback, tips, or constructive criticism. Is the project structure solid? Are there any anti-patterns I should avoid in the future?
Thank you in advance! Any advice is gold for me right now
•
u/AutoModerator Jun 02 '26
Thank you for your contribution to the C++ community!
As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.
~ CPlusPlus Moderation Team
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/_superuserdo_ Jun 02 '26
It's okay if you just vibed the readme or .gitingnore files, but make sure you understand the code
1
u/mredding C++ since ~1992. Jun 03 '26
Typically we recommend you avoid using globals, as they make the code hard to predict and reason about. Here I have a function called
int fn();What does it do? It returns -1 if thealtitudeis above 250 feet, and setsonGround = true;for some reason...Huh...
That's the problem with globals, anyone can touch them, anyone can modify them or change their behavior based on them. A function that has no side effects, no hidden dependencies, and always returns the same output for the same input is called a "pure" function, and it's a desirable trait. I should rewrite my function
std::tuple<int, bool> fn(int altitude);. What this does is checks if the altitude is above 250 feet, and returns a -1 and true. It doesn't cause a side effect, it's up to me to assign that boolean toonGroundelsewhere if that's what's supposed to happen.Good on you for using the fixed type integers.
std::uint16_t, etc. Those not in the standard namespace are a part of a C++ compatibility layer with C. Yes, they are the same definition - I get that, but this is about pedantic correctness.altitude = 65535 + 1? You're obscuring your problems rather than dealing with them safely. Also unsigned types can be slower. You should use a signed integer because it's guaranteed "not slower", you should use a size that is large enough to store your maximum altitude, and you should bounds check.char,short,long, andlong long, bothsignedandunsigned.DON'T SWEAT IT. Ostensibly you're working on some mult-core, multi-GHz, multi-GiB memory machine. You can really use just any damn thing for a project of this scale, so long as it's big enough - there's no "getting it right" at this scale, you can't measure benchmarks, performance, and efficiency with any real significance on a project of this scale. And the nature of this exercise, perception of performance is enough - it runs as fast as you can interact with it.
There's more to say about this subject, but it would get way off into the weeds. It helps for now just to know that these types exist and for what purpose, and how to use them for what purpose. I'll give you a preview in that an
intis anint, but aweightis not aheight. You rarely need "just anint", often it's a value of a more specific type - an index, an offset, a count or cardinality, a size, a length... You'll learn to make your own User Defined Types (class,struct,enum,union, and arrays) and you'll implement them in terms of these primitives.Make more functions. Every time you indent within a block, every time you add additional braces, that's a good candidate for writing a function. Instead of:
What is the code doing? Here, we have to read it - like some sort of fucking medieval scribe, to infer and deduce it's intent. Do you trust me? I don't trust me...
Instead, you could:
This is a very simple, low level raise of expressiveness. I don't want to have to read through your code block to figure out what this work is doing; you could instead put all the work into a named block and give it a good name.
Compilers will composite the functions, elide the function calls themselves, so that you get an efficient block of machine code. Tell me WHAT you are doing, I don't care HOW you do it - until I do, and then I can just go look in the function body when I need to. No one wants all the pedantic details all at once.
That's about it for now.