# How do people start programming C or C++?

**URL:** <https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501>\
**Category:** Factual Questions\
**Created:** [November 29, 2002, 3:25pm UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501 "2002-11-29T15:25:27Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [December 2, 2002, 3:44pm UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/41 "2002-12-02T15:44:54Z")

</div>

> [@](#):
>
> \*Originally posted by Urban Ranger \*  
> \*\*Not quite. Check out the [Forth SIG site](http://www.forth.org/literature.html) for more info \*\*

After reading [A Brief Introduction to Forth](http://www.ece.cmu.edu/~koopman/forth/hopl.html), I don’t see any reason not to call Forth a stack-based language. Care to elaborate?

---

<div class="post-metadata">

**Author:** ![ObiWan](https://avatars.discourse-cdn.com/v4/letter/o/e47774/32.png) [@ObiWan](https://boards.straightdope.com/u/ObiWan)\
**Post date:** [December 2, 2002, 3:45pm UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/42 "2002-12-02T15:45:38Z")

</div>

> [@](#):
>
> \*Originally posted by Napier \*  
> I have an idea of what C# is, and also what Visual Basic is. But what does .NET mean? Is it the Window interface component, as opposed to the C language component, of C# and VB? Or what? Define .NET for me please.

From [WhatIs](http://searchwebservices.techtarget.com/sDefinition/0,,sid26_gci342248,00.html):

> [@](#):
>
> .NET is both a business strategy from Microsoft and its collection of programming support for what are known as Web services, the ability to use the Web rather than your own computer for various services. Microsoft’s goal is to provide individual and business users with a seamlessly interoperable and Web-enabled interface for applications and computing devices and to make computing activities increasingly Web browser-oriented. The .NET platform includes servers; building-block services, such as Web-based data storage; and device software. It also includes Passport, Microsoft’s fill-in-the-form-only-once identity verification service.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [December 2, 2002, 9:09pm UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/43 "2002-12-02T21:09:22Z")

</div>

> [@](#):
>
> \*Originally posted by Urban Ranger \*  
> \*\*neither is _Perl_, just to name a few common languages. \*\*

How much Perl have you seen in your life? Perl is a prime example of a C-like language: It has all the same control structures, syntax rules, and code grouping mechanisms.

There are many, many C-like languages. Here are a few I can name off the top of my head:  
[ul]  
[li]Ada[/li][li]Ruby[/li][li]Python[/li][li]Perl[/li][li]Java[/li][li]Pascal[/li][li]Almost any modern interpreted language.[/li][/ul]C has become a modern template, like FORTRAN before it (FORTRAN begat COBOL, Basic, CORC, CUPL, and a host of other really bad teaching languages). It’s guaranteed that any new language will have to incorporate some C-like features to be acceptable to the majority of programmers.

Ok, name me some non-C-like languages in modern use by more than a few people worldwide.

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [December 3, 2002, 10:44pm UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/44 "2002-12-03T22:44:51Z")

</div>

Damn, you folks are great. Lotsa splendid information here - thanks $1e6.

Several folks have recommended Borland C++ Builder. But the Borland website seems to say I couldn’t use it on my NT computer at work - anybody know otherwise?

Everybody that recommends K&R (2nd edition) does so most eloquently. Not to worry - I’m reading it! As Derleth says, “Helpfully, K&R lists an abbreviated version of the ANSI documentation…” and in fact I didn’t notice this until last night (it’s actually an appendix). Wow - this is perfect - rather than muddying the water with a teaching example without stating the point, this splendid section just says what the language does - it’s the perfect introduction - where has it been all my life??? I’m gonna Xerox it onto the wall! But Derleth, really - “Everybody but Microsoft is using UNIX” is kinda like saying “There are no tyrants in Iraq except Saddam Hussain”, isn’t it? Oh, well, no harm in hoping, I guess. Onward: I’ll also check into the Oualline book.

Sandwriter, thanks for suggesting Bloodshed Dev-C++ 4.0. I’ll check it out.

Ultrafilter, the program in Forth to compute 3\*4+2 and print the result would look like this:  
: demo.for.ultrafilter 3 4 \* 2 + . ;  
You said “After reading A Brief Introduction to Forth, I don’t see any reason not to call Forth a stack-based language.” I quite agree. Actually, two stacks, one for computation and one for returns from words (subroutines), are at the heart of Forth. And Forth is actually assembly language for some Forth processors that implement the two stacks in hardware. I don’t mean a virtual machine, either - I mean real melted sand.

Urban Ranger, you said “Basic, Fortran and Ada certainly do not look anything like C…”  
I found a neat collection of hello world programs at [Hello, World Page!](http://www2.latech.edu/~acm/HelloWorld.shtml), to wit:

ADA:  
with Text\_Io; use Text\_Io;  
procdure hello is  
begin  
put (“Hello world!”);  
end hello;

BASIC:  
10 print"Hello World!"  
20 goto 10

C:  
#include \<stdio.h\>  
main()  
{  
for(;😉  
{  
printf ("Hello World!  
");  
}  
}  
FORTRAN:  
PROGRAM HELLO  
DO 10, I=1,10  
PRINT \*,‘Hello World’  
10 CONTINUE  
STOP  
END

FORTH:  
: hello  
begin  
true  
while  
." Hello World "  
repeat  
;

Which ones do you think look the most and least C-like?

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [December 4, 2002, 12:41am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/45 "2002-12-04T00:41:35Z")

</div>

Well, I do know that C does _not_ have smilies, unless you’ve gone gonzo with an Emacs mode.

😃

I was wrong about Ada being C-like. It _is_ block-structured, which is what most C code ends up looking like, but the structure is more a part of the language than it is in C. It also has other resemblences to C, but not enough to make it C-like. It is actually Pascal-descended, which means it was written to be deliberately non-permissive in an attempt to fight bugs. C, on the other hand, is free-form in its syntax and permissive in its rules: Types can be overridden with casts, pointers can be bent, folded, spindled, and mutilated, and a programmer can rewrite portions of the language with judicious (or gonzo :D) use of the preprocessor.

I was wrong on Ada, but knowing C syntax has stood me in good stead as I’ve learned other languages.

A way to write the FORTRAN program so it has an infinite loop is:

```auto

     PROGRAM HELLO2
100 WRITE *, "HELLO, WORLD!"
     GO TO 100
     STOP
     END

```

Gotos are Considered Harmful. _Computed_ gotos are Considered Sadistic.

😃

---

<div class="post-metadata">

**Author:** ![ftg](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ftg/32/2801_2.png) [@ftg](https://boards.straightdope.com/u/ftg)\
**Post date:** [December 4, 2002, 2:28pm UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/46 "2002-12-04T14:28:09Z")

</div>

> [@](#):
>
> \*Originally posted by Derleth \*  
> There are many, many C-like languages. Here are a few I can name off the top of my head:  
> [ul]  
> [li]Ada[/li][li]Ruby[/li][li]Python[/li][li]Perl[/li][li]Java[/li][li]Pascal[/li][li]Almost any modern interpreted language.[/li][/ul]C has become a modern template, like FORTRAN before it (FORTRAN begat COBOL, Basic, CORC, CUPL, and a host of other really bad teaching languages). It’s guaranteed that any new language will have to incorporate some C-like features to be acceptable to the majority of programmers.
> 
> Ok, name me some non-C-like languages in modern use by more than a few people worldwide.

Wow, where do I begin.

First of all, Pascal was invented long before C. It, its descendent Modula, and Ada are all Algol derivatives. Algol influenced far more programming languages than C, which is also one of its descendents.

As for interpreted languages, apparently you are unaware of Lisp descendents such as Scheme that are [widely used](http://www.schemers.com/schools.html).

COBOL was not influenced to any sig. extent by Fortran.

Etc., etc.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [December 5, 2002, 1:47am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/47 "2002-12-05T01:47:38Z")

</div>

OK, I admitted I was wrong about Pascal and, by extension, Ada.

---

<div class="post-metadata">

**Author:** ![Urban\_Ranger](https://avatars.discourse-cdn.com/v4/letter/u/e9c0ed/32.png) [@Urban\_Ranger](https://boards.straightdope.com/u/Urban_Ranger)\
**Post date:** [December 5, 2002, 3:12am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/48 "2002-12-05T03:12:39Z")

</div>

> [@](#):
>
> \*Originally posted by Derleth \*  
> How much Perl have you seen in your life? Perl is a prime example of a C-like language: It has all the same control structures, syntax rules, and code grouping mechanisms.

If you put it that way, modern imperative languages all have very similar control structures, syntax rules, and code grouping mechanisms.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [December 5, 2002, 3:20am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/49 "2002-12-05T03:20:09Z")

</div>

**Urban Ranger** : Exactly my point, and all of those structures are similar to C’s. So learning C would help you learn those the way learning Latin gives you a foothold into Italian, French, and Spanish.

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [December 5, 2002, 5:01am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/50 "2002-12-05T05:01:18Z")

</div>

The real difference in imperative languages comes in to play once you start dealing with the object-oriented languages. There are a lot more issues there, and lots of other things you have to provide syntax for.

---

<div class="post-metadata">

**Author:** ![Ms2001](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ms2001/32/18463_2.png) [@Ms2001](https://boards.straightdope.com/u/Ms2001)\
**Post date:** [December 5, 2002, 5:11am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/51 "2002-12-05T05:11:03Z")

</div>

> [@](#):
>
> \*Originally posted by Libertarian \*  
> \*\*Custom components have been a part of VB since version 5 and ActiveX. \*\*

Well, they’ve been a part of VB longer than that–remember VBX controls? But you needed a C compiler to make those. I confess that I’m ignorant about recent versions of VB… can you make your own full-featured ActiveX controls with it?

> [@](#):
>
> _Originally posted by Napier_  
> **Aw, shoot - I just looked at Borland’s info on C++ Builder V6, and it says the system requirements include several versions of Windows but not NT. Does this mean I can’t use it on my NT desktop work computer?**

I’ve had no problems running Delphi on NT 4, and C++Builder on Windows 2000 and XP (NT 5.0 and 5.1). You shouldn’t have any trouble.

> [@](#):
>
> _Originally posted by Derleth_  
> **Exactly my point, and all of those structures are similar to C’s.**

That doesn’t mean the languages themselves are similar. Knowing how an if/else statement works will help you write decision-making code in nearly any language (perhaps not Scheme or Forth), but knowing C won’t necessarily help you learn Basic or Python.

I disagree that Python is a C-like language. One of the most fundamental differences between C (or Java, C#, [Snack](http://www.nyx.net/~gthompso/self_snack.txt)…) and other languages such as Basic (or Fortran, [ABC](http://www.nyx.net/~gthompso/self_abc.txt), [REXX](http://www.nyx.net/~gthompso/self_rexx.txt)…) is that C ignores whitespace and line breaks. On the other hand, [Python](http://www.nyx.net/~gthompso/self_pyth.txt) code uses indentation to group statements and line breaks to terminate them. Artistically arranged code like you see in the [Obfuscated C Contest](http://www.ioccc.org/) simply isn’t possible in those languages.

---

<div class="post-metadata">

**Author:** ![c\_carol](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@c\_carol](https://boards.straightdope.com/u/c_carol)\
**Post date:** [December 5, 2002, 5:12am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/52 "2002-12-05T05:12:43Z")

</div>

> [@](#):
>
> for(;😉 // smiley problem fixed  
> {  
> printf ("Hello World!  
> ");  
> }

Is it just me, or is that an odd use of “for”? What does that do, an infinite loop? (I should know this, but my C / C++ is very rusty.)

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [December 5, 2002, 5:19am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/53 "2002-12-05T05:19:42Z")

</div>

Yes, that does loop forever.

---

<div class="post-metadata">

**Author:** ![c\_carol](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@c\_carol](https://boards.straightdope.com/u/c_carol)\
**Post date:** [December 6, 2002, 2:25am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/54 "2002-12-06T02:25:39Z")

</div>

[hijack]

> [@](#):
>
> Artistically arranged code like you see in the Obfuscated C Contest simply isn’t possible in those languages

[Python FAQ on obfuscated code](http://www.python.org/doc/FAQ.html#4.15)  
[Here’s another obfuscated Python page](http://p-nand-q.com/obfuscated-python.htm)  
[/hijack]

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [December 6, 2002, 2:47am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/55 "2002-12-06T02:47:13Z")

</div>

Derleth,

You said “Gotos are Considered Harmful.” I always hear this. But the machine language implements all sorts of control structures with gotos, doesn’t it? Perhaps what should be considered harmful is how people can get lost in them, or something.

And I think C does have lots of smilies. That is, I am guessing that the definition of a smilie has something to do with three semicolons in a row. C often says “for parenthesis semicolon semicolon semicolon closedparanthesis”. If I type it for(;;;), which looks right in my “Your Reply” window, I think it gets displayed like a smilie. Maybe if I put spaces in there, for( ; ; ; ), it won’t. But I don’t get to find out till I post it. So, whether C uses smilies depends on your - excuse me, the SDMB’s - definition of a smilie.

---

<div class="post-metadata">

**Author:** ![Ms2001](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ms2001/32/18463_2.png) [@Ms2001](https://boards.straightdope.com/u/Ms2001)\
**Post date:** [December 6, 2002, 3:09am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/56 "2002-12-06T03:09:34Z")

</div>

> [@](#):
>
> \*Originally posted by c\_carol \*  
> \*\*[hijack]  
> [Python FAQ on obfuscated code](http://www.python.org/doc/FAQ.html#4.15)  
> [Here’s another obfuscated Python page](http://p-nand-q.com/obfuscated-python.htm)  
> [/hijack] \*\*

Sure, but look at these [IOCCC](http://www.ioccc.org) winners… 🙂  
[dhyang](http://www.ioccc.org/2000/dhyang.c)  
[thadgavin](http://www.ioccc.org/2000/thadgavin.c)  
[bas1](http://www.ioccc.org/1998/bas1.c)  
[dloweneil](http://www.ioccc.org/1998/dloweneil.c)  
[heathbar](http://www.ioccc.org/1995/heathbar.c)

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [December 6, 2002, 6:08am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/57 "2002-12-06T06:08:25Z")

</div>

> [@](#):
>
> \*Originally posted by Napier \*  
> **You said “Gotos are Considered Harmful.” I always hear this. But the machine language implements all sorts of control structures with gotos, doesn’t it? Perhaps what should be considered harmful is how people can get lost in them, or something.**

Yes.

The difference is, the compiler’s goto’s have been thoroughly tested, and probably proven correct. Yours, on the other hand, probably haven’t. goto is best left to the experts.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [December 6, 2002, 8:18am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/58 "2002-12-06T08:18:13Z")

</div>

“Gotos Considered Harmful” was my misremembering of the title of the paper that began the absolutely moronic Structured Programming Wars. It was actually called “Goto Statment Considered Harmful,” and was written by Edsger W. Dijkstra.

`Structured Programming’ is the idea that all code must conform to certain precepts to be correct and readable, which is all well and good until you consider how many ways there are to code something, and how ideas relevant in one context (writing large applications) are counterproductive or nonsensical in another (coding device drivers).

The main good to come out of the Structured Programming Wars was the idea that code _should_ be structured, that having jump statments (or gotos, or branch statements, etc.) everwhere is _not_ a good idea, but that any good idea can be taken too far.

[http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?considered+harmful](http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?considered+harmful)

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [December 6, 2002, 8:39am UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/59 "2002-12-06T08:39:24Z")

</div>

> [@](#):
>
> \*Originally posted by ultrafilter \*  
> \*\*The real difference in imperative languages comes in to play once you start dealing with the object-oriented languages. There are a lot more issues there, and lots of other things you have to provide syntax for. \*\*

But that’s my point: It’s all _syntax_, aka implementation details, not general concepts. Look at it this way: Learning Forth isn’t going to do you a lot of good if you go right on into Ruby. Why? You’ll have to relearn everything. You’ll have to switch from the stack-model to the procedural-model, and that involves a lot more thought than gleaning the syntax from a language overview and some example code. You could, however, go from Ruby to C with less trouble, because both are procedural langauges. The spelling changes, but the grammar remains the same.

**Napier** : Please don’t read so much into my jokes. :😁:

I don’t think there is ever a situation in C where you have _three_ semicolons in a row, but you sometimes have _two_, like this:

```auto

for (;;) {
   printf("This will print forever.
");
}

```

Why will that print forever? It’s all to do with the syntax of the for statement.[ul]  
[li]The first part of the for statment, the part before the first semicolon, initializes the index variable. IOW, it sets up the beginning of the loop. If you wanted to count from zero to 99 using i as an index variable, this would say `i = 0'.[/li][li]The second part, between the two semicolons, decides if the loop is done yet. It does this by seeing if the index variable satisfies the end condition. To carry out my example, this part would say `i \<= 99’, which means `if i is less than or equal to 99, we're not done yet'.[/li][li]The third and final part, after the second semicolon, advances the loop. It is a statement that does something to the index variable. A good statement for our purposes would be `i++’, which increments i.[/li][/ul]If the compiler notices one of those statments is missing, it doesn’t care. It just ignores it and compiles the loop anyway. So if all three parts are missing, the compiler creates an infinite loop. Things like these are called idioms, and like idioms in natural languages, they can trip up newbies just as much as they help seasoned veterans. (BTW, Perl has a huge stock of idioms. The language’s motto is TMTOWTDI (There’s More Than One Way To Do It), something that either repulses you or enamors you.)

If you want to create code without smilies, like I did, check the litte `Disable Smilies in This Post’ button below the text box.

---

<div class="post-metadata">

**Author:** ![Ms2001](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ms2001/32/18463_2.png) [@Ms2001](https://boards.straightdope.com/u/Ms2001)\
**Post date:** [December 6, 2002, 1:02pm UTC](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501/60 "2002-12-06T13:02:20Z")

</div>

Object-oriented programming languages differ from each other more than regular procedural languages. The way you use objects in C++ is about 50% different from how you use them in Delphi (where all object variables are pointers), and totally different from Objective C or Smalltalk (where you pass messages at run time instead of binding method calls at compile time).

Another difference between C++ and most other languages is the role of user-defined types. In C++, the compiler works enough magic that you can extend the language to fit your needs by writing new classes, though the purpose of your code will be unclear to anyone who isn’t familiar with your new types. Other languages (e.g. Delphi, Java) make a much greater distinction between language syntax and user function calls, which means coding is more tedious, but your code is more readable.

[Previous page](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501.md?page=2)

[Next page](https://boards.straightdope.com/t/how-do-people-start-programming-c-or-c/139501.md?page=4)
