C as first language?

T

toxemicsquire4

I'm learning C right now as my first language(I've done functions, loops, data types, if/else), and I'm wondering if I'm going the right path. I've heard alot of good stuff about C, like how it's super fast and simple to learn. I've also heard alot of bad stuff about how it's old, busted, and non-object oriented. I'm a linux user(Arch/Gentoo), and I want to get started on a project after I'm done learning. I want to join an operating system project and help in it and stuff(I really like the whole idea of operating systems and how many layers it has), but I want to make sure I'm getting the right stuff so I could learn what I need.

What do you guys think is the benifit of learning C first? What would be a drawback?(BTW: I'm totally fine with the manual memory thing(it turns me on(I know that's a bit weird, but I'm a linux geek)) and I'm willing to learnit). What would be some good sources of learning? What practices should I avoid? What OS projects would be good for a beginner?
 
S

Stefan Ram

non-object oriented. I'm a linux user(Arch/Gentoo), and I
want to get started on a project after I'm done learning.

I will be done learning C the day I die.
What do you guys think is the benifit of learning C first?

If you already know that you want to do something where some
language is the most important language, than it is best to
immediately start learning that language, without learning
another language before it.
 
G

glen herrmannsfeldt

I'm learning C right now as my first language(I've done functions,
loops, data types, if/else), and I'm wondering if I'm going the
right path. I've heard alot of good stuff about C, like how it's
super fast and simple to learn.

I suggest learning Java first. There are (intentionally) many
similarities between Java and C. Java will help you learn much
of what you need to learn such that when you do learn C, it
will go much easier.

More specifically, there are two "teaching styles" used with Java,
called "objects early" and "objects last". If your real interest
is C, then learning "objects last" will get you in the right
direction. (You can even quit Java and switch to C when you get
to objects, but it is probably better not to do that.)

Java is much better at catching and reporting many common errors
of beginning programmers. Once you learn to avoid those, you will
be in better shape to learn C.
I've also heard alot of bad stuff about how it's old, busted,
and non-object oriented. I'm a linux user(Arch/Gentoo), and
I want to get started on a project after I'm done learning.

Well, you can write object-oriented code in any language.
The OO languages have provisions to make it easier, though.
I want to join an operating system project and help in it
and stuff(I really like the whole idea of operating systems
and how many layers it has), but I want to make sure I'm
getting the right stuff so I could learn what I need.

I never got so interested in operating systems, but I did get
interested in compilers pretty early.

-- glen
 
O

Omar Radwan

I've seen some Java code and I know some basic syntax, no offense, but I'm not very fond of Java, because everything you write is a class that turns into an object. I also would rather much use something compiled, instead of a virtual machine thing.
 
G

glen herrmannsfeldt

Omar Radwan said:
I've seen some Java code and I know some basic syntax, no offense,
but I'm not very fond of Java, because everything you write is
a class that turns into an object.

Well, you can write your whole program as one class, and mostly
not do much with objects. The String class is pretty useful, and so
you probably have to use it, but it isn't so hard to use. Many others
are also useful, but it is your choice to use them or not.
I also would rather much use something compiled, instead of
a virtual machine thing.

Java is compiled. The processor that it compiles for is sometimes
interpreted, though the JIT compiler makes the run time darn close
to code compiled for your actual processor. There have been
hardware chips that execute JVM code directly, though not recently.

But unless it is too slow, which it usually isn't, what are
you complaining about?

-- glen
 
K

Kaz Kylheku

I'm learning C right now as my first language(I've done functions, loops,
data types, if/else), and I'm wondering if I'm going the right path.

You are.

Normally, I would recomment English as a good language to learn first (or next)
for the average troglodyte who posts here, but you seem okay in that
department.
I've heard alot of good stuff about C, like how it's super fast and simple to
learn.

C is simple to learn. C is not quite so simple to learn to use effectively,
while avoiding pitfalls.
I've also heard alot of bad stuff about how it's old, busted, and
non-object oriented.

Object-oriented programs can be written in C: you get to design the plumbing
of your own object system. There is little support from the language.

Some C programs exhibit considerable OO design, with patterns which are closely
analogous to inheritance, encapsulation and polymorphism. For instance,
numerous areas of the Linux kernel.
What do you guys think is the benifit of learning C first?

The benefit of learning C is that it's the most successful representative and
descendant of that family of languages which includes Pascal, Modula, Algol and
their ilk. Once you learn C, you have that whole thing covered.

C has become ubiquitous for expressing system level programming interfaces, so
if you understand C declaration syntax, that is helpful when using other
languages, which necessarily have to have bindings to C interfaces for
sheer survival.
know that's a bit weird, but I'm a linux geek)) and I'm willing to learn it).
What would be some good sources of learning?

The C Programming Language (second edition, Kernighan and Ritchie)
C: A Reference Manual (Harbison and Steele)
What practices should I avoid?

C Traps and Pitfalls (Andrew Koenig)

(this is a book based on a much shorter paper from 1989 of the same name).
What OS projects would be good for a beginner?

Xinu, Minix, ...
 
D

David Brown

I'm learning C right now as my first language(I've done functions,
loops, data types, if/else), and I'm wondering if I'm going the right
path. I've heard alot of good stuff about C, like how it's super fast
and simple to learn. I've also heard alot of bad stuff about how it's
old, busted, and non-object oriented. I'm a linux user(Arch/Gentoo),
and I want to get started on a project after I'm done learning. I
want to join an operating system project and help in it and stuff(I
really like the whole idea of operating systems and how many layers
it has), but I want to make sure I'm getting the right stuff so I
could learn what I need.

What do you guys think is the benifit of learning C first? What would
be a drawback?(BTW: I'm totally fine with the manual memory thing(it
turns me on(I know that's a bit weird, but I'm a linux geek)) and I'm
willing to learn it). What would be some good sources of learning?
What practices should I avoid? What OS projects would be good for a
beginner?

I would say that learning C is one of two sensible approaches. The
other is to learn Python.

C is typically the language of choice for low-level programming - OS's,
low-level utilities, libraries, drivers, embedded systems, etc. It is
what you use when you want the best out of the machine, and are willing
to put in the effort.

C is not too hard to learn roughly - it's a small language. But takes
quite a bit of experience to learn to write efficient, safe, reliable
and (at least reasonably) portable programs.

Python is at the other end of the scale. It is a very high level
language, and has standard libraries for all sorts of stuff. It is
quick and easy to write small scripts in Python, and it excels at
handling strings and files. It is therefore very important as a "glue"
language for the small tasks needed to keep everything together. But it
also works well for larger programs and supports object oriented
programming and various safety features, and is used heavily in web servers.

Python is easy to get started with, as it is interpreted and you get a
lot of high-level structures and libraries included. But it is
generally significantly slower than C (though there are exceptions). It
is quick for programming, but slow to run.


As another poster says, a lot depends on what you want to do with your
programming language. If you've got particular tasks in mind, look at
them before deciding. And if you want to contribute to existing
projects, be prepared to spend a lot of effort learning the project in
question - that can be a bigger task than learning the basics of the
language. Certainly Linux kernel work is an art unto itself - you can
have programmed C for 30 years and still have trouble understanding it
or spotting the subtleties.
 
L

luser droog

I will be done learning C the day I die.


If you already know that you want to do something where some
language is the most important language, than it is best to
immediately start learning that language, without learning
another language before it.

Hear, hear!
 
B

BartC

I'm a linux user(Arch/Gentoo), and I want to get started on a project after
I'm done learning. I want to join an operating system project and help in
it and stuff(I really like the whole idea of operating systems and how many
layers it has), but I want to make sure I'm getting the right stuff so I
could learn what I need.

If you're using Linux and want to do OS work (presumably associated with
Linux) then I don't think there's any alternative to learning C. (Which is
also a good prerequisite to learning other similar languages; a bit like
learning to drive with a manual gear shift.)
What OS projects would be good for a beginner?

There is a newsgroup alt.os.development where some guys hang out who do work
on OSes (I think, writing their own). They might have some ideas.
 
J

James Harris

glen herrmannsfeldt said:
I suggest learning Java first. There are (intentionally) many
similarities between Java and C. Java will help you learn much
of what you need to learn such that when you do learn C, it
will go much easier.

The OP linked learning a language to getting involved in OS development.
Were you thinking he could use Java to develop an OS or just as a first step
before learning C or another language?

James
 
J

James Harris

Kaz Kylheku said:
....


C is simple to learn. C is not quite so simple to learn to use
effectively,
while avoiding pitfalls.

C should be a great first language for someone who wants to learn
programming. Rather than hiding internals C lets the programmer work with
many real implementation details. A programmer who wants to learn C first
would get a reasonably good understanding of what a computer actually does
when executing a program. That can only stand the programmer in good stead
for learning other languages, if necessary. There are lots of examples of
low-level concepts such as:

* C's data types map to hardware
* C includes an unsigned type (not all languages do)
* C's function calls have explicit parameters (no hidden keyword mechanism)
* C's operators and constructs map to machine instructions
* C's pointer types are unadorned

At the same time C does abstract somewhat from base hardware: automatic type
conversions, less than total control over struct layout, no control over
call mechanism etc. But apart from an assembly language I don't know any
good language which gives better control.
Object-oriented programs can be written in C: you get to design the
plumbing
of your own object system. There is little support from the language.

Some C programs exhibit considerable OO design, with patterns which are
closely
analogous to inheritance, encapsulation and polymorphism. For instance,
numerous areas of the Linux kernel.

The only important thing I can think of that C lacks is support for separate
namespaces. Other things can be written in as needed.
The benefit of learning C is that it's the most successful representative
and
descendant of that family of languages which includes Pascal, Modula,
Algol and
their ilk. Once you learn C, you have that whole thing covered.

C has become ubiquitous for expressing system level programming
interfaces, so
if you understand C declaration syntax, that is helpful when using other
languages, which necessarily have to have bindings to C interfaces for
sheer survival.

That is a really important point. A great deal of documentation is expressed
in C such as manpages and code snippets in books and online. That alone
makes it a language that programmers should know in order to understand info
supplied by others and to use to express info to fellow programmers.
The C Programming Language (second edition, Kernighan and Ritchie)

A great suggestion, IMO, at least for someone who has programmed before.
Would you say it is also good for someone to learn programming from?

....
Xinu, Minix, ...

Some sources of info

Usenet newsgroup alt.os.development (as Bartc already suggested)
http://wiki.osdev.org/Expanded_Main_Page
http://aodfaq.wikispaces.com/

James
 
V

Vijay WroX

I'm learning C right now as my first language(I've done functions, loops,data types, if/else), and I'm wondering if I'm going the right path. I've heard alot of good stuff about C, like how it's super fast and simple to learn. I've also heard alot of bad stuff about how it's old, busted, and non-object oriented. I'm a linux user(Arch/Gentoo), and I want to get started on a project after I'm done learning. I want to join an operating system project and help in it and stuff(I really like the whole idea of operating systems and how many layers it has), but I want to make sure I'm getting the right stuff so I could learn what I need.



What do you guys think is the benifit of learning C first? What would be a drawback?(BTW: I'm totally fine with the manual memory thing(it turns me on(I know that's a bit weird, but I'm a linux geek)) and I'm willing to learn it). What would be some good sources of learning? What practices should I avoid? What OS projects would be good for a beginner?

Hi OP,
There have been several great replies and suggestions already. So, I'm justgoing to give 3 suggestions for you to start on as those are what I started with:
1. K & R The C Programming Language book
2. Operating System - Design and Implementation by Andrew S Tanenbaum book
3. OSDev.org wiki pages

As a fourth, I'd suggest start with a cute Linux OS such as Ubuntu or use Cygwin if you love Windows. Command line and programming always make you learn a lot of important nuances like the warnings, errors and why they happen..

Good luck
-
VwX
 
B

Ben Bacarisse

James Harris said:
A great suggestion, IMO, at least for someone who has programmed before.
Would you say it is also good for someone to learn programming from?

I wouldn't, though it is better than many (the examples strike a
reasonable balance between too complex and too silly) but most beginners
find it way too terse.

The trouble is that books that teach programming are rare, and good ones
that teach programming are spectacularly rare. And I don't know any
that use C, good or bad.

In fact this brings up another problem. C seems to the language every
programmer knows, and almost all of the seem to have written a terrible
tutorial about it on the web! There is probably more bad source
material about C than about any other language, and it's tricky, when
learning, to pick your way though all the crud.

I don't have much help to offer except that I'd strongly advice the OP
to learn several languages at once. You soon find out that the language
is not usually the hard part. The hard part is designing the program
within the constraints of the language, and that skill is pretty much
universal. You also avoid the danger of thinking in C -- the trick is
to think in terms of programs that map into C.

<snip>
 
S

Stefan Ram

Ben Bacarisse said:
I don't have much help to offer except that I'd strongly advice the OP
to learn several languages at once.

I'd advice exactly the contrary! Learning several languages
at once makes learning more difficult. For example,
bilingual children are less fluent in each language
according to some tests. For another example, the term
»object« has a different meaning in C than in Java, but most
of those who have learned Java and C at the same time cannot
give the correct definition of »object« in C.
You soon find out that the language is not usually the hard
part.

When one already has learned most of the language, this is
easy to say.
You also avoid the danger of thinking in C -- the trick is
to think in terms of programs that map into C.

The best C programmers think and dream in C, and ignore all
distractions, such as other programming languages, except
when writing an implementation for another language in C.
 
B

Ben Bacarisse

I'd advice exactly the contrary! Learning several languages
at once makes learning more difficult. For example,
bilingual children are less fluent in each language
according to some tests. For another example, the term
»object« has a different meaning in C than in Java, but most
of those who have learned Java and C at the same time cannot
give the correct definition of »object« in C.

I don't know that learning simple artificial languages as an adult
compares to learning natural language as a baby. I suspect that even
the end measure -- fluency is a completely different thing in the two
cases. I'll accept your point if there is any evidence linking the two
modes of learning.
When one already has learned most of the language, this is
easy to say.

Maybe, but I say this as someone experienced with teaching both.
The best C programmers think and dream in C, and ignore all
distractions, such as other programming languages, except
when writing an implementation for another language in C.

An interesting claim. What's your evidence? (It's OK to have none,
many things in this area as surmised from nothing more than anecdote
and persona experience).
 
S

Stefan Ram

Ben Bacarisse said:
Maybe, but I say this as someone experienced with teaching both.

Then we have something in common! Today I will give my next
Java class, and on the 5th of this November my next C course
will start (in Berlin, Germany at the Volkshochschule Pankow).
In this year, I am also giving classes in C++, Android
programming, SQL, and JavaScript.

So I do not live up to my own recommendation - that one
should only learn one language. I'd /prefer/ to do
everything in a single language only, like, for example, C.
But this world was forcing me to learn several languages!
An interesting claim. What's your evidence? (It's OK to have none,
many things in this area as surmised from nothing more than anecdote
and persona experience).

One of the most common misconceptions about programming is
the idea that there were »language-independent algorithms«
or designs that one then can just implement in any language.

Instead, when designing the same program for several
languages, such as C, Haskell, Prolog, and 6502, one needs
different program designs right from the start! The best
C program, therefore, is designed right from the start with C
in mind. To learn more about this mindset, one might read
on the web: »Code as Design: Three Essays by Jack W. Reeves«.

For example, the C algorithm to calculate the absolute value
of a number x is: »#include <math.h> and then call fabs«.
The 6502 algorithm to do the same would be more complicated.
 
K

Kaz Kylheku

C should be a great first language for someone who wants to learn
programming. Rather than hiding internals C lets the programmer work with
many real implementation details. A programmer who wants to learn C first
would get a reasonably good understanding of what a computer actually does
when executing a program. That can only stand the programmer in good stead
for learning other languages, if necessary. There are lots of examples of
low-level concepts such as:

* C's data types map to hardware
* C includes an unsigned type (not all languages do)
* C's function calls have explicit parameters (no hidden keyword mechanism)
* C's operators and constructs map to machine instructions
* C's pointer types are unadorned

At the same time C does abstract somewhat from base hardware: automatic type
conversions, less than total control over struct layout, no control over
call mechanism etc. But apart from an assembly language I don't know any
good language which gives better control.


The only important thing I can think of that C lacks is support for separate
namespaces. Other things can be written in as needed.


That is a really important point. A great deal of documentation is expressed
in C such as manpages and code snippets in books and online. That alone
makes it a language that programmers should know in order to understand info
supplied by others and to use to express info to fellow programmers.


A great suggestion, IMO, at least for someone who has programmed before.
Would you say it is also good for someone to learn programming from?

For someone who has programmed before, perhaps.

"Algorithms in C" by Robert Sedgewick also comes to mind, by the way.

If you're learning how to program and need to know about algorithms,
and are choosing C, then it makes sense to have a book about that subject
which uses C. Almost a no brainer.
 
M

Malcolm McLean

An interesting claim. What's your evidence? (It's OK to have none,
many things in this area as surmised from nothing more than anecdote
and persona experience).
The Open GL programmers' guide famously glossed C as "God's own programming language".
It's almost perfect as an abstraction of a general assembler.

All procedural languages perform arithmetical or logical operations, copy memory from
one location to another, and allow conditional jumps, plus some mechanism for jumping to
a passed address.
You need a slight layer over those to have a usable, non-assembly language, such as
an infix expression syntax, named variables with scoping, and a subroutine call mechanism.
But that's all you really need.
The core C language provides what you need, and no more. So if you're thinking of an
algorithm you'll think of it in C terms - usually, in terms of a graph connected by pointers,
and operations on that graph.
 
D

David Brown

Then we have something in common! Today I will give my next
Java class, and on the 5th of this November my next C course
will start (in Berlin, Germany at the Volkshochschule Pankow).
In this year, I am also giving classes in C++, Android
programming, SQL, and JavaScript.

So I do not live up to my own recommendation - that one
should only learn one language. I'd /prefer/ to do
everything in a single language only, like, for example, C.
But this world was forcing me to learn several languages!


One of the most common misconceptions about programming is
the idea that there were »language-independent algorithms«
or designs that one then can just implement in any language.

Instead, when designing the same program for several
languages, such as C, Haskell, Prolog, and 6502, one needs
different program designs right from the start! The best
C program, therefore, is designed right from the start with C
in mind. To learn more about this mindset, one might read
on the web: »Code as Design: Three Essays by Jack W. Reeves«.

For example, the C algorithm to calculate the absolute value
of a number x is: »#include <math.h> and then call fabs«.
The 6502 algorithm to do the same would be more complicated.

Of course there are language-independent algorithms and program designs,
but it is also true that the algorithms and design you use is likely to
be strongly influenced by the programming language targeted.

It often makes sense to think in terms of programming paradigms rather
than programming languages. The way you design an algorithm in C and in
Haskell is likely to be significantly different, but the algorithm in C
and Pascal is likely to be very similar (both are imperative languages)
while the algorithm in Haskell and OCaml will be similar (both are
functional programming languages). In each case, however, the
beginnings of the design are the same - you start with pencil and paper,
or a whiteboard, with a combination of maths, natural language and lines
and arrows rather than any programming language.
 
B

BartC

Instead, when designing the same program for several
languages, such as C, Haskell, Prolog, and 6502, one needs
different program designs right from the start! The best
C program, therefore, is designed right from the start with C
in mind. To learn more about this mindset, one might read
on the web: »Code as Design: Three Essays by Jack W. Reeves«.

For example, the C algorithm to calculate the absolute value
of a number x is: »#include <math.h> and then call fabs«.
The 6502 algorithm to do the same would be more complicated.

You seem confused about what an algorithm is. One for determining the
absolute value of a number is something like:

abs(x) = if x>=0 then x else -x

Leaving it to the language to provide an implementation (and decide what to
do with any corner cases).

(I assume by 6502, you mean the machine language for that device.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top