For those who ask: "What programming language should I learn?"

  • Thread starter Thread starter pbuk
  • Start date Start date
AI Thread Summary
Choosing a programming language to learn depends on your goals. Python is recommended for machine learning, web applications, and data analysis, while JavaScript is ideal for web development. C# is suited for game development and Windows applications, whereas C++ is best for performance-critical applications like games and operating systems. Beginners are advised against starting with C++ due to its complexity and potential for confusion, with suggestions leaning towards Python or Java for foundational learning. Ultimately, the choice of language should align with the specific applications you wish to pursue in programming.
pbuk
Science Advisor
Homework Helper
Gold Member
Messages
4,969
Reaction score
3,217
TL;DR Summary
If you are new to programming, learn Python - it is relatively easy to learn and you can do a lot with it.
LearnIf you want to write code for
PythonMachine learning, AI
Statistics/data analysis
Scientific research
Web application servers
Some microcontrollers
JavaScript/Node JS/TypeScriptWeb sites
Web application servers
C#Games (Unity)
Consumer applications (Windows)
Business applications
C++Games (Unreal Engine)
Operating systems, device drivers
Microcontrollers/embedded systems
Consumer applications (Linux)

Some more tips:
  • Do not learn C++ (or any other dialect of C) as a first language - there are too many things to learn that are unimportant that distract from focusing on what is important.
  • Do not learn C++ (or any other dialect of C) because you believe that it is "fast" in some general sense - the contexts in which this may be relevant are limited to those mentioned above (games, embedded systems etc.)
  • Do not learn C++ because you believe that all interviewers expect you to use it to answer coding questions - in 2023 this is no longer true in many cases, and it is easier and quicker to solve coding problems correctly in e.g. Python. Of course if you are going for a job writing device drivers at NVIDIA this is not going to apply, but if you think you can get a job writing device drivers at NVIDIA you don't need advice on learning to code anyway.
  • Do not avoid Python or Node JS because you believe that they are "slow" - the contexts in which this may be true are unlikely to be relevant to you.
  • Do not learn how to implement algorithms and data structures like linked lists, hash tables, trees, indexing, sorting etc - these algorithms have already been implemented optimally in the languages that you will learn (although the comment about NVIDIA etc. above applies).
 
Last edited:
  • Like
  • Informative
Likes DeBangis21, CGandC, phyzguy and 2 others
Technology news on Phys.org
I would say that, between Python and C++, Python is best for the hobbyist and C or C++ is best for job opportunities.
Your comments about the speed of Python not being important ignore that it can be 40 times slower. That is annoyingly slow for many serious applications.
 
FactChecker said:
Your comments about the speed of Python not being important ignore that it can be 40 times slower. That is annoyingly slow for many serious applications.
That might be why @pbuk listed areas where either the speed is not an annoyance (for example, web servers are network I/O bound, not CPU bound, and network I/O is roughly 1000 times slower so a factor of 40 slowdown is not a problem) or there are extension modules written in C (or even assembly language) to do the CPU intensive work (microcontrollers, scientific research, statistics/data analysis, and I expect ML/AI to move in this direction if it hasn't already).

I have also used Python for GUI programs and interactive scripts where the program spends most of its time waiting for user input and responses to each user input are not CPU intensive. Here again speed is not an issue because the program is not CPU bound.
 
  • Like
Likes Klystron, pbuk, berkeman and 1 other person
PeterDonis said:
That might be why @pbuk listed areas where either the speed is not an annoyance (for example, web servers are network I/O bound, not CPU bound, and network I/O is roughly 1000 times slower so a factor of 40 slowdown is not a problem) or there are extension modules written in C (or even assembly language) to do the CPU intensive work (microcontrollers, scientific research, statistics/data analysis, and I expect ML/AI to move in this direction if it hasn't already).

I have also used Python for GUI programs and interactive scripts where the program spends most of its time waiting for user input and responses to each user input are not CPU intensive. Here again speed is not an issue because the program is not CPU bound.
I think that is all true. But one must be careful about saying that speed is not important. It is often ignored on small examples and then the program must be converted to another language for larger problems. Of course, if there are C libraries that do the real work, then they can be used, but relying on those libraries can be a problem in itself. A few of my last jobs were to completely rewrite large programs to make them independent of licensed libraries.
 
FactChecker said:
if there are C libraries that do the real work, then they can be used, but relying on those libraries can be a problem in itself
In general, yes, but in the particular cases that were mentioned, there are well-established libraries (for example, numpy and scipy) that have proven themselves to be reliable and fast.
 
FactChecker said:
I would say that, between Python and C++, Python is best for the hobbyist and C or C++ is best for job opportunities.
Can you support that with evidence? Here is some evidence that that is not the case: https://www.devjobsscanner.com/blog/top-8-most-demanded-languages-in-2022/

FactChecker said:
Your comments about the speed of Python not being important ignore that it can be 40 times slower.
No they dont, what I said was that the contexts in which Python can be 40 times slower are unlikely to be relevant to someone deciding what programming language to learn.
 
pbuk said:
Can you support that with evidence? Here is some evidence that that is not the case: https://www.devjobsscanner.com/blog/top-8-most-demanded-languages-in-2022/
I retired as a programmer about 7 years ago. I can say that I saw occasional Python programs but the vast majority was C or C++. IMO, most programmers do not have the authority to determine what language they use in a job; they use the language of the already existing code at that company.
pbuk said:
No they dont, what I said was that the contexts in which Python can be 40 times slower are unlikely to be relevant to someone deciding what programming language to learn.
Learning for what use? Hobby or on a job at a company?
 
I wonder if any of this matters anymore with LLMs - if you can code in any high-level language or just do clear enough pseudo-code, the LLM can convert it
 
  • Like
Likes FactChecker
BWV said:
I wonder if any of this matters anymore with LLMs - if you can code in any high-level language or just do clear enough pseudo-code, the LLM can convert it
That is a good question for future programmers. It's hard for me to imagine what the future, even the near future, will be like. Where I worked, we were not even allowed to use some higher-level optimization options of compilers. :wideeyed:
 
Last edited:
  • #10
While I like the concept of this thread, I am afraid that too often the context of the question is "All I need to know to become a highly paid programmer is for someone to tell me what language to learn." I disagree with this, and I think the job market bears me out.

There is more to programming than syntax.

I want to like Python. I really do. It just seems that Python is today's BASIC. Whitespace being significant is absurd. I might be able to learn to live with that if I didn't see my colleagues producing thousands of lines of unmaintainable spaghetti code.` "Rapid prototyping" is good. "I never have to design" and "I can start coding before I start thinking" is not so good.

I'd like Python more if it was limited to say 500 lines. :smile:
 
  • Like
Likes DrClaude, phinds, pbuk and 2 others
  • #11
BWV said:
if you can code in any high-level language or just do clear enough pseudo-code, the LLM can convert it
Current LLMs do not do this based on the actual meaning of the code, they do it purely based on relative token frequencies. That is not a reliable method of translation.

I believe there has been work done on doing inter-language translations based on abstract syntax trees, which does capture the meaning of the code, but I don't know what tools currently exist for that.
 
  • #12
I would recommend people to learn Java as their first programming language. Yes, you may say it has a lot of boilerplate code. But dealing with indentation errors is not what I would like to encounter when I am absolutely new to programming, and not fully familiar with an IDE. Maybe you will say that learning OOP is not necessary for programming. True, but OOP helps build programming logic in a certain direction. Each variable always having a global scope is also an issue in Python. The loop variable is available even outside the loop. For a newbie, this could give rise to logical errors if not careful. In Java, declaring a variable inside the loop keeps it inside.
 
  • Like
Likes shivajikobardan
  • #13
In general, my experience is that people pay too much attention to speed too early in the process.

Getting the wrong answer more quickly is seldom helpful.
Working hard to speed up a piece of code that didnt take up much of the time to begin with likewise.
 
  • #14
chagpt-coding.png
 
  • Haha
Likes OmCheeto, Demystifier, Filip Larsen and 3 others
  • #15
Wrichik Basu said:
I would recommend people to learn Java as their first programming language.
So in my table where I have "Learn... Java" on the left, how do you complete "If you want to write code for..." on the right?

Wrichik Basu said:
But dealing with indentation errors is not what I would like to encounter when I am absolutely new to programming
C:
// So you are OK with code that looks like this?
void myFunction ()
 {   if (someFlag = true)
    doThis();
    doThat();
  doSomethingElse();}

Wrichik Basu said:
Maybe you will say that learning OOP is not necessary for programming.
All the languages in my OP support OOP (that looks like an "oops", but isn't).
 
Last edited:
  • #16
Wrichik Basu said:
Maybe you will say that learning OOP is not necessary for programming.
Nor is it necessary for learning Python.

Wrichik Basu said:
Each variable always having a global scope is also an issue in Python.
I don't know what you're talking about. Only variables defined at the module level have global scope (which really means module scope) in Python.

Wrichik Basu said:
The loop variable is available even outside the loop.
Yes, but only within the function in which the loop is defined. Only if the loop is at the module level (i.e., not inside any function) will its loop variable be visible at module level. If that's a problem, just wrap the loop inside a function.
 
  • #17
As far as speed goes, let me also say that some people have a knack for writing slow code in any language. :smile:

Beginners? Java has one thing going for it: in C++ there are usually many ways to do something. Java tries to reduce this, ideally to one. Ruby, while not as popular, is similar in thsi regard. It also tries to minimize surprises ("principle of least astomishment") which is good.

There are two things I like about Ada. One is the uber-strong typing. If you understand strong typing, you better understand where and when it can or should be relaxed. The thing I like, and the world hates - well, hated - was the propensity to throw compile time errors. For me, this is a good thing: better to find a problem at compile time

But if I were teaching beginners, I'd probably go with Pascal. It's about as trendy as an Oldsmobile, but like your grandfather's car, it's good to learn on. Strong typing, block structured, and you can go a semester without running into the limits of the language.
 
  • Informative
Likes Klystron and symbolipoint
  • #18
Vanadium 50 said:
But if I were teaching beginners, I'd probably go with Pascal. It's about as trendy as an Oldsmobile, but like your grandgather's car, it's good to learn on. Strong typing, block structured, and you can go a semester without running into the limits of thge language.
I love Pascal, it's the second high level language I learned*. However that was 40 years ago, and also it runs into the same problem as Java: if the best answer is "Learn Pascal", what is the remainder of the sentence "if you want to write code for..."?

* Edit: I forgot about a bit of RPG III before Pascal. Oh and Forth.
 
  • #19
I think the best approach is before learning to "write code for X" one learns to "write code".

I recognize I am in the minoruty here. That doesn't make me wrong/
 
  • Love
Likes Lord Jestocost
  • #20
You might take a look at a random selection ofg programming questions either here or on the interwebs. They start wiyj "I am trying to program X in Y language" and end with:

"You have an uninitialized variable"
"That variable has moved out of scope."
"You made changes to a copy of the variable/object not the original"
"That condition neve`r gets tested for`:

and we might as well be saying "Bleeble gozzle nordle zev."
 
  • #21
pbuk said:
I love Pascal, it's the second high level language I learned*. However that was 40 years ago
Somewhat OT: For me it was the third, after a bit of PL/C and some BASIC (which used to be an all-caps acronym for Beginner's All-purpose Symbolic Instruction Code (as I recall). Not long after that was Fortran and another Wirth language, Modula-2. Pascal for me was also about 40 years ago.
 
  • Like
Likes symbolipoint
  • #22
pbuk said:
Oh and Forth.
Which, ironically, pushes Pascal into fourth.
 
  • Haha
Likes Vanadium 50 and pbuk
  • #23
Vanadium 50 said:
You might take a look at a random selection ofg programming questions either here or on the interwebs. They start wiyj "I am trying to program X in Y language" and end with:

"You have an uninitialized variable"
"That variable has moved out of scope."
"You made changes to a copy of the variable/object not the original"
"That condition neve`r gets tested for`:
I have, that was my motivation for writing the OP (which I hope may be stickied here when refined).

My experience is that many of these questions start with "I am trying to program X in C++", and it becomes clear sooner or later that the questioner is wasting their time learning C++. So the post is really about discouraging people from learning C++ unless they have a specific relevant goal in mind, in which case their learning can be directed by that specific goal.
 
  • #24
pbuk said:
So in my table where I have "Learn... Java" on the left, how do you complete "If you want to write code for..." on the right?
"To build your programming logic and thought process, assuming you are absolutely new to programming."
pbuk said:
C:
// So you are OK with code that looks like this?
void myFunction ()
 {   if (someFlag = true)
    doThis();
    doThat();
  doSomethingElse();}
Zero indentation is not preferable, but at least Java will not throw an error if you give three spaces instead of four on a particular line. In addition, for an absolute beginner, the braces are a must, in my opinion. Shorthands can come later. I have seen my friends in college, who have had no programming experience before, suffer badly due to indentation issues in Python. Especially because our uni does not use any IDE, but only gedit or Notepad.
pbuk said:
All the languages in my OP support OOP (that looks like an "oops", but isn't).
Agreed, but OOP is not necessary if you want to program in Python. In Java, unless you are using JDK 21 with unnamed classes and instance main methods, you have to have an idea of classes. Complete idea is not necessary, but you need to be able to understand what objects are, variable scope in static methods and so on.
 
  • #25
Wrichik Basu said:
"To build your programming logic and thought process, assuming you are absolutely new to programming."
Ah, but that's a different table that looks like this:

If you want toLearn
Build your programming logic and thought process, assuming you are absolutely new to programmingOne of: Java, JavaScript, Pascal :wink:, Perl, PHP, Processing, Python, Scratch, TypeScript, Visual Basic, ... (each has strengths and weaknesses)

Given that no two programmers can agree on what should be on the RHS that is not a very helpful table.

Wrichik Basu said:
In Java ... you need to be able to understand what objects are, variable scope in static methods and so on.
I do not consider that a strength as a first language - there are more important things to learn first.
 
  • #26
All I can say is Javascript is too tough. Specially ES6.
 
  • #27
shivajikobardan said:
All I can say is Javascript is too tough. Specially ES6.
I don't agree, particularly in comparison to C++ which you have decided to focus on.

What I think you have found tough in javascript is moving from the procedural/object oriented paradigms to the event driven paradigm: this is a difficult leap in any language.
 
  • #28
@pbuk How does one make themselves familiar with the event driven mechanism of javascript? Also why're you against data structures leetcoding? I agree C++ is tough but I had no option because of STL.
 
  • #29
Who is the audience?

Is it people who know zero programming and want to learn their first language?
Is it people who want to get a high-paying job in computer science without learning all that icky computer science?
Is it people that need to be steered away from C++ as a good starting point?
 
  • #30
shivajikobardan said:
How does one make themselves familiar with the event driven mechanism of javascript?
Practice. The two classic apps to practice with are a calculator and a to-do list: there are plenty of tutorials on the web. This applies not just to JavaScript but to every event-driven application, the difference with JS is that event handling is built into the language rather than handled by third party libraries e.g. Swift for Java, Tkinter for Python, GTK, qt, etc. for C++. I guarantee you that creating a GUI to-do list app in C++ is many times harder than in JavaScript.

shivajikobardan said:
Also why're you against data structures leetcoding?
I'm not, there are some great practice tasks on Leetcode e.g.
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
and Leetcode defaults to Python for new users (Edit: I've just realised it defaults to Python 2: this is insane and should be changed to Python 3) - this is a great task to practice your programming skills.
shivajikobardan said:
I agree C++ is tough but I had no option because of STL.
I don't understand what this means, can you phrase it differently?
 
Last edited:
  • #31
@pbuk I mean because of standard template library it is easier to study leetcode in c++.
 
  • #32
shivajikobardan said:
@pbuk I mean because of standard template library it is easier to study leetcode in c++.
I think you are mistaken, what gave you that idea?

The STL implements in C++ features that are built in to other high level languages. So the leetcode C++ template for the above problem uses std::vector from the STL not to make it easier, but because it has to.

The Python template uses Python's built in lists, the JavaScript template uses JS's built in arrays...,
 
  • #33
I) Speed is not the only issue
When you have a speed or timing constraint that gets you worrying about milliseconds or microseconds, then C and C++ look very good. But in many applications, particularly embedded applications, the greatest imperative is for the object code footprint - including engines, libraries, and the runtime environment.

II) First language for hobbyist:
I suggest HTML/CSS/JavaScript. For Chrome and Firefox, it's as convenient as the F12 key.

III) First language for the pre-professional:
There was once a time when there were only two types of programmers, Cobol and Fortran - and Fortran programmers were expected to be comfortable with assembler.
Now the market is not so simple: Here's an article that gives the rundown.

But as important as it is to have a SW skills attractive to potential employers, more important is that you find it attractive. Otherwise, you will never enter the marketplace. It is okay for your first language to be cheap, easy, with lots of opportunity to quickly see the results of your creative efforts. Once you known what programming is, and you have proven to yourself that you can survive happily in such a world, then perhaps something like this will work for you:

1) Find some job listing that describe what you want.
2) Practice the additional software language and tool skills that you need to move in that direction.
3) If you ended up choosing skills that are too much of a challenge, you may need better mentorship or you may need to retarget the kind of job you are looking for.

and best of luck
 
  • Like
Likes symbolipoint
  • #34
Wrichik Basu said:
I would recommend people to learn Java as their first programming language. Yes, you may say it has a lot of boilerplate code. But dealing with indentation errors is not what I would like to encounter when I am absolutely new to programming, and not fully familiar with an IDE. Maybe you will say that learning OOP is not necessary for programming. True, but OOP helps build programming logic in a certain direction. Each variable always having a global scope is also an issue in Python. The loop variable is available even outside the loop. For a newbie, this could give rise to logical errors if not careful. In Java, declaring a variable inside the loop keeps it inside.

I can fully support this. As a first programming language, I would always recommend Java. It makes you learn about structured code, forces object oriented thinking, separation of concerns, and keeping track of type-checking, without the added complexities of C++.
Python is great for prototyping (basically the modern Perl), but is very hard to manage in large scale programs.

JavaScript is a lousy language, but unfortunately mandatory for client side web programming.
For systems programming on Windows, learn C#. For systems programming on any Apple platform: Swift. For any other platform (including Android): Java.

To add to that: in the day-to-day practice of programming, you will find out that you spend a lot more time learning libraries than learning the programming language.
 
  • Like
Likes Wrichik Basu
  • #35
Vanadium 50 said:
Who is the audience?
Mainly this:
Vanadium 50 said:
Is it people that need to be steered away from C++ as a good starting point?
 
  • #36
That's fair, but I might focus on that.

I do think C++ has gotten a bit of an unfair rap (but some of its problems are ignored, so maybe it averages out) because it exposes what people don't understand. Scoping certainly. Strong typing. Pointers. Maybe you remember confused by call-by-value. Toss in STL and now you expose a lack of understanding of data structures - do I want a list or a vector or a dequeue or...
 
Last edited:
  • #37
One thing that’s not been brought up here is the fragile base class issue of OOP languages like Java or C++.

https://en.wikipedia.org/wiki/Fragile_base_class#:~:text=The fragile base class problem,the derived classes to malfunction.

C++ allows for multiple inheritance and as a result can introduce some funky errors in code. As an example, say you have a class C that inherits from classes PA and PB and they in turn inherit a common class G. G has a variable x that a method in class C changes.

The question is how should one access x from methods in C? Via PA to G or via PB to G. It turns out that in C++ there are two instances of the G class and hence two x variables. The solution was to always design with getter and setter functions and not allow direct access to the variables of another class.

These subtleties can really mess with a beginning student and must be approached carefully as they get comfortable with whatever OOP language they choose.

in the past, I’ve championed the Processing approach to learning to program because of it immediate feedback and relatively simple editor and runtime. It’s based on Java but introduces students to the setup and draw model allowing them to get immediate feedback when something it run. Java is a good language on several fronts, single inheritance, platform agnostic, rich library of features, good vendor support and great IDE tools.

The student has a clear path from Processing to more serious projects and an easier transition from hobbyist level to professional developer while maintaining what they’ve learned.

Processing has a similar path for Python folks when the Jython mode is selected although it’s not as easy to transition to developer level since Jython is at v2.7 and most modern Python development is done with Python 3.

Another popular Java student IDE is BlueJ. I’ve played with it but feel that Processing has more to offer.

Anyway, this is an endless flame war topic with no clear winner only many options for folks to choose from and lots of people with varying opinions and positions on what works best.
 
  • Informative
Likes jack action
  • #38
jedishrfu said:
One thing that’s not been brought up here is the fragile base class issue of OOP languages like Java or C++.
...
These subtleties can really mess with a beginning student
I don't think multiple inheritance is something a beginning student should be learning anyway.

jedishrfu said:
The student has a clear path from Processing to more serious projects and an easier transition from hobbyist level to professional developer while maintaining what they’ve learned.
I accept what you say, however I believe it is better to be able to move to more serious projects without having to change language.

jedishrfu said:
Processing has a similar path for Python folks when the Jython mode is selected although it’s not as easy to transition to developer level since Jython is at v2.7 and most modern Python development is done with Python 3.
No, Python 2.7 reached end of life three years ago and should not be used by anyone for anything, let alone be taught to beginners.

jedishrfu said:
Anyway, this is an endless flame war topic with no clear winner only many options for folks to choose from and lots of people with varying opinions and positions on what works best.
I have two thoughts on this:
  1. Although there are many opinions stated among posters here and elsewhere, I believe that there is now a consensus among the academic community, particuarly in STEM, that Python is the best first language (some indicative evidence below). I think PF would benefit from a sticky post joining this consensus.
  2. Alternatively, there does at least appear to be a consensus on here for "don't learn C++ just because someone has told you it is fast", and I think a post along those lines that we could link in answers would be useful.
@Greg Bernhardt what do you think?

University of Cambridge Department of Computer Science and Technology said:
FAQ: Can you recommend any books or activities to do that would help my application and/or studies?
A: If you choose to learn a new language, it may be a good idea to learn one that is not explicitly taught in the Tripos. Doing so obviously helps to avoid repetition, but also gives you a wider perspective on languages that can be useful later in the degree and in employment. A popular choice is Python, for which there are many tutorials available.
https://www.cst.cam.ac.uk/admissions/undergraduate/faqs

Since 2016 Python has been the first language taught to University of Cambride Engineering students
https://github.com/CambridgeEngineering/PartIA-Computing-Michaelmas

MIT Open Courseware Introductory Programming said:
This page will help you begin to learn programming and computer science, with some suggested introductory courses on OCW.
These courses introduce principles of computer science and begin to develop programming skills, specifically in the Python language. Learn more about these courses’ learning goals, history and student experience in this MIT news article.
Introduction to Computer Science and Programming in Python
Introduction to Computational Thinking and Data Science
Programming for the Puzzled
https://ocw.mit.edu/course-lists/general-introductions-to-programming/
 
  • #39
pbuk said:
Although there are many opinions stated among posters here and elsewhere, I believe that there is now a consensus among the academic community, particuarly in STEM, that Python is the best first language (some indicative evidence below). I think PF would benefit from a sticky post joining this consensus.
Among the academic community, particularly in STEM, it is prototyping that is mostly needed, not serious programming. For that purpose Python is a good choice. But the academic community is an extremely small sample of all programmers.
To the general question: "what programming language should I learn", I'd say the consensus in the industry is that it should at least be an object-oriented language with static typing.

Even people using Python would do well to learn a statically typed language with separation of concerns first. That would greatly improve their programming style.
 
  • Like
Likes Wrichik Basu
  • #40
Rene Dekker said:
Among the academic community, particularly in STEM, it is prototyping that is mostly needed, not serious programming.
I think you have misunderstood my point, which is that if institutions such as the University of Cambridge and MIT are recommending and using Python as the first language to learn for computing and STEM students then why would it not be good for PF to do that too?

Rene Dekker said:
Even people using Python would do well to learn a statically typed language with separation of concerns first.
I don't understand your reference to separation of concerns as a language feature, surely it's a (highly desireable) programming style that can (and should) be used in any language?
 
  • #41
pbuk said:
Although there are many opinions stated among posters here and elsewhere, I believe that there is now a consensus among the academic community, particuarly in STEM, that Python is the best first language (some indicative evidence below).
I beg to differ on this. Python is a good language for scientific computing, no questions regarding that. But that's primarily due to the availability of libraries like numpy, scipy and matplotlib - the foundations. If these libraries were written for Java, the scenario would have been different.

An absolute beginner needs to learn programming first, before going into scientific or numerical programming. Without the notion of data types, for instance, I am not convinced how programming logic can be created. A solid base in programming would help you master any programming language in the future.

I am not saying stay with Java. Switch to whatever language you want, based on your needs. But start with Java.
 
  • #42
Wrichik Basu said:
I beg to differ on this.
Then you are differing with the recommendations I quoted from the University of Cambridge and MIT which are not specific for scientists.

Wrichik Basu said:
An absolute beginner needs to learn programming first, before going into scientific or numerical programming. Without the notion of data types, for instance, I am not convinced how programming logic can be created. A solid base in programming would help you master any programming language in the future.
I agree completely. Data types are encountered early in learning Python with
Python:
# Adding numbers.
print(2 + 2) # 4

# Adding strings (concatenation).
print("2" + "2") # 22

# You can't mix types.
print(2 + "2") # TypeError: unsupported operand type(s) for +: 'int' and 'str'
 
  • #43
On Python:

There are research groups out there beimg strangled (get it?) by too much Python. They depend on thousands of lines of unmaintainable Python code written by a parade of students, and never really designed. "Prototypes" are sent straight into production.

This was done with American automobiles in the 1980s and it worked about as well. I suppose it worked out very well..if you are Toyota.

On C++:

Just because you can doesn't mean you should.

We have a discussion upstream about the "diamond of death" inheritance pattern. As a friend said "this should onl;y be used in compiler test suites, and not any actual running code." I dislike it too, not because of the probelms with it so much as it is almost never what you want.

There is a tendency of beginning C++ programs to overuse inheritance. This is aggravated by textbooks using geometric shapes to showcase it ("look, it inherits the perimeter clas") which is a bad choice - it's contrived, saves little coding, and turns the classes into monstrsities of exception handling.

The design philosophy is good - if you write code to do one thing, you write it one time and put it in one place. If you are using a feature of the language in some other way, there will be harder times ahead.
 
  • Like
Likes Wrichik Basu, jack action and jedishrfu
  • #44
Vanadium 50 said:
There are research groups out there beimg strangled (get it?) by too much Python. They depend on thousands of lines of unmaintainable Python code written by a parade of students, and never really designed. "Prototypes" are sent straight into production.
Yes, you can write bad code in any language. In the 1990s the same groups struggled with FORTRAN77 legacy code, in the 2000s it was Fortran 90, the 2010s C++ and Java. Perhaps if we teach people how to write good Python code from the get-go this will be better in future.

Vanadium 50 said:
We have a discussion upstream about the "diamond of death" inheritance pattern. As a friend said "this should onl;y be used in compiler test suites, and not any actual running code." I dislike it too, not because of the probelms with it so much as it is almost never what you want.
Absolutely.

Vanadium 50 said:
There is a tendency of beginning C++ programs to overuse inheritance. This is aggravated by textbooks using geometric shapes to showcase it ("look, it inherits the perimeter clas") which is a bad choice - it's contrived, saves little coding, and turns the classes into monstrsities of exception handling.
I don't know what idiot it was that confused the perfectly sensible "Shape" example of polymormorphism and the equally sensible "calculatePerimeter" example of function overloading to come up with a Perimiter class. I hope they were sacked, but somehow their legacy lingers on. Personally I prefer the "Animal" example.
 
  • #45
pbuk said:
you can write bad code in any language
Go too far down that path and you will reach the conclusion "nothing wring with just writing that code in C++".

If the story is "There's a lot of Python out there. so it;s a good thing to learn" it's hard to argue with. If the story is "Python encourages good programming habits" I think you can find a lot of counter examples.

But I think this dances around the real issue - people want to be programmers without learning any programming (and worse, they think they are good at it). Not too long ago, we had a thread where someone wanted to learn a particular database query language - but wasn't willing to put in more than two days on it.

To steal a phrase, if you want to build a doghouse, you can run down to Home Depot, pick up some wood and nails and go. If you want to build a house, you probably at least want blueprints. If you want to build a skyscraper, you want engineering. CS gets in trouble when people treat skyscrapers as great big doghouses.
 
  • Like
Likes Klystron, Wrichik Basu and jack action
  • #46
pbuk said:
I don't think multiple inheritance is something a beginning student should be learning anyway.I accept what you say, however I believe it is better to be able to move to more serious projects without having to change language.No, Python 2.7 reached end of life three years ago and should not be used by anyone for anything, let alone be taught to beginners.I have two thoughts on this:
  1. Although there are many opinions stated among posters here and elsewhere, I believe that there is now a consensus among the academic community, particuarly in STEM, that Python is the best first language (some indicative evidence below). I think PF would benefit from a sticky post joining this consensus.
  2. Alternatively, there does at least appear to be a consensus on here for "don't learn C++ just because someone has told you it is fast", and I think a post along those lines that we could link in answers would be useful.
@Greg Bernhardt what do you think?

Since 2016 Python has been the first language taught to University of Cambride Engineering students
https://github.com/CambridgeEngineering/PartIA-Computing-Michaelmas
Would you like to take a try at writing this post?
 
  • #47
Python's indentation is a bit hard to realize. In C++, I can use codeblocks to format on save. And it auto formats code for me. I'm pretty sure there's not one in python because that's the whole thing it is built in.
 
  • Like
Likes Wrichik Basu
  • #50
jedishrfu said:
One thing that’s not been brought up here is the fragile base class issue of OOP languages like Java or C++.

https://en.wikipedia.org/wiki/Fragile_base_class#:~:text=The fragile base class problem,the derived classes to malfunction.
Very interesting: I have never run into this problem.
I converted the example provided in that wiki article to C++ and included it here:
[CODE lang="cpp" title="Wiki example to C++"]
class base {
public:
// int incA() { return counter++; }
int incA() { return incB(); }
virtual int incB() { return counter++; }
private:
static int counter;
};
int base::counter = 0;

class derived: public base {
public:
int incB() { return incA(); }
};
[/CODE]
First off, I think this is an excellent example of how mentorship is really important to a beginning programmer. Without mentorship, a novice will fiddle with this code until it works and leave mystery and frustration in its wake.

Although the semantics of the language are very important, in my mind, this "fragility" is more profound than just semantics. In contrast to addressing semantics, I think it is important to track this issue all the way through the design process - because that is where the problem lies.

When coded exactly as it is written above, it will drop into infinite recursion and fail.
The way to correct this would depend on the actual purpose of base::incA(). Of course, in this case it is only to provide an example. But in "real life", you would need to determine if it was correct for it to call this-> incB() or base::incB().
If base::incB() is needed, then "int incA() { return incB(); }" needs to be corrected to "int incA() { return base::incB(); }". And the bug is fixed.

On the other hand, it could be that base::incB() really should be relying on the derived version of incA().
If that is the case, the problem is with derived::incA(). That function should not rely on base::incB() and the fact that it was coded that way indicates that the coder did not understand how the classes 'base' and 'derived' are being used to address the "real life" problem. I such a case, I would expect that the derived::incA() has been completely mis-coded and that fixing it will involve more than just replacing one or two lines of code. In other words, the problem isn't just inadvertent recursion, it is a misunderstanding of what incA() was supposed to do.
jedishrfu said:
C++ allows for multiple inheritance and as a result can introduce some funky errors in code. As an example, say you have a class C that inherits from classes PA and PB and they in turn inherit a common class G. G has a variable x that a method in class C changes.

The question is how should one access x from methods in C? Via PA to G or via PB to G. It turns out that in C++ there are two instances of the G class and hence two x variables. The solution was to always design with getter and setter functions and not allow direct access to the variables of another class.
So here is my rendition of the example you describe in C++. If this is not what you have in mind, let me know and I will take another shot at it.
[CODE lang="cpp" title="Wiki example to C++"]
class G { public: int x; };
class PA: public G {};
class PB: public G {};
class C: public PA, PB
{
void SetX(int n) { x=n; }
int GetX() { return x; }
};
[/CODE]

That code will not compile. The C++ compiler complains that the x's in SetX() and GetX are ambiguous.
To correct the code, you need to replace each 'x' with either 'PA::x' or 'PB::x'.
 
Back
Top