# Learning programming languages

Dear PF Forum,
Hi Guys
Do I need to learn C before C ++?
That makes me think, "How, straight with C++, do we teach programming language to someone who never knows progamming language?"

phinds
Gold Member
By "straight with C++" do you mean teaching someone who knows nothing about programming the OOP aspects of C++ without their knowing any of the sequential programming basics? If that's what you mean, I think it could only be done at a conceptual level. That is, you could give them a fair amount of solid information about the principles of OPP constructs but it would be a terrible approach to have them try to do useful programming from that point without their first going back and learning the basics of sequential programming.

By "straight with C++" do you mean teaching someone who knows nothing about programming the OOP aspects of C++ without their knowing any of the sequential programming basics? If that's what you mean, I think it could only be done at a conceptual level. That is, you could give them a fair amount of solid information about the principles of OPP constructs but it would be a terrible approach to have them try to do useful programming from that point without their first going back and learning the basics of sequential programming.
I mean like your quote before Phinds.
Teaching the "c" first than later (much later) the "++".
I really love BASICA
No procedures, just line numbers.
No variable definition.
It's the easiest language to teach someone about programming language.
Later when they know how to program, we just skip GOSUB, RETURN, DEFINT, DEFDBL, DEF SEG, PEEK, POKE, and go straight to Pascal.
And introduce them with just:
Code:
program MyFirstProgram;
{ all variables here }
{ all goto Labels here }

begin
{ all the instructions here }
end.
I call this BASICing Pascal.

But on secound thought, I think it's wrong to introduce GOTO for someone who wants programming language for the first time.

jtbell
Mentor
"How, straight with C++, do we teach programming language to someone who never knows progamming language?"

When I taught an introductory programming course using C++, I used the following sequence, more or less:
1. The basic process of writing, compiling and running programs (i.e. how to use programming tools), using very simple "Hello, world!" type programs that just do text output.
2. Variables: int and double for numbers, and strings for text data. (Not char arrays and pointers; I used the 'string' data type.).
3. Programs with both input and output.
4. If-statements and loops.
5. How to use functions that have already been written for you, e.g. library functions from the standard library.
6. How to use member functions of objects that have already been written, e.g. strings and other objects from the standard library: myname.length() gives you the length of myname, etc.
7. Grouping data together into vectors (I prefer these to plain old arrays) and structs.
8. How to write your own functions, and design programs effectively using functions to organize tasks and sub-tasks.
9. How to write your own classes (objects), and their member functions, and design programs to use them to organize your data and the actions that you do with them.
I've probably left something out; it's been ten years since I last taught that course.

Stephanus
When I taught an introductory programming course using C++, I used the following sequence, more or less:
1. The basic process of writing, compiling and running programs (i.e. how to use programming tools), using very simple "Hello, world!" type programs that just do text output.
2. Variables: int and double for numbers, and strings for text data. (Not char arrays and pointers; I used the 'string' data type.).
3. Programs with both input and output.
4. If-statements and loops.
5. How to use functions that have already been written for you, e.g. library functions from the standard library.
6. How to use member functions of objects that have already been written, e.g. strings and other objects from the standard library: myname.length() gives you the length of myname, etc.
7. Grouping data together into vectors (I prefer these to plain old arrays) and structs.
8. How to write your own functions, and design programs effectively using functions to organize tasks and sub-tasks.
9. How to write your own classes (objects), and their member functions, and design programs to use them to organize your data and the actions that you do with them.
I've probably left something out; it's been ten years since I last taught that course.
Good steps.
But I didn't see pointer?
I am lucky, I ever studied programming in DOS.
At least I can tell that in pascal: A = B + C; that would be
mov AX,
mov [A], AX
And all those segment : offset

jtbell
Mentor
But I didn't see pointer?

I didn't do pointers until near the end of the course. Using the standard string data type means you don't need char*. Using vectors instead of arrays eliminates another place where pointers come up early in C. When passing stuff to functions I used references instead of pointers. The only thing left where pointers made sense was dynamic memory allocation using 'new' and 'delete'.

In fact, I remember having trouble coming up with a situation involving dynamic memory allocation that I could use to motivate introducing pointers. "OK, here's what I'd like to do, but none of the tools we've learned so far can accomplish it. So here's something new: pointers." I don't remember what I used. (Hey, it was ten years ago!) Probably something involving linked lists.

The guy who taught the upper-level computer science courses told me not to worry about it if I didn't do much with pointers. The students would study them in the computer architecture course anyway. That's where they did stuff like assembly language, addressing modes, etc.

Stephanus
I didn't do pointers until near the end of the course. Using the standard string data type means you don't need char*. Using vectors instead of arrays eliminates another place where pointers come up early in C. When passing stuff to functions I used references instead of pointers. The only thing left where pointers made sense was dynamic memory allocation using 'new' and 'delete'.

In fact, I remember having trouble coming up with a situation involving dynamic memory allocation that I could use to motivate introducing pointers. "OK, here's what I'd like to do, but none of the tools we've learned so far can accomplish it. So here's something new: pointers." I don't remember what I used. (Hey, it was ten years ago!) Probably something involving linked lists.

The guy who taught the upper-level computer science courses told me not to worry about it if I didn't do much with pointers. The students would study them in the computer architecture course anyway. That's where they did stuff like assembly language, addressing modes, etc.
"Nothing can accomplish it" A very good phrase for pointer introduction. I remember, 20 years ago I used to teach programming language when I was in college for some cash. Just fire the pointer away.

Mark44
Mentor
I mean like your quote before Phinds.
Teaching the "c" first than later (much later) the "++".
I really love BASICA
No procedures, just line numbers.
As I recall from many years ago, BASICA (and GWBASIC and several other variants of BASIC) had subroutines (called with GOSUB) and functions.
Stephanus said:
No variable definition.
It's the easiest language to teach someone about programming language.
Later when they know how to program, we just skip GOSUB, RETURN, DEFINT, DEFDBL, DEF SEG, PEEK, POKE, and go straight to Pascal.
And introduce them with just:
Code:
program MyFirstProgram;
{ all variables here }
{ all goto Labels here }

begin
{ all the instructions here }
end.
I call this BASICing Pascal.

Mark44
Mentor
Good steps.
But I didn't see pointer?
I am lucky, I ever studied programming in DOS.
At least I can tell that in pascal: A = B + C;
Nope, that isn't Pascal. For assignment, you use := .
Stephanus said:
that would be
mov AX,
mov [A], AX
And all those segment : offset
Your first MOV instruction is missing something.

Nope, that isn't Pascal. For assignment, you use := .

Your first MOV instruction is missing something.
Sorry, you have sharp eye, Mark!
I typed to fast I think. I have been using pascal since 1990.
Code:
var
A,B,C: Word;
begin
A:=B+C;
{ assembly equivalence
mov AX,[B]
mov [A],AX
}
end.
Should use Word or Integer in Turbo Pascal works fine. In Delphi, should be Word.
A little try (just try that this very time. 'Integer' doesn't work in Delphi in asm mode }
Code:
var
A: Integer;
B: Word;

begin
B:=A; //works
asm
mov AX,A // syntax error
end;
end;

But on secound thought, I think it's wrong to introduce GOTO for someone who wants programming language for the first time.

I couldn't agree more. I started with BASIC on a C64 and produced nothing but spaghetti code just because it was possible. As BASIC was too slow to do something useful I then switched to assembler. That made it even worse. Learning programming this way was a really bad idea.

Stephanus
I couldn't agree more. I started with BASIC on a C64 and produced nothing but spaghetti code just because it was possible. As BASIC was too slow to do something useful I then switched to assembler. That made it even worse. Learning programming this way was a really bad idea.
What bad idea? Using GOTO or go straight to assembly after BASIC?
Judging your first programming language is BASIC, I think you learned it at the 70's. If you study programming language in the 50's you'd be lucky just to have the punched card FORTRAN

What bad idea? Using GOTO or go straight to assembly after BASIC?

Starting with programming languages that doesn't force me to structured programming.

Starting with programming languages that doesn't force me to structured programming.
But I find BASIC is very useful to teach someone the first programming language.
After the pupil is experienced enough. Writing a pascal triangle or fibonacci sequence, he/she should immediately be taught Pascal, then after that, is just choices.

But I find BASIC is very useful to teach someone the first programming language.

That's what it is purposed for. And with a BASIC dialect that does not include GOTO it is even useful to teach good programming from the beginning.

That's what it is purposed for. And with a BASIC dialect that does not include GOTO it is even useful to teach good programming from the beginning.
Couldn't agree more. NO GOTO, GOSUB. At least not GOSUB. Switch to Pascal before GOSUB.

Mark44
Mentor
Couldn't agree more. NO GOTO, GOSUB. At least not GOSUB. Switch to Pascal before GOSUB.
Why Pascal? I might be wrong, but as far as I know it's pretty much a dead language. After doing a little searching, I find that it still exists, though, as Delphi, which Borland sold off in 2008 to a company named Embarcadero.

I don't know of many schools that teach Pascal/Delphi, and we don't get a lot of questions about it here, so it would seem that not a lot of people are writing code with Pascal/Delphi.

Mark44
Mentor
That's what it is purposed for. And with a BASIC dialect that does not include GOTO it is even useful to teach good programming from the beginning.
Although the use of goto often leads to unreadable "spaghetti" code, and was excoriated in a paper by Edsger Dijkstra in 1968, its use is recommended in certain instances, such as for "end-of-function error handlers and for multi-level breaks from loops." -- Per Dennis Ritchie and Brian Kernighan from wiki article in link below.

https://en.wikipedia.org/wiki/Goto
Other programmers, such as Linux Kernel designer and coder Linus Torvalds or software engineer and book author Steve McConnell, also object to Dijkstra's point of view, stating that GOTOs can be a useful language feature, improving program speed, size and code clearness, but only when used in a sensible way by a comparably sensible programmer. According to computer science professor John Regehr, in 2013, there were about 100,000 instances of goto in the Linux kernel code.

Some quotes from Steve McConnell, in "Code Complete", pp. 348-349.
A well-placed goto can eliminate the need for duplicate code.
...
The goto is useful in a routine that allocates resources, performs operations on those resources, and then deallocates the resources.
...
In some cases, the goto can result in faster and smaller code.

Stephanus
Why Pascal? I might be wrong, but as far as I know it's pretty much a dead language. After doing a little searching, I find that it still exists, though, as Delphi, which Borland sold off in 2008 to a company named Embarcadero.

Embarcadero still sells it for prices that nobody would pay just for fun. Thus there seem to be some professional users left. But I would also say that it is close to extinction.

Mark44
Mentor
Embarcadero still sells it for prices that nobody would pay just for fun. Thus there seem to be some professional users left. But I would also say that it is close to extinction.
Borland made a great marketing decision back when they released TurboPascal in 1983. As I recall, it sold for $49 (?), and they sold a ton of copies, and got a lot of people interested in programming. Back about '83 or so I had a version of UCSD Pascal that ran on Apple II computers. After I started learning C in '85, I was all done with Pascal. Why Pascal? I might be wrong, but as far as I know it's pretty much a dead language. After doing a little searching, I find that it still exists, though, as Delphi, which Borland sold off in 2008 to a company named Embarcadero. I don't know of many schools that teach Pascal/Delphi, and we don't get a lot of questions about it here, so it would seem that not a lot of people are writing code with Pascal/Delphi. Aside from Borland text editor which allow cursor to go up/down vertically , what I like about Pascal is its nested procedure. It's very convenient to access local variable globally. Code: procedure Level1; var A: Integer; procedure Level2; procedure Level3; begin A:=10; { don't have to put A in global scope } end; begin end; begin end; And it's array definition which has a unique characteristic. Pascal: var A: Integer[7..10]; Basic: dim A(10) C: int a[10]; Pascal can set the element of the array from 7 not from zero, not a good programming technique tough. Has to leave this concept, because 99% of Delphi objects starts from 0 TStrings.Strings[Index] starts from zero TList.Items[Index] starts from zero TMemo.Lines[Index], TDataSet.Fields[Index], and almost many more. But of course C++ has multiple inheritance which Pascal don't have. And operator overloading is the most impressive feature in C++. But nested procedure is the one that I need most in Pascal. Pascal OOP has a unique characteristic than C++. In C++ the inherited constructors) is called automatically. Is it good? Bad? I don't know. But in Pascal we can delay calling inherited constructor. Code: constructor Square.InitSquare; begin A:-10; B:=20; { some codes here } InitRectangle; { call the inherited constructor after some lines processed } end; But I know a kid, (not mine unfortunately ), 13 years old, start doing Phyton. Although the use of goto often leads to unreadable "spaghetti" code, and was excoriated in a paper by Edsger Dijkstra in 1968, its use is recommended in certain instances, such as for "end-of-function error handlers and for multi-level breaks from loops." -- Per Dennis Ritchie and Brian Kernighan from wiki article in link below. https://en.wikipedia.org/wiki/Goto Some quotes from Steve McConnell, in "Code Complete", pp. 348-349. GOTO is important for an experienced programmer. For a beginner it's a disaster. It's like watching violence in GodFather. Good movie for adult, bad movie for children. Borland made a great marketing decision back when they released TurboPascal in 1983. As I recall, it sold for$49 (?), and they sold a ton of copies, and got a lot of people interested in programming. Back about '83 or so I had a version of UCSD Pascal that ran on Apple II computers. After I started learning C in '85, I was all done with Pascal.
Sorry, Mark if I trouble you. It's just out of curiousity, why C is better than Pascal. I still doing C in Metatrader, I like C, but I think Pascal is better than C.
Perhaps if you could give me some enlightment...