I rather write garage code than using slop

  • iusemybrain@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    1 day ago

    Just as advice, please don’t declare namespaces using the “using namespace <namespace_name>”. Unless you know what functions are implemented inside of it, if two namespaces have the same function name in both of them with different implementations, the compiler will run the function based on the namespace you have declared using the “using namespace <namespace_name>.”

    It is better, for example, instead of instatiating the namespace “using namespace std” you should do std::cout << “your_string” << std::endl this is explicitly saying from the std namespace, get cout, and from std namespace, get endl. It is more clear it is concise and everyone knows where you are getting this function from. Whereas if you did “using namespace std” and then cout << “your_string” << endl no one knows where you are getting those functions.

    Explicitly instantiate your namespaces at the time you declare your functions inside said namespaces even if it means tediously writing out the namespace every instantiation, it makes reading your c++ code that much more easier.

  • AMA@piefed.zip
    link
    fedilink
    English
    arrow-up
    4
    ·
    13 days ago

    Hell yeah 🎉🎉

    in the current age of AI bros vibe coding everything, finding an actual human learning a programming language to fix a problem they have is like finding a deepslate emerald ore (iykyk)

    wishing you the best of luck :D

      • Supercrunchy@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        13 days ago

        Nice!

        For me, slow progression is important to actually make the concepts “stick” in the brain, so do make sure to take your time in the journey, and not do the whole course in few days.

        I would heavily reccommend to experiment with the code yourself, see it crash and error out and really get the “why” it works (not just how to do it in that case). For example, you can pass 3 parameters to a function?

        Another great tip is to have a small project you are passionate about yourself: a card playing game (on the terminal, without graphics), an interesting math simulation, or a small program usable via terminal.

        C++ is hard. If it’s too frustrating consider python for an easier introduction (there are no pointers there!), and you can still switch to c++ later. All mainstream programming languages work more or less the same, and the programming skills transfer very well between them!

  • Buddahriffic@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    13 days ago

    I suggest you also spend some time learning about data structures and algorithms. That’s one of the things that separate university trained computer scientists from many self-taught or college trained programmers. Spending some time learning about how the hardware works is also worthwhile. Just stick these on your todo list, they aren’t necessary to understand to program, but the quality of what you make will improve if you understand these.

    There’s a lot of other ways you can increase your depth or breadth of knowledge, but IMO those are the two biggest.

    And for software design in general, the biggest thing I’d emphasise is modularization. Try to break up your program into different pieces that fit together. Like for a game engine, you could have the renderer framework as one module, input handling as another, and game logic as a third. Then, if you want to make a different game, you just swap out the game logic module and you’ve got a different game using the same renderer and input modules. This is essentially what libraries are.

    • starelfsc2@sh.itjust.works
      link
      fedilink
      arrow-up
      2
      ·
      13 days ago

      imo these are things you learn if you really want to understand coding deeply and write good code, not if you just want to make some software. I also don’t know if you would really understand what you’re seeing unless you know why you need it, at least that was the case for me. I majored in CS and most of my understanding still comes from how I actually ended up using things, and most of it never fully clicked until a couple years of using it.

      • Buddahriffic@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        13 days ago

        Somehow I got into an efficiency/performance focused mindset pretty early on, so I appreciated the algorithm analysis when I got to it (though I thought then and still do think that big O notation simplifies it a bit too much… Those dropped terms can be just as or even more significant as the final term when it comes to typical data sets, but it’s still useful in understanding how an algorithm scales).

        And I’d say that just going over the existing data structures and understanding their strengths and weaknesses can help just by being aware something exists. Like if all you know are arrays and linked lists, you’ll probably struggle a bit to handle key/value pairs. And then, once you learn about them, you might use them for everything and then wonder why your code runs so slowly.

        And the main reason why I’d like more people to be aware of how to be good programmers is that there seems to be a lot of people that just go from “something I’m doing as a hobby” to “something I’m doing for money” or “a large hobby project that has been picked up by the community”. And software quality has been dropping at a similar rate to how much hardware is improving.

        But you’re right that, without the greater context, a lot of it can be confusing and can beg the question of “why do I need this?”

        • starelfsc2@sh.itjust.works
          link
          fedilink
          arrow-up
          0
          ·
          13 days ago

          Yeah just for me personally I also really liked making things as efficient as possible, but I thought data structures and algorithms were lame because I had zero context around it.

          Maybe that’s just how it’s taught though, because there are really cool examples of what data structures to use and why. For instance if you have npcs with attacks that all have different cooldowns, and a central system that applies the attacks, what’s the best way to store it? A min tree is O(log n) on insertion, so that seems best, but what if it’s very likely an attack is invalidated and you need to remove it before it triggers? Lots of interesting concepts to consider there, instead of just “this does x and has y properties, so it’s good in this use case.”

          • Buddahriffic@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            12 days ago

            Oh yeah, and that’s where I think that knowledge comes in handy because they don’t just say “here’s a list of structures to use and the rules of when to use them” but they give you tools for evaluating how good various ideas are for handling that problem. It boils down to pretty much counting the CPU operations (which IMO is obvious, if tedious-seeming) and then goes through examples of how to do this to show that the math isn’t actually that overwhelming.

            Also it helps seeing equivalence between problems. Like your example is pretty much equivalent to scheduling threads on shared CPU resources with different priorities, especially if there’s a shared global cooldown between all those skills so they don’t just fire off when ready. They are a bit different but they might be close enough for a similar solution to work. So research can include CPU schedulers. Though on the other hand, something running at a game time resolution is trivial compared to the OS that needs to determine this as quick as possible so it can switch to the next thread (which is also an important consideration because it might not be worth optimizing this part at all vs say the order you process the data in each frame, though this isn’t a lesson from algorithms or data structure class but more general “how to optimise usefully” advice).

            • starelfsc2@sh.itjust.works
              link
              fedilink
              arrow-up
              2
              ·
              11 days ago

              Yep all of that is super interesting, and I’ve seen some people on YouTube make it that interesting but I rarely saw any examples like that in all my time in uni. When I first learned calculus the professor drew the speed of the car on a graph, and said how far did it travel in this time? Well it’s the area under the curve. Instantly connects it to something tangible and useful, rather than saying “the derivative is the slope of the line at this point.” I learned what a binary tree was and sort of how to make it, but I essentially had to relearn it anyway when I actually came across a situation where I needed it.

    • Jankatarch@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      12 days ago

      Also see: How to read other peoples’ code and understand enough to replicate same effects.

      Really hard skill but EXTREMELY helpful with projects.

    • dfyx@piefed.social
      link
      fedilink
      English
      arrow-up
      2
      ·
      13 days ago

      I would say the main downside of C++ is that it carries around a lot of baggage from the last 40 years. Even if you decide to use a modern standard in your own code, you’ll have to deal with libraries that can’t use many of the new features because they need to stay backwards compatible with old code bases. Also, a lot of tutorials and examples still look like they are from pre-C++11 times.

      I recently started a project that would have been a great fit for C++ (simple 2D game engine + editor) but the way Qt has to reinvent half the standard library, GTK basically asks you to write plain C and gtkmm had some other issues that I can’t even remember, all the fun of working on the project was gone. I decided to switch to C# (which I use for work anyway) and Avalonia and so far it’s going well. Not being able to use C++ still nags at me anyway. I would have loved to get more comfortable with modern C++ but I just couldn’t keep up the motivation.

      I’ll try again for the next project.

      • diaphragmwp@discuss.tchncs.de
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        13 days ago

        carries around a lot of baggage from the last 40 years

        cries in C stdlib

        I hate null terminated strings. Though the rest of just C without the “pluses” is nice. Nobody really kept adding new things unlike in C++, it’s just mostly the good old stuff.

        Anyways

        GTK basically asks you to write plain C

        From my perspective, glib is all possible languages at once implemented as C macros. What you are actually writing is technically valid C, but I would consider it “glib language” lmao.

  • Remus86@lemmy.zip
    link
    fedilink
    arrow-up
    1
    ·
    13 days ago

    The Cherno also has good videos on C++, although he assumes you have an understanding of the most common programming concepts.

  • Hugh@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    13 days ago

    Is this your first programming language? If so I strongly recommend Harvard’s CS50 course. It’s mostly in C but it’s very well taught and you learn enough fundamentals that you can quickly transition to another language.

      • AgentOrangesicle@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        12 days ago

        Oh, snap, you’re right! Garbage did that one James Bond song. I do all of my processing in a hole of my own making that drives my existential terror.