C as first language?


B

Ben Bacarisse

An algorithm expresses the solution to a problem with the
elements of a given language, whatever language this is.

Malcolm has made the preposterous claim that "if you're thinking of an
algorithm you'll think of it in C terms".

The question of whether some "language" is needed (however abstract and
ill-specified) simply to *think* about algorithms, is one I am not
remotely qualified address. I could report what I feel is happening in
my head when I do such a thing, but will that help to arrive at a true
picture of the phenomenon? I doubt it.

Expressing an algorithm needs a notation, but that's as far as I'd be
prepared to go.
 
Ad

Advertisements

S

Stefan Ram

Ben Bacarisse said:
The question of whether some "language" is needed (however abstract and
ill-specified) simply to *think* about algorithms, is one I am not
remotely qualified address. I could report what I feel is happening in
my head when I do such a thing, but will that help to arrive at a true
picture of the phenomenon? I doubt it.

It depends on the definitions used. ISO/IEC 2382-1:1993
»Information technology -- Vocabulary -- Part 1: Fundamental
terms«, which is a normative reference of n1570, says:

»01.05.05
algorithm
A finite ordered set of well-defined
rules for the solution of a problem.«

If this is a /set/, then by the mathematical definition of
»set«, all its elements must be clearly specified. Without
any language, it should be difficult to specify rules.
 
G

G G

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.

learn assembler first. ;-)
after that, C will be the greatest lang. you will come to know.

just kidding about assembler first.
C is ok for a first lang. Pascal would be better. i don't think Pascal has a lot of followers these days.

but, pascal was cool. loved that lang. the elders remember it, but they may have real problems with it. but, i loved it. ada is similar but it's too, something... didn't like it at all.
 
J

James Harris

Jorgen Grahn said:
....

I /would/ recommend skipping C and going straight to C++, while still
being able to use the same set of C libraries and tools ... but that
would be rude considering this is comp.lang.c.

I have to say that I think that it is a terrible idea for a beginner to
learn C++ first. (Sorry!) C++ has its good points but, like many languages
which start off well, has become too large and cumbersome. It is mentally
manageable if a programmer sticks to a subset of C++ - and I presume that's
what you had in mind - but the trouble is that one has to interact with the
ninjas who want to use the more esoteric features. C++ was already bulky in
its early days, compared to C. It has since become worse. Thus there is a
lot of it to learn if one wants to work with others.

Programming language designers, ISTM, get hooked on adding features. Perhaps
because they are so familiar with their own languages they see them as
easily understandable. So enhancements don't seem to add much complexity.
And there is always the temptation to add a useful new feature - like being
on a diet but gazing at tempting items of food! So the language gets bigger
and increases the knowledge a programmer needs not for his own code but in
order to interact with other programmers who might use those features.

By contrast, C has been kept admirably small even after decades. That is
remarkable in itself but it also, IMO, makes C a better language for a new
programmer to learn properly.

James
 
I

Ian Collins

James said:
I have to say that I think that it is a terrible idea for a beginner to
learn C++ first. (Sorry!) C++ has its good points but, like many languages
which start off well, has become too large and cumbersome. It is mentally
manageable if a programmer sticks to a subset of C++ - and I presume that's
what you had in mind - but the trouble is that one has to interact with the
ninjas who want to use the more esoteric features. C++ was already bulky in
its early days, compared to C. It has since become worse. Thus there is a
lot of it to learn if one wants to work with others.

The more complexity that goes into the language (and its library), the
less ends up in user code! C++ resource management is a classic example.
Programming language designers, ISTM, get hooked on adding features. Perhaps
because they are so familiar with their own languages they see them as
easily understandable. So enhancements don't seem to add much complexity.
And there is always the temptation to add a useful new feature - like being
on a diet but gazing at tempting items of food! So the language gets bigger
and increases the knowledge a programmer needs not for his own code but in
order to interact with other programmers who might use those features.

The C++ committee listens to the user community and adds features that
users want and in many case have been using through libraries such as
boost. Now if C only had a sandpit like boost to develop new ideas...
By contrast, C has been kept admirably small even after decades. That is
remarkable in itself but it also, IMO, makes C a better language for a new
programmer to learn properly.

Maybe, there's certainly less to learn, but is there less to learn
before a newcomer can produce robust code? A good example is the input
thread that's been running and running. It simply wouldn't happen on a
C++ list because the language has the necessary support for arbitrarily
long lines.
 
B

BartC

Ian Collins said:
James Harris wrote:

(I agree. Probably not as a second or third language either, only if it's
unavoidable.)
The more complexity that goes into the language (and its library), the
less ends up in user code! C++ resource management is a classic example.
Maybe, there's certainly less to learn, but is there less to learn before
a newcomer can produce robust code? A good example is the input thread
that's been running and running. It simply wouldn't happen on a C++ list
because the language has the necessary support for arbitrarily long lines.

You're talking about C++ pretending it is a higher level language than C.

Certainly it can do many things which are already built-in, but the
cumbersome mechanics of how they are implemented aren't very well hidden and
the resulting code tends to be ugly (enough to put people off).

If a beginner wants a higher level language to experiment with, then there
are easier ones: Python has been mentioned to complement C. For example,
someone mentioned a GCD algorithm, here is a version in Python:

def gcd(a,b):
while b!=0:
t=b
b=a % b
a=t
return a

print (gcd(31415926534676736647,438478473847834834784748))

It just works.

But also, with a language like C++ with so many things built-in, there is
less opportunity to learn how to implement them, because they're already
there! (And with over-the-top implementations too.)

(The language is also extremely complex; most people seem to agree about
that. I've been programming for decades, and I could never get my head
around it. It's not enough to say you only need to use a subset; you're
always aware of the complexity behind the scenes. It's not a beginner's
language.)
 
Ad

Advertisements

B

Borax Man

G said:
learn assembler first. ;-)
after that, C will be the greatest lang. you will come to know.

just kidding about assembler first.
C is ok for a first lang. Pascal would be better. i don't think Pascal has
a lot of followers these days.

but, pascal was cool. loved that lang. the elders remember it, but they
may have real problems with it. but, i loved it. ada is similar but it's
too, something... didn't like it at all.

I learned assembler first, and C made a LOT more sense because of it.
Pointers and pointer arithmetic, referencing and dereferencing instantly
made sense. Many other aspects of C were "familiar".
 
G

glen herrmannsfeldt

(snip)
I have to say that I think that it is a terrible idea for a beginner to
learn C++ first. (Sorry!) C++ has its good points but, like many languages
which start off well, has become too large and cumbersome. It is mentally
manageable if a programmer sticks to a subset of C++ - and I presume that's
what you had in mind - but the trouble is that one has to interact with the
ninjas who want to use the more esoteric features. C++ was already bulky in
its early days, compared to C. It has since become worse. Thus there is a
lot of it to learn if one wants to work with others.
Programming language designers, ISTM, get hooked on adding features.

Well, there is what Brooks, in "Mythical Man Month" calls "The Second
System Effect". That was intended to apply to OS designers, but
could also apply in this case.
Perhaps because they are so familiar with their own languages
they see them as easily understandable. So enhancements don't
seem to add much complexity.
And there is always the temptation to add a useful new
feature - like being on a diet but gazing at tempting items
of food! So the language gets bigger and increases the
knowledge a programmer needs not for his own code but in
order to interact with other programmers who might use
those features.

-- glen
 
I

Ian Collins

BartC said:
You're talking about C++ pretending it is a higher level language than C.

Certainly it can do many things which are already built-in, but the
cumbersome mechanics of how they are implemented aren't very well hidden and
the resulting code tends to be ugly (enough to put people off).

If a beginner wants a higher level language to experiment with, then there
are easier ones: Python has been mentioned to complement C. For example,
someone mentioned a GCD algorithm, here is a version in Python:

def gcd(a,b):
while b!=0:
t=b
b=a % b
a=t
return a

print (gcd(31415926534676736647,438478473847834834784748))

It just works.

I think you just proved my point that the more complexity that goes into
the language (and its library), the less ends up in user code!
 
J

Jorgen Grahn

I don't know how things are done elsewhere, but all of my clients who
produce "embedded" (some are Linux based) C products use Python for
their acceptance and production test systems.

Same experience here. Python is by far the most common tool for such
things. Free, flexible and perceived as newbie-friendly.
I'm guessing this is a
pretty popular combination. On the OS front, I'm not sure about Linux,
but Solaris derived systems use a lot of Python.

IME it's uncommon to find a Linux system where Python isn't installed.
Many (all?) distributions use it for infrastructure things, when shell
scripts aren't enough.

....
Write your unit tests in C++!

I planned to skunk that in, but sadly missed my window of opportunity.

/Jorgen
 
Ad

Advertisements

J

jacob navia

Le 21/05/2014 23:07, Jorgen Grahn a écrit :
(Also I tend to get paid for writing C code, but not C++.)

I would say that this is not a coincidence.

C is much more popular than C++
 
J

Jorgen Grahn

.
([C++] is also extremely complex; most people seem to agree about
that.

I won't do C++ advocacy here, except I'll note that I don't find it
particularly complex (and I'm not particularly smart). Working with
it is like working in C, except you don't have to invent linked lists
over and over again.
I've been programming for decades, and I could never get my head
around it.

To me that translates to one of:
- I never seriously tried.
- I got burned in the OOP craze in the early 1990s, when it
was more important that your code could be reused in the
Space Shuttle than that it solved your immediate problem.

I can emphatize with the latter ... one drawback that C++ has and C
hasn't is that it -- sometimes -- attracts people who aren't
interested into Getting Things Done.

/Jorgen
 
B

BartC

Jorgen Grahn said:
([C++] is also extremely complex; most people seem to agree about
that.

I won't do C++ advocacy here, except I'll note that I don't find it
particularly complex (and I'm not particularly smart). Working with
it is like working in C, except you don't have to invent linked lists
over and over again.

So why hasn't C disappeared then, as everyone rushes to use C++ which is so
much better?

(BTW you only have to invent linked lists once. You might have to implement
them more than once, but since my data structures were linked to each other
in up to seven different ways, a simple generic off-the-shelf linked-list
type in a library wouldn't have worked.)
To me that translates to one of:
- I never seriously tried.

I've tried to get into it every so often, to discover the mysteries of OOP
and templates and generics and polymorphism and so on. But when I looked at
examples, it was stuff I'd already been doing for years anyway in some
dynamic language or other, without even knowing I was doing it! And with a
lot less effort. C++ might just do some things a bit faster.

(In my case I use two levels of language: a higher level (than C++) dynamic
language to do most of my work, and a lower-level one (C or like C) to
implement the other; this one doesn't need to be fancy. I don't need a
generic, flex array type, because that's in the other language.)
 
J

James Harris

Jorgen Grahn said:
Ok, but please note that that was not what I suggested!

I suppose it wasn't! The OP who asked for suggestions did say he was a
beginner. I assumed you were answering in that context but I see that could
have been an incorrect assumption.

James
 
M

Malcolm McLean

I learned assembler first, and C made a LOT more sense because of it.
Pointers and pointer arithmetic, referencing and dereferencing instantly
made sense. Many other aspects of C were "familiar".
I'd been programming on and off for about ten years when I got my first C
compiler. So for me "that funny asterisk isn't a unary multiply, it's the
indirection operator" more or less sorted pointers. To someone who is new
to programming, however, they are often highly confusing.
 
Ad

Advertisements

J

Jorgen Grahn

I suppose it wasn't! The OP who asked for suggestions did say he was a
beginner. I assumed you were answering in that context but I see that could
have been an incorrect assumption.

Sorry, that's probably also a misreading. The advice I was playing
with was "learn and use C++ and skip C" rather than "learn C++ with
the final goal to learn and use C".

I don't believe in making detours via another language -- except very
brief ones which can show you what's unique to/missing from the
language you're learning. People seem to find it hard to separate at
least the statically typed languages, and you see them write C++ as if
it was Java, C++ as if it was C and C as if it was C++.

/Jorgen
 
J

Jorgen Grahn

Jorgen Grahn said:
([C++] is also extremely complex; most people seem to agree about
that.

I won't do C++ advocacy here, except I'll note that I don't find it
particularly complex (and I'm not particularly smart). Working with
it is like working in C, except you don't have to invent linked lists
over and over again.

So why hasn't C disappeared then, as everyone rushes to use C++ which is so
much better?

A good question, and I often ask myself that.

C works, that's one reason. It's known not to be a toy language!

Another may be a certain conservatism in the ecosystem where C is
strong (Unix, embedded -- the areas where I myself work). In the
Microsoft or Java worlds people seem prepared to switch everything and
relearn once a year. I think it takes years to be optimally
productive in a programming environment, so I assume those people are
always working /below/ their optimal level.

A third is I think organizations got burned in the 1990s when they
tried to switch from C to a not fully mature C++, and at the same time
focus heavily on OOA/OOD/OOP and navel-gazing in general. I know
examples of companies which had disaster projects back then, and then
blamed and more or less banned C++ until now.

Fourth: there are many more ways to do things in C++, and it's hard to
get people to agree on one. I sometimes think this is the best
argument for C -- although there are surprisingly many incompatible
ways to treat C too!
(BTW you only have to invent linked lists once. You might have to implement
them more than once, but since my data structures were linked to each other
in up to seven different ways, a simple generic off-the-shelf linked-list
type in a library wouldn't have worked.)


I've tried to get into it every so often, to discover the mysteries of OOP
and templates and generics and polymorphism and so on.

I never could get my head around OOP and polymorphism either -- write
your code as a deep class hierarchy and I'm immediately lost. I
suspect it's a personality thing, because experienced programmers tell
me it's the way to go, at least for some kinds of problems.

Fortunately you don't have to do it: you can design all your classes
without any inheritance. The C++ standard library itself rarly uses it.

The big benefits of C++ lie elsewhere, and would IMO feel more natural
to someone coming from C.
But when I looked at
examples, it was stuff I'd already been doing for years anyway in some
dynamic language or other, without even knowing I was doing it! And with a
lot less effort. C++ might just do some things a bit faster.

In recent years I've begun to rewrite much of my Python code into C++.
Not because of speed usually -- I noticed the lack of static type
checking made my code hard to maintain ... I like Python, but the
"rigidness" of C and C++ suits me better in the long run.
(In my case I use two levels of language: a higher level (than C++) dynamic
language to do most of my work, and a lower-level one (C or like C) to
implement the other; this one doesn't need to be fancy. I don't need a
generic, flex array type, because that's in the other language.)

That's not the scenario I was thinking of ... True, if you're program
is e.g. Python with some "leaf" parts in C, you have little use for C++.

/Jorgen
 
J

J. Clarke

Sorry, that's probably also a misreading. The advice I was playing
with was "learn and use C++ and skip C" rather than "learn C++ with
the final goal to learn and use C".

I don't believe in making detours via another language -- except very
brief ones which can show you what's unique to/missing from the
language you're learning. People seem to find it hard to separate at
least the statically typed languages, and you see them write C++ as if
it was Java, C++ as if it was C and C as if it was C++.

There's an old saying, "You can write FORTRAN in any language". If your
goal is to learn X then learn X, not Y that is somewhat similar to X.
If your goal is to learn to program and not to learn a specific
language, then your options are broader.
 
Ad

Advertisements

G

glen herrmannsfeldt

(snip)
There's an old saying, "You can write FORTRAN in any language".
If your goal is to learn X then learn X, not Y that is somewhat
similar to X.

And my Java code probably looks more like C than most Java
programmers would expect. For one, I now use

System.out.format()

for most of my output. A relatively new addition to Java
that works much like C's printf. One difference, though, is
that you use %n instead of \n to generate a newline.
I believe it generates \r\n on Windows machines.
If your goal is to learn to program and not to learn a specific
language, then your options are broader.

-- glen
 

Similar threads

S
Replies
0
Views
611
smocho
S
C
Replies
2
Views
264
ChillyBilly
C
D
2 3 4
Replies
76
Views
3K
Nick Keighley
N
Thiefcom
Replies
6
Views
1K
sidkaushal95
sidkaushal95
T
Replies
13
Views
806
BartC
B
Z
Replies
1
Views
2K
odlumb
O
P
Replies
3
Views
752
jacob navia
J
T
Replies
9
Views
916
Geoff
G
Top