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.
  • #331
yungman said:
Yes, I found out after design the program, that switch-case doesn't take conditional statement. That is switch can only take simple case of A, B, C, D etc. It will not read

switch ( temp)
case ( temp <101):
case (temp >103):

I have no choice but to use if-else if - else to put A, B and C for the case statement.
You can make the program a lot simpler by eliminating the switch statement. Also, it simplifies things greatly if you don't confuse the user by asking for numeric and character input (i.e., asking for a temperature followed by the Enter character to quit).

Here's my simplified version.
C++:
// Program checks temperature.
// If 101 <= temp <= 103deg C, check every 15mins.
// If temp > 103 C, turn heat down, check every 5 minutes until correct temp.
// If temp < 101 C, turn heat up, check every 5 minutes until correct temp.
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
    int temp;

    do
    {
        cout << "Enter the temperature, or a negative number to quit.   ";
        cin >> temp;            // Read temperature.
        if (temp < 0) break;    // If negative, exit do loop.
       
        if (temp < 101)
        {
            // Temperature too low.
            cout << "Raise the temperature, wait 5 minutes and measure again.\n\n";
            continue;

        }
        else if (temp > 103)
        {
            // Temperature too high.
            cout << "Lower the temperature, wait 5 minutes and measure again.\n\n";
            continue;
        }
        else
        {
            // Temperature is between 101 and 103 degrees C.
            cout << "Wait 15 minutes and measure again.\n\n";
            continue;
        }               

    } while (true);
    cout << "You chose to quit, goodbye.";
}
The do ... while loop is an infinite loop that uses continue to start a new loop iteration, and break to get completely out of the loop.

Input from the user is asked for once, at the top of the loop. The user can enter any integer value 0 or larger, or can enter any negative number to exit the program.
 
  • Like
Likes yungman
Technology news on Phys.org
  • #332
Mark44 said:
You can make the program a lot simpler by eliminating the switch statement. Also, it simplifies things greatly if you don't confuse the user by asking for numeric and character input (i.e., asking for a temperature followed by the Enter character to quit).

Here's my simplified version.
C++:
// Program checks temperature.
// If 101 <= temp <= 103deg C, check every 15mins.
// If temp > 103 C, turn heat down, check every 5 minutes until correct temp.
// If temp < 101 C, turn heat up, check every 5 minutes until correct temp.
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
    int temp;

    do
    {
        cout << "Enter the temperature, or a negative number to quit.   ";
        cin >> temp;            // Read temperature.
        if (temp < 0) break;    // If negative, exit do loop.
    
        if (temp < 101)
        {
            // Temperature too low.
            cout << "Raise the temperature, wait 5 minutes and measure again.\n\n";
            continue;

        }
        else if (temp > 103)
        {
            // Temperature too high.
            cout << "Lower the temperature, wait 5 minutes and measure again.\n\n";
            continue;
        }
        else
        {
            // Temperature is between 101 and 103 degrees C.
            cout << "Wait 15 minutes and measure again.\n\n";
            continue;
        }            

    } while (true);
    cout << "You chose to quit, goodbye.";
}
The do ... while loop is an infinite loop that uses continue to start a new loop iteration, and break to get completely out of the loop.

Input from the user is asked for once, at the top of the loop. The user can enter any integer value 0 or larger, or can enter any negative number to exit the program.
Thanks for taking the time. I did started out with flowing through concept like what you have. But my goal is to continuous monitoring. It became messy doing it this way.

Like I explain before, my program is like a kindergarten version of closed loop feedback temperature control, not just doing one adjustment and it's done. The way I loop is to monitor over and under shoot of temperature and adjust so it will settle into the optimal range. I can envision in the future, I can add time constant within the do-while that nested under the switch-case to control the oven, if the Temp is over 10deg below the lower limit, crank the oven high, but when temp approach the lower limit, turn the oven down and ease into the optimal range. Then when it's in optimal range, keep it there by touching up the oven control every time it loops around.

I did this more in system point of view, I spent a few hours designing the flow chart, only like half an hour to code it.

I can't wait to get to chapter 6 functions and chapter 9 pointers.

Thanks for you time to look at it.
 
Last edited:
  • #333
I am studying chapter 6 Functions. I am confused, I read all along that C++ is an Object Oriented programming, that the program calls on Objects to perform a certain task. That an Object is a self contained unit the consists of it's data and codes to work on the data. That the program call on the Object with given parameters and the Object performs the task and return back the parameters.

But this is EXACTLY what Gaddis book described as Function! That the main() is a function, each of the Object ( subroutine) it calls is a Function. That the Headers the program used in #include <> contain all the Function needed.

What am I missing? This goes right back to my biggest road block in learning the C++ again. I have to say after writing quite a bit of programs by now, coding and even designing the program is the EASY part of C++. This kind of fancy naming is the difficult part and the most confusing part. I am so lucky I decided to order my grandson's book( Gaddis), or else I would be still be struggling.
 
  • #334
Again, I will say that I don't have Gaddis's book, so I am just guessing. Nevertheless, based on my experience with C++ textbooks many years ago, I will guess that he and you are still in the realm of procedural programming.

I will guess that a following chapter will introduce you to "structs", which are collections of data of different types, as opposed to arrays, which are collections of data of the same type.

Then, a later chapter will introduce you to "classes". They define objects that are basically structs that also include "member functions" that act on the data that the objects contain. Then you will enter the realm of object-oriented programming.
 
  • Like
Likes yungman
  • #335
Gaddis gets to objects and structures in the next chapter. He is working you thru procedural programming then he eases you into object oriented. The best layman's description I can give is that a function can return one thing only, i.e., a matrix, a float etc...whereas a structure with it's defined functions, can return a collection of things.

I remember when I was taking the course, we had to write a program to calculate trhe propertiesd of a rectangle, the area and perimeter. Both take the exact same arguments and I remember saying that if I could return two things from this function, I'd only have to write one function. Whohooo when I learned about structures and classes...
 
  • Like
Likes jtbell and yungman
  • #336
Dr Transport said:
Gaddis gets to objects and structures in the next chapter. He is working you thru procedural programming then he eases you into object oriented. The best layman's description I can give is that a function can return one thing only, i.e., a matrix, a float etc...whereas a structure with it's defined functions, can return a collection of things.

I remember when I was taking the course, we had to write a program to calculate trhe propertiesd of a rectangle, the area and perimeter. Both take the exact same arguments and I remember saying that if I could return two things from this function, I'd only have to write one function. Whohooo when I learned about structures and classes...
I guess I am too impatience! I'll wait till I get there.

thanks
 
  • Like
Likes Dr Transport
  • #337
I am back to my question of my original title of this thread. I am going to finish this C++ following the college class. I want to look ahead to what's next to plan ahead. I picked C++ first as it's the closest to my trade, hardware application where C++ is closest to the real hardware and the fastest.

1) What language Windows use in their programs? Like if I want to understand windows, what language should I learn next or what stuff should I learn? I have a suspicion it's NOT C++.

2) What language is most common for web design?

3) What language is most common for writing games?

Thanks
 
  • #338
yungman said:
2) What language is most common for web design?
Do you mean "web design" as in the graphic design and layout of the page or are you using the term to me "web delvelopment" that is the creation of websites and web based apps.

In terms of web design, it is mostly HTML and CSS, both of which are pretty simple and straight forward. To some extent Javascript (JS). But the use of JS begins to blur the line between design and development.

In terms of web development, you must also make the distinction between server side and client side. For the server side, the most common language is most likely PHP. Client side it is by far JS as it is native to every available browser. Other languages would require some kind of client download.

Personally I don't like PHP, I much prefer Python, you can use frameworks such as Flask, Django or multitude of others. Then you can use the same language to other non-web related things. And, you can then integrate your non-web things with the web and not require any other languages.

Client side, I like to stick with plain Javascript, but you can use other frameworks such as React, Angular, or JQuery and then also use JS server side with NodeJS.
 
  • Like
Likes sysprog and yungman
  • #339
I was searching on google, it said Windows Kernals are written in C, C++ or C#. Does that mean the Windows is written in C related language, that I am learning the right language?
 
  • #340
yungman said:
I was searching on google, it said Windows Kernals are written in C, C++ or C#. Does that mean the Windows is written in C related language, that I am learning the right language?

Unless you are planning on writing Windows kernel code, or a Windows driver for some piece of hardware, you don't have to write Windows programs in the same language as the Windows operating system is written in.

AFAIK the language Microsoft currently seems to be pushing for people to write Windows programs in is F#, which is a sort of successor to C#. I personally don't have any need or desire to use anything Microsoft is pushing; when I need to write code to run on Windows, I write it in Python.
 
  • Like
Likes sysprog
  • #341
PeterDonis said:
Unless you are planning on writing Windows kernel code, or a Windows driver for some piece of hardware, you don't have to write Windows programs in the same language as the Windows operating system is written in.

The language Microsoft currently seems to be pushing for people to write Windows programs in is F#.
Thanks for the reply, I am more interested in understanding windows, I thought knowing that language allows me to read some of their codes to understand it better. Understand how the kernels and drivers work is good too.
 
  • #342
yungman said:
Thanks for the reply, I am more interested in understanding windows, I thought knowing that language allows me to read some of their codes to understand it better. Understand how the kernels and drivers work is good too.
Windows is mostly supplied as object code only (non-source), although various versions of various pieces of it have been leaked. MS has provided a lot of other material for open source distribution. MS recently released source code for Windows Calculator
https://github.com/Microsoft/calculator
and for Windows File Manager
https://github.com/Microsoft/winfile/

For general understanding of inner workings of Windows, you might check out Inside OS/2 (1988), by Gordon Letwin.
 
Last edited:
  • Like
Likes yungman
  • #343
Thanks for the reply, sounds like people can use any program to write to interface with Windows. I kept thinking you have to match the language of the program written in order to interface and work with the existing program. I guess you don't have to, you just need to know the interface.

Is it generally true that you can use C++ to interface with any other language? Is there a standard of interfacing that people follow?

If that is all true, then there is NO need to learn different languages, you just need one and you can do everything! I understand that maybe it's more convenient using one language over another for certain situation, but it can be done using one language only. Is that true?

BTW, I am surprised I don't have question lately. With Gaddis, it's been smooth. Particular as I learn more, when I google, I found out they are not all written in Russia! Some actually written in English! At the beginning, when you guys kept saying google first, but when I did that, they all seemed to be written in Russian to me! Now it's getting better.

Thanks
 
  • #344
yungman said:
I kept thinking you have to match the language of the program written in order to interface and work with the existing program. I guess you don't have to, you just need to know the interface.

Windows is not a program, it's an operating system. All operating systems have interfaces that any program has to use, and all programming languages have library functions that know about the interfaces of all operating systems that those programming languages can run on.

Programs in general don't have interfaces; they aren't designed to have other programs work with them. They're just designed to do whatever it is they do.

yungman said:
Is it generally true that you can use C++ to interface with any other language?

No.

yungman said:
Is there a standard of interfacing that people follow?

No.

yungman said:
If that is all true, then there is NO need to learn different languages, you just need one and you can do everything! I understand that maybe it's more convenient using one language over another for certain situation, but it can be done using one language only. Is that true?

You can in principle write pretty much any program in any language. But many programs are much easier to write in some languages than in others.
 
  • Informative
Likes yungman
  • #345
PeterDonis said:
......
You can in principle write pretty much any program in any language. But many programs are much easier to write in some languages than in others.
What is the best language to interface with Windows?

What is the most popular language to write pc gaming?

Thanks
 
  • #346
I spoke too soon. I fail to compile this program. It's a very simple program but if failed. It is EXACTLY as in the book, I checked many times and I also understand what the program want and everything is correct.
C++:
//Default Arguments
#include <iostream>
using namespace std;

void displayStars(int = 10, int = 1);// Default argument to 10 and 1 in prototype.

int main()
{
    displayStars(); cout << endl;
    displayStars(5); cout << endl;
    displayStars(7,3); cout << endl;
    return 0;
}

void displayStars(int cols, int rows)
{
    for(int down = 0; down < rows; down++)
    {
        for (int across = 0; across < cols; across++)
        {
            cout << "*";
        }
        cout << endl;
    }
}

The error message is:
Compile error file write.jpg


Can anyone see what's happened? What does that mean of cannot open the file? It's opened, I am working on it!

Thanks
 
  • #347
Next time you get an error message, please try looking it up:

1597002465771.png

You can see from the explanation that the error has nothing to do with the program code.
 
  • #348
yungman said:
What is the best language to interface with Windows?

I don't think there is a single "best" language to interface with any operating system. All major languages know how to interface with all major operating systems.
 
  • Like
Likes sysprog
  • #349
sysprog said:
Next time you get an error message, please try looking it up:

View attachment 267544
You can see from the explanation that the error has nothing to do with the program code.
I read a few this before I posted, I don't understand why.

It is strange. I copy the .cpp out, created another project, put in the EXACT source.cpp. It ran on the new project under new name.

What went wrong, that's what I don't understand.

It's even more strange, I closed VS, I try to delete the whole program folder that has problem, I can't even delete it, it said the program is opened somewhere! I closed everything. The only other thing left is restart the computer!
 
  • #350
yungman said:
I read a few this before I posted, I don't understand why.

It is strange. I copy the .cpp out, created another project, put in the EXACT source.cpp. It ran on the new project under new name.

What went wrong, that's what I don't understand.
The message explanation refers to what amounts to a version control problem (can't find referenced file in this version) that is entirely unrelated to anything in the .cpp code.
 
  • #351
sysprog said:
The message explanation refers to what amounts to a version control problem (can't find referenced file in this version) that is entirely unrelated to anything in the .cpp code.
I know now, I had to restart my computer, now everything is fine! Strange. But thanks anyway.
 
  • #352
yungman said:
I know now, I had to restart my computer, now everything is fine! Strange. But thanks anyway.
Restarting the computer resets environment variables including the global multi-path PATH variable.
 
  • #353
yungman said:
What is the best language to interface with Windows?

What is the most popular language to write pc gaming?

Thanks
The terminology is API (application program interface).
https://en.m.wikipedia.org/wiki/Application_programming_interface

For interfacing across languages, the terminology is language binding.
https://en.m.wikipedia.org/wiki/Language_binding

There are APIs for operating systems and APIs for graphics and game engines as well. What you may look at if you want to do a particular style of development is what APIs are available. Windows APIs seem to be mostly written in C or C++, but there are usually bindings for other languages to use them.
https://en.m.wikipedia.org/wiki/Lis...ication_programming_interfaces_and_frameworks

For professional game development, Unreal Engine is the most advanced engine. The best language for interfacing to that would be C++ as far as I know. https://docs.unrealengine.com/en-US/Programming/index.html.
 
Last edited:
  • Like
Likes sysprog and yungman
  • #354
Jarvis323 said:
The terminology is API (application program interface).
https://en.m.wikipedia.org/wiki/Application_programming_interface

For interfacing across languages, the terminology is language binding.
https://en.m.wikipedia.org/wiki/Language_binding

There are APIs for operating systems and APIs for graphics and game engines as well. What you may look at if you want to do a particular style of development is what APIs are available. Windows APIs seem to be mostly written in C or C++, but there are usually bindings for other languages to use them.
https://en.m.wikipedia.org/wiki/Lis...ication_programming_interfaces_and_frameworks

For professional game development, Unreal Engine is the most advanced engine. The best language for interfacing to that would be C++ as far as I know. https://docs.unrealengine.com/en-US/Programming/index.html.
Thanks so much, this is informative. I copied your reply and the links so when time comes, I will look deeper into this.

thanks
 
  • #355
I have a question about using ++, -- on an array element. I already googled error C2105, this is what I found that works. But I still have question as the Gaddis book say it's ok, but it's not.

C++:
#include <iostream>
using namespace std;
int main()
{
    int a[] = { 1, 2, 3, 4, 5 };
    int i = 0, j=0; // Second index number of the array a[]
    cout << " a[i++] = " << a[i++] << "\n\n";
    //cout << " a[0++] = " << a[0++] << "\n\n";// This doesn't work, has to be variable or literal
    cout << " a[j++] = " << a[j++] << "\n\n";// This work, using variable or const
    return 0;
}

The line in question is line 8. I put '//' in front before I can compile.
Compile error file write.jpg


Using line 9 works. This means it works if I use a variable 'j' as a[j++], but if I use a[0++], it will not compile. this is all good EXCEPT, Gaddis book is using a[0++].

So what is the problem here?

thanks
 
  • #356
yungman said:
but if I use a[0++], it will not compile.
How do you think the compiler should interpret that?

yungman said:
this is all good EXCEPT, Gaddis book is using a[0++].
I don't have that book but I'm pretty sure the closing ] is in a different place.

Also, as I think has been mentioned before in this thread (although it is hard to keep track over 355 posts), a[j++] is a good way to get into a mess even if you know what you are doing.
 
  • Like
Likes sysprog
  • #357
pbuk said:
How do you think the compiler should interpret that?I don't have that book but I'm pretty sure the closing ] is in a different place.

Also, as I think has been mentioned before in this thread (although it is hard to keep track over 355 posts), a[j++] is a good way to get into a mess even if you know what you are doing.
Thanks for the reply. I am just following the book to learn. I do think it's kind of strange to advance to another element of the array this way.

No, I did not put the ++ in the wrong place, I took that part out of the program before I post to make it simpler.

Yes, I would avoid using arr[j++] that really doesn't made much sense to use when it's so easy to just do j=j+1 or something.
 
  • #358
++i means increment i and then evaluate the expression. i++ means evaluate the expression and then increment i. 0++ would mean evaluate the expression then increment 0. But 0 is temporary; after the expression is evaluated that instance of 0 doesn't exist anymore, so there is nothing to increment.

The rule to remember is ++ before means increment before, and ++ after means increment after.
 
  • Like
Likes sysprog
  • #359
Can you please quote more of what you're saying about what Gaddis said?
 
  • Like
Likes pbuk
  • #360
what is the number and name of the section in Gaddis? I see in my copy where he decrements and increments array indices, but I don't see the problem you are referring to

Also, 0 is a number and cannot be incremented nor decremented, only variables can
 
  • Like
Likes sysprog and pbuk

Similar threads

  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 107 ·
4
Replies
107
Views
9K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
16
Views
3K
  • · Replies 54 ·
2
Replies
54
Views
5K
  • · Replies 11 ·
Replies
11
Views
2K
  • · 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