Trying to decide which programming language I want to learn

In summary: C++ is considered a lower-level language, meaning that it is closer to the hardware and gives you more control over how your program runs. However, C# is a high-level language, which means it is easier to learn and use and has a lot of built-in libraries that make coding faster and more efficient. Both languages have their advantages and disadvantages, and it ultimately depends on what type of project you are working on. For gaming, C++ is often preferred because of its speed and control, but C# has become increasingly popular in game development as well. It's worth trying both and seeing which one you prefer working with.
  • #106
One thing that you should realize is that the documentation of C++ is so large that on-line and computerized documentation has huge advantages and might be the only practical way to do it. They can include hyperlinks, search tools, and syntax-dependent recommendations that no number of books can match.
 
  • Like
Likes sysprog
Technology news on Phys.org
  • #107
FactChecker said:
One thing that you should realize is that the documentation of C++ is so large that on-line and computerized documentation has huge advantages and might be the only practical way to do it. They can include hyperlinks, search tools, and syntax-dependent recommendations that no number of books can match.
I use google search on everything, but actually to my big surprise, I find searching on line is not helpful for me in C++. This is because I am barely starting to learn, all the links are from like forums where people are much more advance than me. When I read their programs, there are more terms that I don't know than I know. So the programs don't even make sense to me. I don't see and simple explanation on anything.

On line search is very useful if someone already know the subject and just have a specific question. I am surprised like if I have question on very basic electronics, you actually can find article teaching you what is V=IR. But I yet to see any on C++ that get down to this fundamental stuffs. So it's worth to spend extra money to get a few textbooks.

Actually, it's really not the book this is the problem this time, I must be more tired than I realize. I just got stuck in something really simple. I thought both statement ( line3 and line 10 are one syntax), but actually line 3 is just simple definition of a constant(Square), then the constexpr just use that constant to define the size of the array. It's just that simple and I was to blind to see it. After bickering here and wrote a bad review on the book instead of keep working on the program, this morning, when I look at the codes, it just dawn on me that I was stuck in the wrong direction! Now I still have to go and delete my review on the book!

Now I know better, don't rush, don't just keep at it more than 3 or 4 hours a day. I don't have a deadline. I actually read and understand the rest of the Chapter 4 with strings with no problem. I am not in the 20s like before that I can just keep at it anymore.
 
  • #108
You can start with your own simple programs and limit how much of C++ you want to get into. If you are trying to understand other people's code, then they might take you down every C++ rabbit hole that they put in their code. The example code using constexpr is like that. I gave you a link to the documentation on constexpr. That is the best I can do. If you can understand that documentation, then you are doing good. If you can not, then you may want to change your approach so that you can limit the parts of C++ that you need to learn and use. C++ code can be as simple as C, or it can be extremely complicated. Do not expect the complete documentation of C++ to be understandable without years of study and hard work.
 
  • #109
I have a question in this program. I am playing with adding something in the same program I had issues... I added a line to check the size of the array "moreNumbers[]". That is line 27. I learn it from the character string section to check the length of an array by command sizeof(Array).
C++:
//Assign Values to Elements in an Array
#include<iostream>
using namespace std;
constexpr int Square(int number) { return number * number;}// set constant function Square.

int main()
{
    const int ARRAY_LENGTH = 5;

    int myNumbers[ARRAY_LENGTH] = { 5, 10, 0, -101, 20 };
    int moreNumbers[Square(ARRAY_LENGTH)];// replace the constant number for length with a constant function.
   
    cout << "Enter index of the element to be changed: ";
    int elementIndex = 0;
    cin >> elementIndex;

    cout << "Enter new value: ";
    int newValue = 0;
    cin >> newValue;

    myNumbers[elementIndex] = newValue;
    moreNumbers[elementIndex] = newValue;

    cout << "Element" << elementIndex << "in array mynuNumbers is: " << myNumbers[elementIndex] << endl;

    cout << "Element" << elementIndex << " in array moreNumbers is: " << moreNumbers[elementIndex] << endl;
    cout << "The size of moreNumbers[] is: " << sizeof(moreNumbers) << endl;
    return 0;
}

If you run the program, it will return the size is 100 instead of 25. What did I do wrong?
 
  • #110
In your definition of the square, write

return (number*number)

that might be the issue.
 
  • #111
sizeof returns the size in bytes and there are 4 bytes per int
 
  • Like
Likes FactChecker and yungman
  • #112
Jarvis323 said:
sizeof returns the size in bytes and there are 4 bytes per int
How can I forgot that!

Thanks
 
  • #113
Jarvis323 said:
sizeof returns the size in bytes and there are 4 bytes per int
I even modified the array by declaring the array is characters: char morNumbers[]

The length now say it's 25 as characters are 1byte long only.

Thanks
 
  • #114
Jarvis323 said:
there are 4 bytes per int

8 bytes if you're compiling 64-bit code. (And way back in the Stone Age there was code where an int was only 2 bytes, or even 1 byte.)
 
  • #115
I don't think that one byte is large enough to hold the numbers that you want to put in it. newValue is an integer and needs 4 bytes. You can always leave the array large enough for an integer and print sizeof(Array)/sizeof(int).
 
  • Like
Likes yungman
  • #116
FactChecker said:
I don't think that one byte is large enough to hold the numbers that you want to put in it. newValue is an integer and needs 4 bytes. You can always leave the array large enough for an integer and print sizeof(Array)/sizeof(int).
I am just verify the line sizeof() if I change to character as it's 1 byte. Just playing around. I am playing around with the example given by the book by adding things and try it out. It's been fun.

Thanks for the new syntax for integer ( 4 bytes)

I am not at the point of designing and writing my own program, so I just take the sample program, adding stuffs to try to get familiar with the terms and the syntax. I am finishing up chapter 4 tonight, I'll be working with chapter 5...Operators, expressions and statements tomorrow. That's should be a lot more interesting.
 
  • #117
Jarvis323 said:
there are 4 bytes per int
PeterDonis said:
8 bytes if you're compiling 64-bit code. (And way back in the Stone Age there was code where an int was only 2 bytes, or even 1 byte.)
An int is 4 bytes (currently) whether you're compiling 32-bit or 64-bit code. That is definitely the case with Visual Studio, and is probably the case with other compilers as well. The long long (AKA long long int) type is 8 bytes, as is unsigned long long.

When I was first learning C, in 1985, an int was the same size as a short (2 bytes), but all that changed along about 1995 or so. I'm not aware of any machines and compilers for which an int was only one byte. Not saying it didn't happen, but Kernighan and Ritchie were designing a language to be used under Unix, and surely the machine word size was greater than 8 bits.
 
  • #118
yungman said:
I am just verify the line sizeof() if I change to character as it's 1 byte. Just playing around. I am playing around with the example given by the book by adding things and try it out. It's been fun.
Thanks for the new syntax for integer ( 4 bytes)
That's not really syntax -- it's just the size (in bytes) of that data type. You can use the sizeof operator (it's considered an operator, like +, -, *, /, etc., rather than a function) to determine the size of any type or any variable.

When you do more with arrays (the C-style arrays as opposed to the C++ Standard Template Library array template) that are initialized, you can use sizeof to count how many elements there are in the array.

C:
int List[] = {2, 5, 8, 10, 11, 31, -2, 15, 25};

int size = sizeof(List) / sizeof (int);
When this code is run, size will be set to 9. sizeof(List) == 36, and sizeof(int) == 4, so the quotient gives the number of array elements. Similar code will work whatever the base type of the array is: int, short, float, double, structure type, and so on.
 
  • Like
Likes yungman and FactChecker
  • #119
EDIT: I changed "function" to "operator". Thanks, @Mark44 .
The sizeof() function operator can be very useful sometimes. If you make a structure that is a combination of characters, integers, floats, and smaller structures, the computer will often insert padding space to make things align for efficient use. It is tricky to know how big the final result is. The sizeof() function operator can tell you that.
 
Last edited:
  • Like
Likes yungman
  • #120
Anyone know how much one semester in the college C++ class covers? I am using this book:
https://www.amazon.com/gp/product/0789757745/?tag=pfamazon01-20

Seems like it's a lot to cover the whole book in one semester, I just want to know what chapters I have to cover to equal to one college semester. You can see the description of the chapters if you look inside the book in the Amazon link.

Thanks
 
  • #121
C++ used to be a one semester course but now many institutions expect you to learn the language in your spare time and only offer courses in specific applications in C++ for e.g. CFD.

For instance here is what the Cambridge Engineering faculty give you: http://www-h.eng.cam.ac.uk/help/tpl/languages/C++.html. The programiz link there is a good online tutorial with its own compiler that runs in the browser so you don't need to download anything.
 
  • #122
In my experience, C++ was just the language used in an object oriented programming course, and was the 3rd programming course you would take.

They skipped over the stuff in part 1 of that book (which was the subject of a previous course in C), and focus instead on classes, encapsulation, polymorphism, and inheritance (part 2). The course was project based and the book was just used for students as a reference.

A course following object oriented programming was data structures and algorithms. In that course you'd learn about some of part 3 in the book. The focus would be on the underlying algorithms and when to use them, analyze expected and worst case performance, and implement some of them and others yourself from scratch as part of different projects.

The content of parts 4 and 5 were not really covered.

No courses focused specifically on learning C++, just used basic/simple parts of C++ as a base to teach general concepts. I think that they expect people to learn the details of specific languages independently, as there are many of them and they change. Learning new languages and technologies independently is also a sort of long term survival skill in industry.

Anyway, I think your book is about 3 semesters worth of content, but they would include a lot of projects.
 
Last edited:
  • Like
Likes yungman
  • #123
FactChecker said:
The sizeof() function can be very useful sometimes.
Agreed it is very useful, but technically, sizeof is an operator, just like +, -, *, <<, ^, and so on.
 
  • Like
Likes FactChecker
  • #124
Jarvis323 said:
In my experience, C++ was just the language used in an object oriented programming course, and was the 3rd programming course you would take.

They skipped over the stuff in part 1 of that book (which was the subject of a previous course in C), and focus instead on classes, encapsulation, polymorphism, and inheritance (part 2). The course was project based and the book was just used for students as a reference.

A course following object oriented programming was data structures and algorithms. In that course you'd learn about some of part 3 in the book. The focus would be on the underlying algorithms and when to use them, analyze expected and worst case performance, and implement some of them and others yourself from scratch as part of different projects.

The content of parts 4 and 5 were not really covered.

No courses focused specifically on learning C++, just used basic/simple parts of C++ as a base to teach general concepts. I think that they expect people to learn the details of specific languages independently, as there are many of them and they change. Learning new languages and technologies independently is also a sort of long term survival skill in industry.

Anyway, I think your book is about 3 semesters worth of content, but they would include a lot of projects.
That makes me feel a lot better. I was looking at the book, there's no way they can cover the whole book in one semester. It is so deceiving that the tittle of the book is "Learn C++ one hour a day", one hour a day, it will take a long time! I put like 3 to 4 hours a day for almost a week, I barely cover the first 4 chapters and starting on the 5th. It's just have a lot of new names (terms) and it's so hard to remember. I don't think the book is that good, it goes over a lot of terms in the first 4 chapters with no details, then repeat again in the later chapters. Particular Chapter 4, it actually said for detail, refer to chapter 17!

So for someone like me that have not touch programming for 40 years, is it like 3 semesters to cover Part 1 to 3?( learning back C and other things I missed?). I decided not to touch C and bull through C++ because I took a quick look at C, the words used are different from C++, meaning I have to learn more terms. Learning all the terms is the HARDEST part for me. My weak point is remembering people's names, the last thing is to remember more terms. The rest are quite easy, other than one particular problem I got stuck, I pretty much going through the rest without problem at all.

I am hoping I can finish Part 1 to 3 by Christmas.

Thanks
 
  • #125
yungman said:
I am hoping I can finish Part 1 to 3 by Christmas.
You are putting in an impressive level of effort. I think that you will be in very good shape by Christmas. There is a lot to get oriented on initially and it can make progress seem slow. But I think that you may be beyond that and will start to get traction quickly.
 
  • Like
Likes yungman
  • #126
FactChecker said:
You are putting in an impressive level of effort. I think that you will be in very good shape by Christmas. There is a lot to get oriented on initially and it can make progress seem slow. But I think that you may be beyond that and will start to get traction quickly.
Thanks for you complement. I am trying hard to learn. But I think I bull through the 4 chapter too fast, too many new names. I am going to spend the next day to go through them again and update my notes to make sure I have a better feel of the names. It's all the class, function, object etc. that really throws me off. Just have to keep reading and hopefully they will sink in.
 
  • #127
Object Oriented Programming can come from left field sometimes. I came from a background of computer discrete event simulation and OOP was exactly what I wanted. Suppose you are simulating a road intersection and want to generate a stream of cars coming and going. You want each car to control itself according to some rules and to collect its own statistics without getting it confused with all the other cars. You would make a class of vehicles and each car that you generate (instantiate) is an object in that class. The class defines how it will operate and collect data (using methods and hidden data), but the object itself does all the work and collects data internally, without getting it confused with the other cars (objects). Thousands of cars can be generated (instantiated), do their thing (using methods defined for the class), and destroyed (using the destructor method) as they enter and leave the intersection. OOP greatly simplifies simulations like that.
 
  • Like
Likes yungman
  • #128
FactChecker said:
Object Oriented Programming can come from left field sometimes. I came from a background of computer discrete event simulation and OOP was exactly what I wanted. Suppose you are simulating a road intersection and want to generate a stream of cars coming and going. You want each car to control itself according to some rules and to collect its own statistics without getting it confused with all the other cars. You would make a class of vehicles and each car that you generate (instantiate) is an object in that class. The class defines how it will operate and collect data (using methods and hidden data), but the object itself does all the work and collects data internally, without getting it confused with the other cars (objects). Thousands of cars can be generated (instantiated), do their thing (using methods defined for the class), and destroyed (using the destructor method) as they enter and leave the intersection. OOP greatly simplifies simulations like that.
Wow, this is what I need. Perfect timing while I am reviewing the first 4 chapters. I have a few questions:1) I put this in the heading of my notes and I change a little. I highlighted the key words. I want to confirm using #include<iostream>:

Is iostream a HEADER file where std is the CLASS and cout is OBJECT?

2) What do you call the .cpp text file that I created in VS? Is the compiler transforms the text .cpp file into machine code called OBJECTIVE file? Then the next step is to link with other files to form the complete .exe file?

3) Do you call main() {multiple lines of codes} that is the body of the program as FUNCTION? In fact I can declare any myfunction() { multiple lines of codes} as FUNCTION within the .cpp text file.

I am sure I have more question later.

Thanks
 

Attachments

  • C++ notes.docx
    17.8 KB · Views: 155
  • #129
I want to confirm declaration of constant:

int pi = 22/7 = 3
float pi =22/7 = 3.1429

So if I want decimal number, I declare float?
 
  • #130
I have another question about DYNAMIC ARRAY. It supposed to automatically increase the size as needed as shown in this program:
C++:
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> dynArray(3);// define dynamic array of 3 elements
    dynArray[0] = 365;
    dynArray[1] = -421;
    dynArray[2] = 789;
    cout << " Numberof integers in array: " << dynArray.size() << endl; //display the array length

    cout << "Enter another element to insert" << endl;
    int newValue = 0;
    cin >> newValue;
    dynArray.push_back(newValue);

    cout << " Numberof integers in array: " << dynArray.size() << endl;// Display the new array length

    cout << " The last element of array: ";
    cout << dynArray[dynArray.size() - 1] << endl; //The Nth element is dynArray(N-1)

    return 0;
}
I understand the line 17 the number of elements increased by 1 using .push_back() to stuff in the new number. My question is if I don't need that many elements, is there a command to SHRINK the array back?

Sorry I bombard with so many question. I am just going through chapter 1 to 4 with fresh eyes.
 
  • #131
yungman said:
I want to confirm declaration of constant:

int pi = 22/7 = 3
float pi =22/7 = 3.1429

So if I want decimal number, I declare float?
In your first line, pi is initialized to 3. In the second line, pi is initialized to 3.0. This is because 22/7 == 3, due to integer division. Because pi is declared as a float in that line, the value 3 gets promoted to a float value, 3.0.
 
  • #132
Mark44 said:
In your first line, pi is initialized to 3. In the second line, pi is initialized to 3.0. This is because 22/7 == 3, due to integer division. Because pi is declared as a float in that line, the value 3 gets promoted to a float value, 3.0.
Oh! I am still wrong! So how do I get 3.1428?

there goes to show it's never too dumb to ask!
 
  • #133
yungman said:
Wow, this is what I need. Perfect timing while I am reviewing the first 4 chapters. I have a few questions:1) I put this in the heading of my notes and I change a little. I highlighted the key words. I want to confirm using #include<iostream>:

Is iostream a HEADER file where std is the CLASS and cout is OBJECT?
No, std is a namespace: a collection of classes and other stuff. Yes, cout is an object -- a stream object.
yungman said:
2) What do you call the .cpp text file that I created in VS? Is the compiler transforms the text .cpp file into machine code called OBJECTIVE file? Then the next step is to link with other files to form the complete .exe file?
The .cpp file is your source code. The compiler translates it into machine code -- an object file (not objective file). Note that the meaning of object here is different from its use in object-oriented programming. The linker merges in code for whatever library functions you've used.
yungman said:
3) Do you call main() {multiple lines of codes} that is the body of the program as FUNCTION? In fact I can declare any myfunction() { multiple lines of codes} as FUNCTION within the .cpp text file.
Yes, main() is a function. Your program can consist of multiple functions. Note that in C, C++, you can't define a function inside of another function.
yungman said:
I am sure I have more question later.

Thanks
 
  • Like
Likes yungman
  • #134
yungman said:
Oh! I am still wrong! So how do I get 3.1428?

there goes to show it's never too dumb to ask!
Declare pi so that floating point division is performed.
C++:
double pi = 22.0/7;
Now because one operand is double, floating point division will be performed rather than integer division.
 
  • #135
yungman said:
I understand the line 17 the number of elements increased by 1 using .push_back() to stuff in the new number. My question is if I don't need that many elements, is there a command to SHRINK the array back?
The erase() member function of the vector class will shrink the array.
 
  • Like
Likes yungman
  • #136
From your notes, Ch. 1:
* #include <iostream> to perform cout to output streams to display using std::cout << follow by
the “asdfongfasd” for words etc. Where << operator to shift bits LEFT.
The << operator is overloaded, meaning that it has two different purposes.
When it appears with cout, the meaning is to send a stream of bytes to output.
When it appears in an arithmetic express, such as count << 2, it shifts all the bits left by two places.

Several operators are overloaded in C++. These include >>, which is used for both input as well as shifting bits; * is used for multiplication and pointer dereferencing, & is used for bitwise AND and for getting the address of a variable.
 
  • Like
Likes FactChecker
  • #137
Mark44 said:
From your notes, Ch. 1:
The << operator is overloaded, meaning that it has two different purposes.
When it appears with cout, the meaning is to send a stream of bytes to output.
When it appears in an arithmetic express, such as count << 2, it shifts all the bits left by two places.

Several operators are overloaded in C++. These include >>, which is used for both input as well as shifting bits; * is used for multiplication and pointer dereferencing, & is used for bitwise AND and for getting the address of a variable.
What is the meaning of overloaded? Just simple having two purposes? Why don't they call it dual purpose?
 
  • #138
yungman said:
What is the meaning of overloaded? Just simple having two purposes? Why don't they call it dual purpose?
There can be more than two purposes. In C++, but not C (unless it has changed in recent new standards), a function or operator can be overloaded. Here's an example showing the declarations (prototypes) of a function named fun with four overloads.
C++:
int fun(int, int);
int fun(unsigned, unsigned);
int fun(float, float);
int fun(double, double);
A possible motivation might be that each overload adds a pair of numbers of each type. This is a bit fakey, since the function's return type is int, and all overloads must share the same return type.
 
  • #139
yungman said:
What is the meaning of overloaded? Just simple having two purposes? Why don't they call it dual purpose?
They would have to call it n-purpose or multi-purpose because there is no limit. When you define a class, you are allowed to redefine the common operations to make sense in the context of that class. A class of vectors can redefine '+' to add vectors component-wise. A class of data can redefine '+' to put the new data into a database. etc., etc.
I would advise you not to get carried away with this because you are, in a sense, making your own context-sensitive language. One of my annoyances was when I had to figure out someone's code who thought that he would make his own language to do something that is simple and only one-case use. Some people always seem to think that they are creating the next great language.
 
  • #140
Mark44 said:
There can be more than two purposes. In C++, but not C (unless it has changed in recent new standards), a function or operator can be overloaded. Here's an example showing the declarations (prototypes) of a function named fun with four overloads.
C++:
int fun(int, int);
int fun(unsigned, unsigned);
int fun(float, float);
int fun(double, double);
A possible motivation might be that each overload adds a pair of numbers of each type. This is a bit fakey, since the function's return type is int, and all overloads must share the same return type.
I don't think I learn fun(int, int) type, what is this?
 
Back
Top