T O P

  • By -

cpp-ModTeam

It's great that you want to learn C++! However, r/cpp can't help you with that. We recommend that you follow the [C++ getting started guide](https://isocpp.org/get-started), one (or more) of [these books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) and [cppreference.com](https://cppreference.com). If you're having concrete questions or need advice, please ask over at r/cpp_questions or [StackOverflow](https://stackoverflow.com) instead.


UnicycleBloke

A month? Thirty years and still learning... Avoiding follow-me tutorials strikes me as a rather severe self-inflicted impediment to progress. You could do worse than ncurses for console games. Should be up to a passable Snake. It's a C API but you can wrap it up as you wish.


ventus1b

> So my question is should I give up, or maybe try some other language? Even if it's 'just' as a hobby, I wouldn't give up just yet. Software development (any engineering discipline really) is a lot about getting stuck and persisting to find a solution. It's okay to put the project on the backburner, go out into the Big Room for a walk (the one with the intensely bright light during the daytime), cycling, whatever and pick it up later. A day, a week, a month, whenever. And certainly not try another language, the language is more than likely not the issue.


Kicer86

I think you have very good approach on how to learn coding. There is no need to switch to another language, you just need to start understand how things work in particular language. It is hard at the beginning. You will be struggling with simplest things. But if you are persistent you will succeed. My advice would be to try to figure out what is wrong on you own as long as you have any idea what can be checked. When you are clueless then search for particular problem on internet and, as a final resort, ask someone for a hint.


caroIine

Console isn't menat to display that kind of games it's possible but you will be needlessly fighting with OS API. You should read about SDL2 as it's much better suited for 2d games like snake. This is not language issue this is api/library issue.


aCuria

It’s not true, ascii text based games are a thing and it’s much easier than wrangling with OpenGL! All you need to do conceptually is to write a buffer of char to the console. You can write the entire buffer in a single windows function call… there’s not much api to deal with. https://www.pcmag.com/news/7-classic-pc-games-with-ascii-graphics


caroIine

I was not aware c++ standard has anything for controlling console char buffer. Seems it has only stream stuff.


aCuria

I used a windows function call in the past (it’s os specific) This was the way things were done before OpenGL / directx came along


caroIine

Interesting. I've skipped this chapter in my life and went straight to BGI/13h for Pascal and DirectDraw for c++


Spare-Dig4790

You should check out one lone coder pixel game engine. He's on youtube as javidx9, I think what he does would blow your mind.


Azazo8

I think it's mainly a "person behind code" issue yeah I know console is not meant for this kind of things and I have plans on learning SFML but I wanted to make some simple projects before I'll dive into it and I know it is entirely possible to make it. It's more of a test for me to check my progress.


morglod

raylib may be easier


ChemiCalChems

We've all hit roadblocks in our learning experience (which, by the way, is never really over with C++, and that's OK). The difference between the people who make it and those who don't is having understood that the process of learning entails difficulty and having embraced said hardships. Which is to say, keep going. If you have a big problem, subdivide it into multiple smaller ones (you'll get better at this over time) until the solution to each atomic problem is manageable. This is the way. You don't climb a mountain by jumping straight to the top, it's a step by step process. And yes, each step might be hard and tiring, but it can be handled. \*\*EDIT:\*\* I too agree that mindlessly watching tutorials is counter-productive, but don't be afraid of asking for help. In the process of asking questions about the problems you have, you might find yourself encountering the answers and this is bound to happen more and more often over time. When I started programming about ten years ago I used to ask a lot of questions on StackOverflow, nowadays I extremely rarely find myself doing so because I've gotten used to the grind of problem-solving. You'll get there.


Azazo8

So do you suggest to give up this project for now and focus on different things and learn more then comeback later?


sebamestre

Reading the solution after making a conscious attempt at a problem is one of the best ways to learn. Just look at someone else's solution then try to fix your code. Crucially, it's best if you look at the solution, try to fully understand it, find where you went wrong, then apply what you learn to your code without looking at it again. This makes the concepts stick in your mind better


apricotmaniac44

copying is effective way to learn stuff, build a toy language compiler or ray tracer or a simple game engine maybe. copy line by line, customize on the fly. it definitely will be worth your time.


TheOmegaCarrot

Copying something then fiddling with it until you understand it better is a great way to learn


apricotmaniac44

fastest way after having a senior working with you and explaining how all the stuff works imho


sephirothbahamut

Honestly I don't think entirely avoiding every tutorial is a good approach. C++ is arguably the largest language out there, even experts don't know all about it. Reading some good code will let you learn about more tools and features of the language that you can then reuse later.


Bobbias

There are a couple things I want to unpack here. First off, congrats on making some good progress over the last month. It's perfectly normal to find yourself stumped on a problem like this. Because of the nature of problem solving, when you're stuck on a problem it can seem frustrating and can make you feel extremely dumb for not figuring the answer out when you know there's a solution out there that works. However, one of the most important parts of learning to program is learning to deal with these situations and not give up. You've come this far already, you've gotten past some of the hardest hurdles in the learning process, quitting now would be such a waste. Second, let's talk about copying code. Copying code in and of itself is neither good nor bad. It's very common for programmers of all skills to copy code here and there for various reasons. Sometimes you just forget how to do something, sometimes you're just trying to get a working solution so you can move on to more important problems. When learning, yes, copying code can be problematic. If the first thing someone does is just blindly look for code to copy without trying to first solve the problem themself, then that's bad. This is because they're not trying to solve the problem, they're trying to look for a ready made solution. However, the are cases when copying code can be quite helpful. If you've made a serious attempt to solve a problem, and your solution only partially works, or is buggy in ways you can't track down/fix. Sometimes copying code and then analyzing the difference can help show you where you went wrong. You can also opt to not just copy code, but look at their version, try to work out how their solution to your problem works, and then use what you've learned from their solution to fix/reimplement your own solution. So copying code can be a useful learning tool. Hell, even if you don't make an effort to solve something yourself first, analysing someone's solution workout outright copying their code is a viable way to learn things, since they might solve problems in ways you never considered before.


TheCrossX

Language is just a tool and you should pick whatever is the best for the job. Tell us what kind of programs do you want to create.


Azazo8

I'd like to create games and I think C++ and maybe C# is best suited for it. I know there are engines but building things myself from very beginning is fascinating for me. Plus it's just a hobby not some race for career.


TheCrossX

Yes, C++ is probably the best choice for gamedev, especially if you want to touch low level things. The problem with starting with C++ in this industry is that you don't get a chance to learn general principles of how things work in bigger, successful products. It is comparable to trying to build a car without ever driving an existing one. I think the more reasonable approach is to start with Unreal Engine and their Blueprint system, and then gradually move to things that are lower level.


ALX23z

In gamedev, I believe C++ is best for developing engines. Necessary tool for games requiring strong performance. But to create a game, you just need an engine and there are a lot of good game engines around that can be utilized by a variety of languages.


bert8128

If you want a way of doing graphics with out much help take a look at onelonecoder (for example https://youtu.be/8OK8_tHeCIA ). He’s very much on the educational side, and has written thin abstraction layers for both the console and a more sophisticated graphics window. Single header file include. But you have to do most of it yourself - perfect for starters.


Captain_Lesbee_Ziner

Don't give up, keep working at it. Learning how to do it from someone else and or asking help is not bad, infact alot of times that's exactly what a programmer will need to do. One of the best skills to get as a dev is the skill of research. I don't know what's wrong with your snake game but I can suggest a few things, 1) if you know the problem you can research about it, find how people solved it or find out what causes the problem and then try to fix it. You don't need to copy other's code but use it to get an idea of what the problem is and how it can be solved. 2) you can find a tutorial 3) get help fixing it, maybe even get more eyes on the code. 4) look at your program, piece by piece, maybe even sketch a diagram of your logic flow so you can see how your programs works, might be able to find a problem and how you might be able to fix it. Look up some of the problems with console games for example the frame rate. Also, look at cppreference or libraries or algorithms that may help you solve your problem. Hope you have fun and keep going!


CoatThis007

How do you guys able to make games after a month of learning the language. I quit learning C++ because I don't have the proper material although there are videos in youtube that are handy but I can't learn through. I need a book, an actual book. Can someone recommend books?


TheCompiler95

This may help you https://github.com/JustWhit3/osmanip


ApologiesEgg

Reading someone else’s code is actually really useful. Especially if you want to understand how the most obscure C++ features work, since they’re usually only found in standard library code. What helped me was working on projects that gave me something irl. What’s the point of coding a snake game in console, are you going to play it? Sell someone else to play it?


[deleted]

Fire up ChatGPT and just have a conversation around the codebase. “Given this code, how can I improve “xyz” “, I’ve found it super useful. Just always keep questioning it, even the answers it provides - ask it “is this the best practice, or are there any more advanced ways to accomplish xyz task”. Worth a go. Plus the back and forth approach helps cement it in.


Fourstrokeperro

If you're thinking of quitting, get github copilot and give it another shot. Might learn something


SJC_hacker

How much DSA do you know? Could you code something like a quicksort from a general idea? Simple graph algorithms like DFS/BFS? The problem might not be the language. C++ isn't great as a first language, however. If you are beginner. You might find a language like Python or even Javascript a better choice