Trying to decide which programming language I want to learn

Click For Summary
Choosing a programming language to learn can be challenging, especially for someone with a background in older languages like assembly, Fortran, and Pascal. C# and C++ are considered for firmware design, while Python is favored for its ease of use and relevance to gaming, particularly with grandchildren. C++ is noted for its speed and compactness, making it suitable for game programming, but it may require more effort to learn compared to C#. Resources like Visual Studio for C# and various online tutorials can help beginners get started, while microcontroller programming can be explored through platforms like Arduino and Raspberry Pi. Ultimately, the choice should align with personal interests in scientific or gaming applications.
  • #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.
 
Technology news on Phys.org
  • #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

  • #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?
 
  • #141
yungman said:
I don't think I learn fun(int, int) type, what is this?
This is the declaration or prototype of a function with two int arguments, and that returns an int value. In a declaration, the names of the parameters are optional, but in the actual definition, the names are required.
 
  • Like
Likes yungman
  • #142
Mark44 said:
This is the declaration or prototype of a function with two int arguments, and that returns an int value. In a declaration, the names of the parameters are optional, but in the actual definition, the names are required.
Ah, it's like math function f(x,y) = x^2 + y^2.
 
  • #143
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.
Now that I understand fun() is a function with two arguments. How can the program have 4 lines each defining fun() differently particularly fun ( int, int) and fun ( double, double). You can have fun (double, double) be integer, but not the other way around.
 
  • #144
Hi
For once, I have no question! I am hot on the trod on Chapter 5. I looked at one example and I don't like the way the book did, I changed it. I even create functions inside the program so the main() can call and it works. This is on prefix and postfix
C++:
//Difference between prefix and postfix
#include <iostream>
using namespace std;

int PostfixInc()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = num1++;
    cout << "Result of Postfix increment num2=num1++:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    return 0;
}
int PostfixDec()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = num1--;
    cout << "Result of Postfix decrement num2=num1--:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    return 0;
}

int PrefixInc()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = ++num1;
    cout << "Result of Pretfix increment num2=++num1:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    return 0;
}
int PrefixDec()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = --num1;
    cout << "Result of Pretfix decrement num2=--num1:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    return 0;
}
int main()
{

    PostfixInc();
    PostfixDec();
    PrefixInc();
    return PrefixDec();

}

I know this is kindergarten stuff for you guys, but I am happy! I can't wait to get to the next topic on boolean stuffs etc. Then the next chapter is If-Then-Else...About time to move onto some real programming.:biggrin::biggrin:
 
  • Like
Likes FactChecker
  • #145
Here are a couple comments on your latest program.
1. It's not a good idea to do this: "using namespace std;" There's the potential of creating problems for yourself if you happen to choose identifiers that are also using the the std namespace.
A better choice is this, since you are using only two of the identifiers in that namespace:
using std::cout;
using std::endl;

2. None of your functions return anything useful, so it would be better to define them all as void functions, like this. The only thing I've done is to change the return type, and comment out the return statement. It is an error for a void function to return a value.
C++:
void PrefixDec()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = --num1;
    cout << "Result of Pretfix decrement num2=--num1:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    // return 0;   -- commented out, since a void function cannot return a value              
}

3. Call each of the functions like this: PrefixDec();
The fourth function you called like this: return PrefixDec(); -- this doesn't make any sense, because the returned value is not being stored in a variable or being displayed.
 
  • Like
Likes FactChecker
  • #146
Mark44 said:
Here are a couple comments on your latest program.
1. It's not a good idea to do this: "using namespace std;" There's the potential of creating problems for yourself if you happen to choose identifiers that are also using the the std namespace.
A better choice is this, since you are using only two of the identifiers in that namespace:
using std::cout;
using std::endl;

2. None of your functions return anything useful, so it would be better to define them all as void functions, like this. The only thing I've done is to change the return type, and comment out the return statement. It is an error for a void function to return a value.
C++:
void PrefixDec()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = --num1;
    cout << "Result of Pretfix decrement num2=--num1:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    // return 0;   -- commented out, since a void function cannot return a value          
}

3. Call each of the functions like this: PrefixDec();
The fourth function you called like this: return PrefixDec(); -- this doesn't make any sense, because the returned value is not being stored in a variable or being displayed.

I only use what I learn in the 4 chapters and a part of the 5th chapter. I have not learn "void" function.
Can you explain why it's not a good idea to use using namespace std? What is an identifier?

I use " return PrefixDec()" because it gave me the correct display. I never learn this, just saw an example in chapter 2 or 3. Then I just experiment. If I put return in the earlier statement, it will end without going to the function after that. If I don't put return, it gave me an error.

Remember, I do a lot of guessing here as I am only at the beginning of the book. I am just trying things out. The book is not good in the sense it gave out examples with stuffs that have not been covered yet, they even point out it would be in the later chapters. So I just experiment on my own to get the right outcome.

What is the right way to call a function?
 
Last edited:
  • #147
Good comments, but I would like to clarify this:
Mark44 said:
3. Call each of the functions like this: PrefixDec();
The fourth function you called like this: return PrefixDec(); -- this doesn't make any sense, because the returned value is not being stored in a variable or being displayed.
It should run fine, but the idea of returning a hard-coded 0 hidden in the PrefixDec function is questionable. The main() can return a zero to indicate a normal completion or a non-zero error code. What it returns should not be hidden that way in a lower-level function. Typically, if a lower level function can not complete normally, it can return an error indicator and the main can determine what it should do about that. Then main can decide what completion code to return to the operating system.
 
  • #148
FactChecker said:
Good comments, but I would like to clarify this:

It should run fine, but the idea of returning a hard-coded 0 hidden in the PrefixDec function is questionable. The main() can return a zero to indicate a normal completion or a non-zero error code. What it returns should not be hidden that way in a lower-level function. Typically, if a lower level function can not complete normally, it can return an error indicator and the main can determine what it should do about that. Then main can decide what completion code to return to the operating system.
I never even look the display in the debugger "5.2.exe (process 3372) exited with code 0" until you said this. I got the right answer on num1 and num2, I got it to display nicely the way I want it, that's as far as I went on checking.

What does that mean?
 
  • #149
yungman said:
I never even look the display in the debugger "5.2.exe (process 3372) exited with code 0" until you said this. I got the right answer on num1 and num2, I got it to display nicely the way I want it, that's as far as I went on checking.

What does that mean?
It just means that your main() told the operating system that it completed with a completion code 0. It means nothing except that your code always returns 0. If your code did any error checking, you can make main() return a non-zero value (zero usually indicates a successful completion). You decide what the main() returned value should be for different situations. It's up to you. You can run your program in ways that will take special actions if the program did not complete normally.
 
  • #150
I went back and look, I copied pasted something wrong in the original program, main on "return 0" in all the subfunctions. Now it makes a little more sense to me. Everything is the same EXCEPT I put "return 0" at the end of every subfunction and at the end of the main().
Code:
//Difference between prefix and postfix
#include <iostream>
using namespace std;

int PostfixInc()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = num1++;
    cout << "Result of Postfix increment num2=num1++:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    return 0;
}
int PostfixDec()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = num1--;
    cout << "Result of Postfix decrement num2=num1--:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    return 0;
}

int PrefixInc()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = ++num1;
    cout << "Result of Pretfix increment num2=++num1:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    return 0;
}
int PrefixDec()
{
    int num1 = 101;
    cout << "num1 = " << num1 << endl;
    int num2 = --num1;
    cout << "Result of Pretfix decrement num2=--num1:  num1 = " << num1 << "     " << "num2 = " << num2 << endl;
    cout << "  " << endl;
    return 0;
}
int main()
{

    PostfixInc();
    PostfixDec();
    PrefixInc();
    PrefixDec();

    return 0;
}

This book has very few problem at the end. I am waiting for the other 2 books, hopefully they have more assignments I can write programs. For now, I can only play around like this.BTW, how come there's no color on my program this time? Just black characters only, but with all the indents.
 
Last edited:

Similar threads

  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 133 ·
5
Replies
133
Views
10K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
16
Views
3K
  • · Replies 54 ·
2
Replies
54
Views
5K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 58 ·
2
Replies
58
Views
4K