SyntaxBomb - Indie Coders

Languages & Coding => C++ / C# => Topic started by: Pfaber11 on April 28, 2021, 05:14:26

Title: Understanding c++
Post by: Pfaber11 on April 28, 2021, 05:14:26
Hi guys decided to educate myself in the ways of c++ , I don't want to learn it right now but would like to understand namespace and class's etc.
Anyway I think I get that bit . According to what I read c itself only has 44 words in it's language . When I look at some code in c/c++ it looks pretty damn hard to understand . I would really just like to have an understanding of how it works as might come in handy one day. Are there many AGK people out there using tier 2 ? Is OOP better than a procedural language like basic? I'm really just trying to educate myself . I understand basic and a bit of Python but that's about it and I'm still learning new stuff on a regular basis after using for a couple of years . Have an excellent day.
Title: Re: Understanding c++
Post by: iWasAdam on April 28, 2021, 11:33:35
C++ is a great language... But it's also a beast  :-X

The main thing you really need to get a grip on is resources and allocation.

In languages like blitz and agk. all of the resource and memory management is done for you. You just 'load' something and it's done.

c/c++ is very low level and fast - to do this is has NO memory and resource management. So...
You want to load something - you need to allocate resources, load, track and (THE MOST IMPORTANT THING) release the resources back to the system once you are done with them. If you don't do this correctly then you can make systems do nasty things like crash, have memory problems, all sorts of nasty things that are very hard to track down.

Also be aware that vanilla c/c++ has no string support, so you will have to find (or write) your own systems. and that goes for most everything else. You are going to need frameworks and rely on the work of others and know all about headers. .H and .CPP. thats without all the namespaces, classes, etc.

But in saying all of this - if you can get your head around it - c++ is totally amazing, wicked fast. but horrible to begin with...  ;D
Title: Re: Understanding c++
Post by: col on April 28, 2021, 13:49:32
I have to agree with iWasAdam in that it has grown into a powerful beast, and becoming more beastly with every new version.

BMax is like a hugely scaled down version of it so it's not a bad idea to start off by having a go at porting some BMax stuff, assuming you're spot on with BMax of course. At first I would recommend to using the std (standard) library for things such as shared pointer, unique ptr, strings and for your containers such as list, map, set, vector (dynamic sized arrays), and array (fixed sized array). Try not to look at the source for those as for a beginner it will scare the pants off you. If you use c++ and the std library properly (as it's designed to be used - ie no need to use new and delete in your code) then you'll never have memory issues, at the sacrifice of a little loss of speed. Don't worry as you can get that speed back when you know what you're doing.

As with all languages you don't need to use all of its features when starting out so try not to get too far ahead of being comfortable with it.

Class/structs are similar to BMax types except much much more mature, and namespaces just let you put code within a named 'scope'.

Good luck and most importantly... have fun.
Title: Re: Understanding c++
Post by: Steve Elliott on April 28, 2021, 17:32:26
I think we've had this conversation before, stop switching/looking at other languages and get the best out of the one you are currently using.  C++ is very much more complicated than AGK Script.  I see you posting many C++ questions here and getting frustrated.  While you don't need to learn the whole language to get by, the code you see online will be written by people who do use all the features, so this will make it much more difficult to learn.
Title: Re: Understanding c++
Post by: Scaremonger on April 28, 2021, 17:52:08
Programming in general is easier once you know one system really well. Learning a second one becomes easier because you can relate to your existing knowledge.

C++ is not a language for beginners, although I know people who have started there. If you do want to head in that direction start with plain old C and learn it fluently first.
Title: Re: Understanding c++
Post by: Steve Elliott on April 28, 2021, 18:09:55
Quote
C++ is not a language for beginners, although I know people who have started there. If you do want to head in that direction start with plain old C and learn it fluently first.

I totally agree - start with C and C  ;) how you get on.
Title: Re: Understanding c++
Post by: steve_ancell on April 28, 2021, 21:44:47
This tutorial is quite good and easy to understand.

Title: Re: Understanding c++
Post by: steve_ancell on April 28, 2021, 21:46:41
Play around with the core language first and then move onto graphics, sound and input libraries.
Title: Re: Understanding c++
Post by: iWasAdam on April 29, 2021, 05:59:51
ok, you've had some answer from people. now have a quick look here at this current (very) simple question and answer that deals with c:
https://www.syntaxbomb.com/index.php/topic,8406.msg347049799/topicseen.html#new (https://www.syntaxbomb.com/index.php/topic,8406.msg347049799/topicseen.html#new)

now you're back after having a look at the link. What did you think?
could you follow (now when I say follow I mean, look at the code, understand without having to go elsewhere to find out what any of it meant) what was being talked about.

Could you see and 'know' what pointers are where they were used and what happens?

Could you see and understand the memory allocation systems being used?

Look at this piece of code from the link:
struct *data_converter mywrapper(){
      struct data_converter *bbb;
      int length = sizeof(struct data_converter);
      bbb = (struct data_converter*) malloc(length);
      *bbb = anycontent();
      return bbb; 
}


can you see what it does?

can you identify the pointer?

can you understand how the placement of the * works, or is that something you are not sure of. there is no / no + and no -. hmmmm does that give you any thoughts?

There are also some () and {} being used. Do you understand why they are being used, how, etc...

Can you see the most hyper important thing that is missing? It's is glaring and obvious


if the answer to ANY of the above is NO or WFT or even I'm not sure, etc
DO NOT GO NEAR C


Head what Steve and others are telling you: Learn one simple thing really well. not lots of bits and bobs really poorly...

Title: Re: Understanding c++
Post by: col on April 29, 2021, 06:12:32
@iWasAdam.

A bit blunt  :)) - although you will have your reason(s) for being this way, I'm sure.

Quotedecided to educate myself in the ways of c++ , I don't want to learn it right now

It might be a bit unfair to expect Pfaber11 to be able to answer any of your questions so soon?
Title: Re: Understanding c++
Post by: Midimaster on April 29, 2021, 09:01:28
As I'm the "author" of the bugged bad sample, I join the discussion. I was happy without C for my whole life and never came to limits in writing apps. Now I started to learn this "language", as I want to connect to third party codes. But at the moment for me C looks like a "unnecessarily complicated monster" which may be helpful, if you write operating systems, but not if you plan to solve a problem.

C is a really hard stuff when you need to understand this stupid pointers.

In a lot of languages we can see, that all mathematic and logic problems can be solved without having "pointers" and it's variations. So there is really no need to write software in C. At the moment I believe that the advantage of C starts in this moment, when you try to do "forbidden things": change variable types, manipulate RAM directly, doing things without security checks. This brings speed advantages and enables you to do thing in a manipulative way instead of thinking about a safe solution.

All problems "high language" users have, when they start with C are related to this fact. Mathematic and Logic are the same on and "high language" and C. This is as easy to understand as in your "home" language. The problems start, when C is leaving this path.

So the arrogance C-user often show to "high language" users is only, because they know how to drive this "old russian airplane with 1000 buttons and 100 gauges", while a lot of people already fly their airplanes with only one joystick.


Title: Re: Understanding c++
Post by: Xaron on April 29, 2021, 09:42:41
To be honest modern C++ is quite cool. It encapsulates memory management (unique pointers for instance) quite well. Combined with the std lib it's very powerful and not too hard to use.

Using raw pointers is actually not needed at all anymore and sign of bad design (beside some really low level stuff and embedded systems).
Title: Re: Understanding c++
Post by: Pfaber11 on May 01, 2021, 19:38:59
Yeah I do agree oop languages are not something I know much about and I really do not intend on learning any right now and probably not in the future. I really do like AGK Studio and intend to use it for a long time . What concerns me is that if the makers come out with something new then I will at some point need to start again . I have looked at c++ and java years ago and really don't get on with either of them . very nasty indeed , but I would like to Know how they work. I think there are probably many more like me who seek the holy grail of computer languages . Maybe I'm already using it in Studio . Anyway trust me when I say I'm not learning another language right now and I hope I will not be for a long while yet . If AGK keeps working for the next generation of computers then I'll keep using it . The first pc game I put together in Blitz3D will not run on my laptop although it does run on my desktop both running windows 10. I have tried everything running as administrator and compatibility mode but nothing . To me if it won't run on current equipment then it is passed it's sell by date and no good to me . Been busy for the last couple of days and just looked at this post . It seems that for a language to go mainstream it has to be free . Am thinking of making my programs for Linux too but my laptop will not let me boot from my usb sticks . Been into my bios and it will not let me do this so cannot install it . Anybody know how to rectify this ? Sorry for the novel. Happy Days
Title: Re: Understanding c++
Post by: Scaremonger on May 02, 2021, 08:36:06
Quote from: Pfaber11 on May 01, 2021, 19:38:59
Am thinking of making my programs for Linux too but my laptop will not let me boot from my usb sticks . Been into my bios and it will not let me do this so cannot install it . Anybody know how to rectify this ?

Linux is a strange beast if you are coming from a Windows background and it took years before I was comfortable enough with it to use it instead of Windows. One of the biggest issues with game development on Linux is that every distribution comes with a different set of libraries installed by default and there are also several different desktop environments to choose from (On Windows you have a standard set of libraries and one desktop environment). You will often need to have a different installation procedures for each distro and this is no easy task.

Back to your question though; if you cannot boot on a USB disk try burning an ISO of your chosen Linux onto a CD/DVD and boot on that. You can then try out the distribution running on your laptop and only install it on your hard disk when you are happy its the one for you. I tried several distributions with various desktop environments before I finally settled on Linux Mint with XFCE desktop. My home server also runs Linux Mint but without a desktop (Headless).

Si...
Title: Re: Understanding c++
Post by: Derron on May 02, 2021, 12:32:07
if it cannot boot from USB it is either locked by the company (so a notebook owned by the company you work for - and they do not want you to boot up other stuff) or the notebook must be ... 2007 or way older.
Think the last laptop I had which did not allow USB booting was from 2005 or so.

Nowerdays you only have to take care of:
- formatting the USB stick the right way (so it is a bootable stick)
- use an usb stick which did not cost just 1 dollar and is behaving outside of standards (some vendors refuse booting from certain sticks - take another one and "voila")
- check what shortcut brings up the boot device options (F11, F12 ...F3 ... it should be written on POST screen of the bios, except you enabled a fancy "wallpaper")
- if you do not find it: open bios and check boot order - it might not list your stick (for above written reason) but maybe it displays things like "removeable device" or "USB mass storage" or such things - select them then

If everything fails you can always take the disc out of the laptop, place it into a desktop, install linux there, place back the disc into the laptop and boot there (and install required special drivers for your GPU if AMD or NVidia based).


Mint+XFCE here too.

bye
Ron
Title: Re: Understanding c++
Post by: jimbo on August 13, 2021, 10:21:19
The c++ is a good programming language, but I suggest you learn the C language at first, and then go forward to c++.
Title: Re: Understanding c++
Post by: Baggey on August 14, 2021, 17:54:14
To understand it you need to run it in the first place!

I use Blitzmax_1.5. You run the .EXE. And you start codeing. In the Blitzmax ide. Compile it! and hey presto. You have a program running!

Now Try doing that with C Please dont mention VisualStudio. What a ball acke to get the right down load let alone use it. You need to find files, make them link them. Guess what you need in the first place!  ???

Now, just imagine. BlitzMax_C.

Don't be silly! My god how Cool would that be, Running with SDK 2.0 built in. Just Run the .Exe and just use it. Straight out of the box. I know im being to Practical.

I know it's only a dream!

Kind Regards Baggey
Title: Re: Understanding c++
Post by: 3DzForMe on August 14, 2021, 21:37:13
QuoteBut in saying all of this - if you can get your head around it - c++ is totally amazing, wicked fast. but horrible to begin with...     

My thruppence.  I've coded in 'C' for a bit of a living briefly once.... made a terminal version of space invaders in it to consolidate stuff.  Never got into C++..... I'll see if I can dig out the code for my terminal version of space invaders. Compiling C can be a bit of a game depending on what system your on..... haven't done it for a while.... bit loath to dip my toe back into that 'murky' pond.  Will give it a blast anyway - good luck!!

Oh yeah, did c# for about 8 weeks 7 years ago - that did it for me, went back to fixing planes!
Title: Re: Understanding c++
Post by: EdzUp on August 16, 2021, 12:31:18
If your serious about C/C++ download Code::Blocks and the latest version of MingW GNU C++ and go through some of the examples provided, ive been coding in C since the "before times" (Turbo C++ 2 and up on MSDOS yes before times (before windows)) and that is my happy place coding in MSDOS was so much easier than coding on Windows is today.

As an example for you in BlitzMax you can call Graphics 1024, 768, 32 to get a graphics window setup ready for you, well http://www.winprog.org/tutorial/simple_window.html (http://www.winprog.org/tutorial/simple_window.html) this just sets up a basic window without graphics ;)
Title: Re: Understanding c++
Post by: col on August 16, 2021, 15:48:43
QuoteAs an example for you in BlitzMax you can call Graphics 1024, 768, 32 to get a graphics window setup ready for you, well http://www.winprog.org/tutorial/simple_window.html this just sets up a basic window without graphics

I'm not sure this fits within the difference of languages? :P

BlitzMax does all of that too behind the Graphics command - it has to as its the Windows way of doing things and isn't really so much of a language difference feature. For eg you could easily create a similar Graphics function in c/c++ and hide it all away in the same way as Max2D does.

I'm using c# for UI stuff and c++ for code pretty much exclusively nowadays.
Title: Re: Understanding c++
Post by: EdzUp on August 16, 2021, 19:48:00
True my example was more as an example of Max allows for rapid application development.

Personally I too use C++ and OpenGL exclusively these days as it feels more like coding to me, writing games in Unity feels like scripting than coding and doesn't feel right.
Title: Re: Understanding c++
Post by: Pfaber11 on August 26, 2021, 22:07:17
I feel the same coding in AGK in that it is pretty easy anybody can do it , or can they. It's taken me about 3 years to get comfortable with AGK and am still picking up new things as I go along . TGC say anybody can program in AGK and it is easy and it is once you've been at it a few years . Maybe I'm just a slow learner . Anyway I looked at that code for opening a window and it is pretty lengthy. I think if AGK was taken away from me my next port of call would be PureBasic .