3
$\begingroup$

These days everybody is learning Python. I remember when we first started programming we were taught C Language. As a teacher which language should be taught first these days, C Language or Python?

$\endgroup$
5
  • 6
    $\begingroup$ This is a strangely constrained choice. None of the above. Why only these two? $\endgroup$
    – Ben I.
    Commented Apr 23, 2021 at 20:38
  • 2
    $\begingroup$ Maybe, also more context would be nice: What age? Are the students already into computers or do you want to excite them for the topic or do you want to give them something they could practically use later on the job? I also agree with Ben: why only these two? I would at least add in Javascript as choice to not confuse them with unnecessary things like classes. $\endgroup$
    – DarkTrick
    Commented Apr 24, 2021 at 11:14
  • 2
    $\begingroup$ I put only these two languages for choice as in some of the Asian countries like India etc. C is the first language that is taught to students. They learn the syntax, core concepts, and even the advanced concepts like pointers. In ICSC syllabus format they even use Java for grade 9, 10. and advanced Java with data structures like binary trees, etc. in grade 11, 12. But, now Python is being introduced to students... $\endgroup$ Commented Apr 24, 2021 at 12:35
  • 2
    $\begingroup$ I would only teach C before assembly -- to teach pointers and memory allocation, which are obscured in other languages, but not for a first language. $\endgroup$
    – Erik Eidt
    Commented Apr 25, 2021 at 23:15
  • $\begingroup$ Possible duplicate: cseducators.stackexchange.com/questions/212/… $\endgroup$
    – BrDaHa
    Commented May 3, 2021 at 19:07

6 Answers 6

11
$\begingroup$

The question is actually more complex than it might appear, and really the answer can depend on the context. For example, at what age are the students when they are first taught to program? Is this in Primary School, High School or part of an undergraduate programme? The answer might be different in each case.

It also depends on the purpose of teaching the initial programming language (IPL). Is the purpose to lead towards a practical skill (vocational programming), or is it to enable the teaching of some knowledge of algorithms (pedagogic programming), is it to enable the functioning of some devices (engineering programming) or is it to prepare students for further study? Each of these questions could lead to a different language as an IPL.

For a very early age start of programming one does not have to worry about employment or future curricula so something engaging is important, so tools such as MIT Scratch have a role. For later childhood Python fills a nice niche, particularly as it can run on a wide variety of inexpensive platforms (such as Arduino's, Raspberry Pi and so forth) which provides accessibility and make it within the reach of the classroom and individual students.

Conversely, if one is looking at an undergraduate IPL then it may depend on which degree programme is being considered. Is it a degree in Computer Science, Engineering, Biology, Chemistry or Physics? One would then need to take into account what graduate employers might be looking for and tailor to that market.

Python might have value in some of these programs but the students would also have to learn other languages at some point. For example, Computer Scientists would need a wider experience that would embrace C#, C++ (among others). Electronic Engineers might need C, but Computer Scientists less so. Biologists might need R, Chemists and Physicists might still need Fortran!

However, I would say that I might never recommend C as an IPL, and would start at C++ even for the most hardened Electrical Engineer. I only show Computer Science students C in specific contexts (like working with flex and bison)!

One thing I say to my students in the course where I look at Languages is that there is no one best language. The choice of language for any particular situation is so very context dependent on resources available, skills available, the purpose of the programming and the end goal of the task, and for an IPL that advice still holds true.

$\endgroup$
3
  • 4
    $\begingroup$ Hear, hear! I second "C only in specific contexts" -- languages are the second choice you make, with learning goals as the first choice -- and there are very few learning goals for which C is the best choice. We use C in two different contexts within our 4-year program, and both are for well-considered reasons and fairly limited in scope. $\endgroup$
    – Ben I.
    Commented Apr 23, 2021 at 20:33
  • $\begingroup$ I thought it was funny that you used the abbreviation IPL. Of course you know what that meant for mainframe computers - deliberately loading the OS in a separate step between powering it on and then running user programs. So, teaching the initial programming language is exactly the same thing for students: you load the OS of how to program in to their heads. As we know, if you don't know where you are going, any road will get you there. People have learned to program using all sorts of languages and systems. We are very good at figuring things out. $\endgroup$
    – Scott Rowe
    Commented May 2, 2021 at 1:09
  • $\begingroup$ Never C or C++ as a first language. C++ only after you have mastered Object Orientation. And only for very specialist uses. I am not even sure that ever is the best for kernel, device-driver, fast-code, definitely not compilers. C may be good when studying HOW thinks work. Or defining the output of a compiler. $\endgroup$ Commented May 28, 2021 at 15:31
6
$\begingroup$

I started teaching Python at NCSSM in 2004. Here are some reasons I chose it.

  1. It is direct and simple, and there is not a whole ton of boilerplate to deal with at the beginning. Hello, World looks like this

    print("Hello, World")

We all know what it looks like in Java (enclosing class needed) and C.

  1. Delimitation occurs via whitespace. Students who begin with Python tend to have excellent formatting habits when they learn other languages, because Python requires them. There is a direct visual connection between the flow of a program and its appearance.

  2. It's a professional tool. Students don't "outgrow" Python. It has a rich standard library and numerous third-party libraries that make it an awesome tool.

  3. It supports OO, functional, and imperative programming paradigms

  4. Memory management on the heap is largely abstracted away.

  5. The built-in types provide a significant creative palette. We teach our students to "use wheels, not re-invent them." An exception to this is when we are "dissecting" something to gain an understanding of how it works.

  6. It runs on everything and web interfaces for it are freely available.

Long experience shows that Python is an excellent language for beginners.

C is not great for beginners. However, it is very important. In many ways it is the "Latin" of computer languages. Every programmer should know it, because it lurks beneath the surface in so many places. We teach it to students who are already proficient programmers.

$\endgroup$
1
  • $\begingroup$ +1 good answer.. $\endgroup$ Commented May 18, 2021 at 13:03
5
$\begingroup$

Python is a fine language for learning algorithmic thinking and problem solving (see e.g. Downey's "Think Python" (Green Tea Press, 2nd edition 2016)). Python has an enormous ecosystem, including all the range of packages for simple tasks up to heavyweight systems like SciPy for all sorts of scientific computing, NumPy for numerical computation (included in the previous one) and SageMath for wide range of mathematical tools. It is also extensively used to program front-ends for administrative tools on many Linux distributions. Very far from a toy language, it usually ranks in the first places of language popularity.

C is a simple, low(ish) level language, very useful for tasks that require intimate access to the machine, like operating systems and all sort of system programs. There are good compilers available, that generate very efficient code. It's low-level nature with loopholes to allow fondling hardware at your heart's content, (somewhat) strict type system and lack of amenities like automatic garbage collection makes it harder to use (and a nightmare for newbies). Almost all software that you use daily is written in C.

Both have their place, which one to select depends on the time available (pick Python if there is time for learning other languages later on as needed; pick C if time is at a premium and that will be the later language of choice, but be prepared to spend a lot of time getting e.g. pointers and arrays across).

$\endgroup$
2
  • 1
    $\begingroup$ thanks... I like your answer $\endgroup$ Commented May 2, 2021 at 23:45
  • 2
    $\begingroup$ "Almost all software that you use daily is written in C" -- this doesn't seem right. Most of the software we use on a daily basis has some C components, but it's often a tiny minority of the actual code. (That's not to understate the importance of the code that tends to get written in C!) Windows, for instance, has the kernel in C and... that's it. Only one major browser uses C at all, and that only within the JavaScript engine. While Android is built atop Linux, virtually none of what we actually think of as Android is built in C. C is often an important minority. $\endgroup$
    – Ben I.
    Commented May 3, 2021 at 12:26
2
$\begingroup$

I can not answer directly because I know nothing about Python, but I first started to use C nearly 4 decades ago, and have used it for some really complex stuff. I love C# (I use it in the context of ASP.Net) and think it is very well designed and implemented. So, I would be biased no matter what, as you know, because you never forget your first language, which in my case was somewhere in the murky past of Basic, PDP-11 shell scripting, APL and Fortran, with punched cards and without...

Anyway: I would suggest that the concept of Notional Machine should be the absolutely most important consideration when first teaching anything about programming. Without a notional machine informing their understanding, students will know basically nothing about computing, and with a good foundation in one, they will know everything they need to know to learn new languages, systems, frameworks, etc, forever.

So, choose a language that actually teaches computing in a way that is generative, extensible, with sound metaphors and which has a small grammar that is not too powerful. In other words, something like C without too much preprocessor tricks or frameworks thrown in. Frameworks are the sauce, teach then how to cook first (colorful metaphor).

The problem is that there is such a forest of layers and tools now that actually seeing the machine in a way that contributes to notion-formation is very hard now. I would rather that students learn how to write simple command-line programs than know how to make a web site, because a lot of web site work is not really programming in any sense, it is just setting a lot of switches. And sadly, that misses the whole point of why we invented computers in the first place.

Without the idea of program, they are technicians, not creators. So choose wisely.

$\endgroup$
3
  • $\begingroup$ And you should teach quality while you are at it. $\endgroup$
    – Scott Rowe
    Commented May 1, 2021 at 20:56
  • 1
    $\begingroup$ When people assert that 'state' is the primary obstacle to understanding computers, this just completely dumbfounds me. Well, what more IS there to a computer than state? Really? What is a computer without state? A fancy set of lightswitches. People, please... get a clue. $\endgroup$
    – Scott Rowe
    Commented May 2, 2021 at 1:05
  • 1
    $\begingroup$ +1 I like this answer a lot, thanks for writing it. $\endgroup$ Commented May 2, 2021 at 2:11
1
$\begingroup$

At this moment, definitely Python. Because it's very easy to learn, understand and implement. Also very big and huge community around the world in terms of any help and support needed at any point of time, Large number of packages available based on the need, which simplifies and make programmers life easy, specially beginners. Also there is no need of programming concepts to be known/aware, while start learning Python.

$\endgroup$
1
$\begingroup$

In Python, if a program which is fed certain inputs produces certain outputs, then in the absence of deliberate randomness, those outputs will determined by the program and its inputs. While it's possible that a program might be erroneous and yet produce correct output for some inputs (e.g. if a program is supposed to accept a number and output its square, but instead it simply multiplies the number by 3, such a program would produce correct results when fed 0 or 3 as input), the fact that a program is observed to ever produces correct results for a particular input would generally imply that it would always produce correct results when fed that same input.

In C, by contrast, there are a wide range of constructs over which the Standard waives jurisdiction, which will almost always be processed in sensible fashion, but might occasionally have arbitrary disruptive side effects. Suppose a program would sometimes call a function like:

unsigned mul(unsigned short x, unsigned short y) { return x*y; }

for values of x in the range INT_MAX/y+1 to UINT_MAX/y. Should the function be viewed as "perfectly normal when targeting any machine designed in the last few decades", "correct but non-portable", or "erroneous"? Should it be expected to to be free of side effects in any build that isn't expressly configured to trap overflows, or should it be recognized as potentially affecting the behavior of calling code in weird and bizarre ways?

Such issues don't exist in Python. Having as a first language one where constructs are unambiguously correct or erroneous seems better than having one where an implementation might process a construct in an expected manner 99.99% of the time, but by design process it nonsensically under rare and unpredictable circumstances.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.