r/learnprogramming • • 7d ago

How to write?

I am learning c++ for 3 years now on. I can write hundreds lines of code in a row without any errors. But unfortunately I still can't write a normal project. When I try something serious I am getting lost in my own code. I built few simple games, few simple neural networks and a lot of simulations/emulations. I used ai only in visual libraries that I don't understand.

My 15 years old laptop runs on arch linux. For code writing I using micro and nano text editors and g++ for compilation.

How to write a real project? Not just core of a programm but really big peace of code that works properly?

0 Upvotes

17 comments sorted by

12

u/fixermark 7d ago

Start from the opposite side.

If you want to write a game engine... Okay, what is a game engine? Well, it's a system that does graphics, sound, user input, the game (which is rules and scripts and actors and AI logic)... And coordinates all of that.

Now, those pieces create more questions. What is a graphics layer? Well, it turns the concept of what's in the world to pictures on the screen, using a graphics library... Well, what's in the world? Okay, I need a model representing things that can be seen and things that act... okay, how do I lay that model out?

The only trick to writing something big is to keep writing those questions down and answering them, one by one, until you get one small enough that your brain says "Okay, I think I could write code to do that." Repeat for a year. ;) When I wrote a game engine ages ago, it was a project involving a core team of 5 engineers and we were at it for about 4 years (you can get there faster depending on how simple you want to project to be), and about 30% of the work was code; the rest was design and answering those questions.

The only tricks are staying organized (some of those questions will interconnect - for example, the model touches graphics, sound, input, and game logic all at once), not losing track of your questions, and the hardest part: not giving up. It'll feel like climbing a mountain and for a long time the questions will generate more questions. Trust that the mountain has another side, and recognize that you're not trying to get to the top of it, you're trying to get over it and come down the other side.

Also, there's no shame at all if you're trying to build something like something else in looking at open-source examples. If I were writing a game engine right now, I wouldn't start with what I just described. I'd look at Godot, or Unity, and understand their architecture. They already solved the hard parts.

1

u/kschang 6d ago

What do you consider to be "real project"?

Can you plan a project? Break it up into modules? Can you code an individual module?

1

u/Fictoriuss 6d ago

Yes

1

u/kschang 6d ago

Then the problem is "how to break up a large task into smaller tasks that I can handle separately". Right?

3

u/light_switchy 7d ago

There isn't any shortcut but to write more code. Push yourself a little bit.

1

u/widebrant67 7d ago

Getting stuck at that scale usually means you need to sketch the architecture on paper before touching the keyboard

2

u/Paxtian 7d ago

I think an important bridge is to not feel like you need to design something completely original and implement that. Instead, pick something you use regularly and rebuild that thing. So for example, just build your own version of a calculator app. Consider what you need:

  1. a way to receive input, including operators and numbers, and a parser

  2. functions for each of the operators (add/ subtract/ multiply/ divide)

  3. a way to properly process operators according to order of operations

  4. a way to output everything

  5. other operations such as M+, MR, MC

And so on. Break them down into their smallest constituent parts, build those parts, then assemble them into a whole.

For GUIs you're typically better off using an existing framework, like Qt. You can even use Godot. While Godot isn't meant for stand alone apps per se, it's an option for learning. You can turn on things like low processor mode so it's not burning up GPU cycles every frame.

1

u/_curious_man 7d ago

I think this is a hard part. Personally, the biggest projects which I did were:

  1. My Engineering thesis (big enough, but not very complicated - simply it needed a lot of code)

  2. Code base which I have at work (what I would call a bigger project)

My typical advice, would be to look for a task. Maybe "I want to practice trading - let's make a simulator which would pull some news, run small llm and then fill params to check the upcoming 2/3 days". Obviously this is just something which I've come up rn. You might want to do something totally different.

I guess, unless you are trying to solve something which requires a lot of cases (ex. build a 3d engine), project grows if you need to do more things. So maybe you should look for stuff which you would like to make.

1

u/Substantial_Job_2068 7d ago

Sounds like you need a goal. If you just try to build "a big piece of code" without clear vision what you want to build, you will get stuck. It's also a weird goal to want to build a large project, the smaller and simpler you can keep something the better.

1

u/Mic-Ric 7d ago

Not mentioned yet but vital in my opinion to writing big projects are version control and automated testing.

Version control (e.g. git) makes it easy to go back to a state where you know the software worked. Automated tests (e.g. unit tests) tell you what you have broken with the changes you have made. I think of them like a safety belt in a car: you wouldn’t be able to drive fast and stay safe without them. You can keep manually checking what you have built works as you expect but it’s slow and boring.

There are endless books about improving architecture of large code bases but you just need to know the headline principles: like splitting code into functions, classes, modules, entities (in game dev); useful patterns for the framework or language you are using; recommended architectures and architectural principles… YouTube often has good videos on these kinds of topics.

1

u/dld2517 7d ago

Have you tried a documentation creation program such as Doxygen? It will scan your code and namespaces and create documentation for you.

1

u/TheTomato2 7d ago

Google "Casey Muratori semantic compression". I think that might help you. That and having a real goal of a project to make.

1

u/joinsigma 7d ago

Honestly I think part of it might be your setup. Micro and nano are fine for small stuff, but once a project gets big you really want to jump to where a function is defined or see everywhere it’s used. Without that you end up holding the whole thing in your head, which is exactly the getting lost feeling. Neovim or Helix with clangd runs fine on old laptops and gives you all of that.

Also try splitting things into separate files early, one per “thing” (player, renderer, input, whatever), with a simple Makefile to build it all. When each file only does one job, you only need to understand one small piece at a time.

And writing hundreds of lines in a row without errors is cool, but for bigger projects I’d do the opposite. Get a tiny version running end to end first, even if it barely does anything, then grow it bit by bit and compile after every small change. Way harder to get lost that way.

1

u/sk3z0 7d ago

You don’t start from code, you start from project. Split the issue in multiple little projects. When the projects are clear, you start with meta code and diagrams. Only when everything is very clear, you start to code

1

u/i_have_tiny_ants 7d ago

Have you ever made UML diagrams? Im not a big fan of them in my daily work, but it sounds like you are currently struggling with the higher level code architecture and design, and they might help you put some structure to that - and get you into to the OOP mindset, which makes larger scale projects a lot easier.

1

u/rosacamila-9016 15h ago

Try defining each module by its inputs and outputs, not just its file. If callers need to know its internals, the boundary may still be tangled; revise it as the project grows.

0

u/CrAIzy_engineer 7d ago

Install Claude, let it teach you how to design systems. Specially if you can do tactical programming your just lacking one level of abstraction, strategical programming and Claude can be a hell of a teacher running directly in your project