Programming "only" in an environment of C and it's friends - Being a toolsmith


J

John Reye

Hi,

in writing computer code, the language C has obvious advantages over
other languages ("fads"):
It's close to hardware. It's perfect for operating system interfacing.

You can do anything with it.
Of course this often means creating tools and "programs that write
programs".

A good example is lex or equivalents for lexical analysis, etc.

See http://foldoc.org/toolsmith


I'd rather write C code than Perl-scripts or Python.
But on the other hand I do believe C does require a lot of work, for
which other languages such as Python have already got a lot of built-
in facilities.
I guess that C and tools and a desire for "power" will automatically
lead to C++. C has a notorious lack of GUI libraries (or can you tell
me a good equivalent to something like FLTK and qt?)

My question:
Is it feasible to do everything in C?
Example: Could Unix (or Linux) system administration be done without
Perl and shell-scripting, but using only C. What consequences would
that have?

What languages do you use, and how do you decide what to use?
And how does C fit into the picture?
Thanks.
 
Ad

Advertisements

T

Thomas Richter

Hi,

in writing computer code, the language C has obvious advantages over
other languages ("fads"):
It's close to hardware. It's perfect for operating system interfacing.

That depends on the operating system.
You can do anything with it.

Holds for any Turing complete language. Which includes all the languages
I know.
But on the other hand I do believe C does require a lot of work, for
which other languages such as Python have already got a lot of built-
in facilities.
I guess that C and tools and a desire for "power" will automatically
lead to C++. C has a notorious lack of GUI libraries (or can you tell
me a good equivalent to something like FLTK and qt?)

So does C++. There are plenty third-party libraries, though.
My question:
Is it feasible to do everything in C?

No. Pick the language that solves the problem best. This might be C, but
need not to be.
Example: Could Unix (or Linux) system administration be done without
Perl and shell-scripting, but using only C.

In principle - if you find a way how to run a C compiler without a
shell. But why? Shell scripts are very adequate for most routine tasks,
and explicitly programming a pipe with fgrep and sed in C would be
completely overshooting.
What consequences would
that have?

Total madness of the system operator?
What languages do you use, and how do you decide what to use?

C, C++, python, shell-scriping, Java, Pascal, C#, assembler (if I really
must), sed-regexp, make, latex (that should also count as a language),
perl. With no particular preference. It depends on the problem. User
interfaces are easily done in java. Quick number crunching with complex
algorithms is done in C++. Quick'n dirty sketching of such algorithms
sometimes in C, optimizations in assembly, system adminstration in shell
and python, python for high-level controlling and quick scripting...
And how does C fit into the picture?

As a language somewhere between C++ and assembler to implement
algorithms of small or mediocre complexity with the need of being
reasonably quick without putting too much work into optimization.
At least for me.

So long,
Thomas
 
J

jacob navia

Le 27/05/12 21:32, John Reye a écrit :
Hi,

in writing computer code, the language C has obvious advantages over
other languages ("fads"):
It's close to hardware. It's perfect for operating system interfacing.

You can do anything with it.
Of course this often means creating tools and "programs that write
programs".

A good example is lex or equivalents for lexical analysis, etc.

See http://foldoc.org/toolsmith


I'd rather write C code than Perl-scripts or Python.
But on the other hand I do believe C does require a lot of work, for
which other languages such as Python have already got a lot of built-
in facilities.
I guess that C and tools and a desire for "power" will automatically
lead to C++. C has a notorious lack of GUI libraries (or can you tell
me a good equivalent to something like FLTK and qt?)

My question:
Is it feasible to do everything in C?
Example: Could Unix (or Linux) system administration be done without
Perl and shell-scripting, but using only C. What consequences would
that have?

What languages do you use, and how do you decide what to use?
And how does C fit into the picture?
Thanks.

Look, I use C for most of my programming. Fatter languages will give you
this or that, but they have huge problems, that C avoids.

What is nice in C is that there isn't a "preconceived" ata type or
way of doing things.

C++ has (besides other big drawbacks) OO as a fundamental paradigm.
Lisp has lists, Fortran has numeric applications in view, C# and java
compete for the business market, (both being OO centric).

C is nothing. That's the incredible freedom that it provides. It is
up to you to use it or misuse it.

This is a C group. You will find here people that will be pressed to
tell you that C is not the best, that C++ is better (like Mr Richter
above, for example). Who cares?

C is a good language, with some problems that I have tried to
solve in my system.

But this is also a question of personal philosophy. I like above all
simplicity, lack of unnecessary features, minimal surface but greatest
power. There was a book some centuries ago that put that in a single
sentence:

Small is beautiful.

jacob
 
J

James Kuyper

Hi,

in writing computer code, the language C has obvious advantages over
other languages ("fads"):

Dismissing other languages as fads is rather immature. Some of those
"fads" have been around a lot longer than C, and many of them are
preferred over C in certain contexts for very good reason.
You can do anything with it.

That's not quite true, which answers a question you ask farther down.

....
But on the other hand I do believe C does require a lot of work, for
which other languages such as Python have already got a lot of built-
in facilities.
I guess that C and tools and a desire for "power" will automatically
lead to C++.

Not necessarily; it can lead to many other languages as well, depending
upon what kind of "power" you're looking for.
... C has a notorious lack of GUI libraries (or can you tell
me a good equivalent to something like FLTK and qt?)

There are C interfaces for almost all GUIs; the fact that no such
interface is part of the C standard is not a barrier to using C for such
purposes.
My question:
Is it feasible to do everything in C?

No. C itself gives no direct access to the hardware. Routines that give
such access may be callable by C, but are generally not writable in C.
Many of the C standard library routines are in the standard library
precisely because they do things that user written C code could not do
directly, such as writing to a file. An implementation may provide
extensions to C that allow you to do such things. For instance, many
implementations allow inline assembly using something like asm(), and
many operating systems offer C interfaces. However, those are extensions
to C, they are not C itself.
Example: Could Unix (or Linux) system administration be done without
Perl and shell-scripting, but using only C. What consequences would
that have?

As far as I know, there's nothing that can be done by Perl or a shell
script that couldn't be done using C; they just do somethings more
conveniently than C. perl and shell scripts are (or at least can be)
implemented in C. The main consequence would be that you would have to
develop workarounds for some things that perl or shell scripts do more
easily than C.
What languages do you use, and how do you decide what to use?
And how does C fit into the picture?

I've usually been constrained by our client's requirements. For the last
16 years I've been working on a single project for a single client who
allows us to use C, Fortran, or Ada for our main delivered programs, and
perl for the scripts that control execution of the main programs. Given
those choices, sticking with my predecessors' choices to use C was an
easy decision to make. Some C++ code has been grandfathered in, but it's
almost all C.

If I had more freedom in my choice of languages, I'd like to make more
use of C++, but it would not completely replace C. I'd use perl for any
task where text processing was a large part of the work to be done -
which is not something that comes up much in my work. For analysis and
display of our data, I've found IDL very powerful, particularly because
of it's interactive nature.

I've heard that for various tasks (such as GUI programming or web
interfaces) there are languages which are more powerful than any of the
languages I know best; if I ever needed to write code to perform such
tasks, I'd ask for advice as to the best language to use, and learn it.
I master new programming languages quickly (though less quickly than I
remember doing it a couple of decades ago).
 
J

James Kuyper

On 27.05.2012 21:32, John Reye wrote: ....

As a language somewhere between C++ and assembler to implement
algorithms of small or mediocre complexity with the need of being
reasonably quick without putting too much work into optimization.

Do you mean "moderate" rather than "mediocre"?
 
B

BartC

My question:
Is it feasible to do everything in C?

No. It is more time-consuming, more expensive (if you have to pay for
programmers' time), more error-prone, less readable, needs more maintenance,
less portable (despite what is claimed), less flexible, etc.

But I'm sure you know this already.

You just have to use the right language for the task. In the same way you
might use a bike to to travel to the local shops, and a 747 to travel to
Australia. You *could* use a bike to get to Australia, but you wouldn't.
Example: Could Unix (or Linux) system administration be done without
Perl and shell-scripting, but using only C. What consequences would
that have?

About a month or two, you'd probably use your C to put together some sort of
scripting language so that you can do one-off, everyday tasks in a fraction
of the time.
 
Ad

Advertisements

J

jacob navia

Le 27/05/12 23:29, BartC a écrit :
No. It is more time-consuming, more expensive (if you have to pay for
programmers' time), more error-prone, less readable, needs more
maintenance, less portable (despite what is claimed), less flexible, etc.

But I'm sure you know this already.


This can only come from someone writing in comp.lang.c

:)

More time consuming?

Have you pondered how many days you chased some obscure bug in `the
template code that Mr xyz left you before he left the company?


C is "more error prone" ?

It took the systems engineers of Sun Corp SIX MONTHS to find a memory
leak in their Java system. The problem is that the GC will not
forget that if you have a single bad reference to an object it will NOT
release it, making for a slowly accumulating memory leak.

If you think that horrible bugs happen only in C THINK AGAIN.

Needs more maintenance?
I maintain (sometimes and for a lot of $$$) C++ code. I can tell you
that bugs in C are much easier to find, more simple to spot than
what you find in C++ or other "higher level languages".

Less portable? You are kidding man.

You just have to use the right language for the task. In the same way
you might use a bike to to travel to the local shops, and a 747 to
travel to Australia. You *could* use a bike to get to Australia, but you
wouldn't.

Well, if the 747 you propose is crashing all the time I would prefer
a bike man. I am sure to arrive to Australia instead of crashing
somewhere with a buggy 747!


I am not advocating C for everything, but it has much more uses and it
is much more stable than the GUI add ons and the "language of the day"
 
B

BartC

jacob navia said:
Le 27/05/12 23:29, BartC a écrit :
I am not advocating C for everything, but it has much more uses and it is
much more stable than the GUI add ons and the "language of the day"

My reply was mainly about comparing C to higher-level more dynamic
languages, as this seemed to be what the OP was asking.

I didn't consider anything like C++ at all.
 
M

Malcolm McLean

בת×ריך ×™×•× ×¨×שון, 27 במ××™ 2012 22:29:18 UTC+1, מ×ת Bart:
No. It is more time-consuming, more expensive (if you have to pay for
programmers' time), more error-prone, less readable, needs more maintenance,
less portable (despite what is claimed), less flexible, etc.
It depends what programming you do.

A lot of programming consists of loops, conditional branches, and subroutine calls to execute one-time, high-level logic. It doesn't really matter what syntax you use, the fundamental code is the same. The issue is the subroutines, and the safety of the driver script. C usually has every subroutine you could want available somewhere in a C-callable form. But it's often difficult to integrate the libraries. C can easily be interpreted ina safe manner than prohibits buffer over-runs and other security problems, but generally it is not.

The reason it is not is because of the second common type of programming. This is implementing fundamental, re-useable algorithms. Things like matrix inversions, frequency transforms, neural networks, polygon clippers and lighters. The things that make programs work. Here, usually performance is at a premium. And usually the fundamental problem boils down to bit bashing. C's very good for this. Some people like to use Fortran because they're mathematicians or physicists rather than programmers, and sometimes you want Lisp if the problem is graph-like and suitable for metaprogramming rather than bit bashing. Then of course if speed really is a premium, you resort to assembler. But mainly you want C. Virtually always you want the function to have C-callable interface.
 
K

Kaz Kylheku

Example: Could Unix (or Linux) system administration be done without
Perl and shell-scripting, but using only C. What consequences would
that have?

The consequences that a loon will be replaced by a normal thinking sysadmin.
 
Ad

Advertisements

I

Ian Collins

Hi,

in writing computer code, the language C has obvious advantages over
other languages ("fads"):

Some of those "fads" have grey hair and grandchildren.
It's close to hardware. It's perfect for operating system interfacing.

You can do anything with it.
Of course this often means creating tools and "programs that write
programs".

A good example is lex or equivalents for lexical analysis, etc.

See http://foldoc.org/toolsmith


I'd rather write C code than Perl-scripts or Python.

Scripting languages often have existing libraries that can save you a
lot of time.
But on the other hand I do believe C does require a lot of work, for
which other languages such as Python have already got a lot of built-
in facilities.
I guess that C and tools and a desire for "power" will automatically
lead to C++. C has a notorious lack of GUI libraries (or can you tell
me a good equivalent to something like FLTK and qt?)

GTK and the Gnome desktop is written in C.
My question:
Is it feasible to do everything in C?

Yes, but...
Example: Could Unix (or Linux) system administration be done without
Perl and shell-scripting, but using only C. What consequences would
that have?

A lot of wasted time. Not all Unix commands have a public interface, so
it is often easier to invoke them from a script (yes I know you could
use system(), but why bother?). There are also commands that are
written in other languages (like Solaris' package management which is
written in Python).
What languages do you use, and how do you decide what to use?

Bash, PHP and Python for small command line tools (especially text
processing) or anything platform neutral and mainly C++ for heavyweight
applications. JavaScript for GUIs.
And how does C fit into the picture?

Places without C++ runtime support, such as kernel modules.
 
G

Guest

in writing computer code, the language C has obvious advantages over
other languages ("fads"):
It's close to hardware.

this is a double edged sword. When you don't need to be close to the machine its a disadvantage. you don't spend your time in higher level languages worrying about memory leaks and pointer arithmatic errors. You also know howbig an array is.
It's perfect for operating system interfacing.

I think taht's a bit of a coincidence
You can do anything with it.

amazing. It's Turing Complete. This is trivially true of pretty much all programming languages. The question is not "can it do anything?" but "can it do something easily?". The reason for the existence of multiple languages is the answer in "no", for *all* languages
Of course this often means creating tools and "programs that write
programs".

see Greespans 10th Law
A good example is lex or equivalents for lexical analysis, etc.

See http://foldoc.org/toolsmith

I'd rather write C code than Perl-scripts or Python.

Using C to do what Perl does is frankly a pain in the ass. Python's collection of tools ***shipped with it*** make it a nice environment to knock up tools in. I also quite like Python as a language. Perl's a bit of a mess.
But on the other hand I do believe C does require a lot of work, for
which other languages such as Python have already got a lot of built-
in facilities.

quite. The Turing Tarpit and all that.
I guess that C and tools and a desire for "power" will automatically
lead to C++.

I don't see why. C++ is equally impoverished for built in tools.
C has a notorious lack of GUI libraries (or can you tell
me a good equivalent to something like FLTK and qt?)

My question:
Is it feasible to do everything in C?

is it sane?
Example: Could Unix (or Linux) system administration be done without
Perl and shell-scripting, but using only C.

the lack of an interpreter would be a bit of a pain. There are many conveniences in shell languages that have no C equivalent. Though their syntax is often mind-boggeling crazy and inconsistent.

Quick: I want to read a data file match certain patterns and output a reformtted version. That's about 10 lines of Perl (and I'm a crap Perl programmer). Basically I've finished the job in less time tahn it would take me to choose which regexp library to use. Let alone download it, read the documentation find out it doesn't do anchored matches find another package...
What consequences would that have?

piles of ugly unnecessary C? SysAdmins fighting compilers?
What languages do you use,

Perl, Python, C, C++. Scheme
and how do you decide what to use?

Perl as a super-Awk. Python for quick tools, C or C++ for applications. Scheme mostly playing at the moment.
 
I

Ian Collins

Le 27/05/12 21:32, John Reye a écrit :

Look, I use C for most of my programming. Fatter languages will give you
this or that, but they have huge problems, that C avoids.

What "huge problems" would say Python or PHP have for programming
utilities? I didn't mention Perl because all C programmers know it is a
write only language.
What is nice in C is that there isn't a "preconceived" ata type or
way of doing things.

That can be a bit of a double edged sword, can't it? Yes you have the
freedom, but a programmer unfamiliar with code has to learn both the
code and its idioms. One of Java's strengths was probably its homogeneity.
C++ has (besides other big drawbacks) OO as a fundamental paradigm.

OO amongst many. The only real drawback for libraries is linkage, but C
interoperability comes to the rescue there. For self contained
applications there aren't any real drawbacks. If you are familiar with
C++, you may as well use it.
Lisp has lists, Fortran has numeric applications in view, C# and java
compete for the business market, (both being OO centric).

C is nothing. That's the incredible freedom that it provides. It is
up to you to use it or misuse it.

It isn't nothing, it is at the heart of just about every operating
system. Even those apparently written in another language will sill
have C or assembly at the driver level.

C still dominates in drivers and kernels.
This is a C group. You will find here people that will be pressed to
tell you that C is not the best, that C++ is better (like Mr Richter
above, for example). Who cares?

C is a good language, with some problems that I have tried to
solve in my system.

Problems which have been addressed portably in other languages...
But this is also a question of personal philosophy. I like above all
simplicity, lack of unnecessary features, minimal surface but greatest
power. There was a book some centuries ago that put that in a single
sentence:

Small is beautiful.

Small language or small code? Not a lot can beat the the concise nature
of a few lines of Perl or Awk.
 
B

BartC

David T. Ashley said:
On Sun, 27 May 2012 12:32:50 -0700 (PDT), John Reye

Interpreted scripting languages (bash, Python, PHP, Tcl, Perl) are
very convenient.

But also much slower, otherwise no-one would be using languages such as C or
especially C++; they are hard work!
There is typically no compile phase, and the error
trapping is excellent so you can know immediately where the problem in
the source code is.

That's an implementation issue. There's no reason why a development
environment for C can't also be made fast with a transparent compilation
phase and with additional error checking.

Especially as typical scripts are small, and so would the corresponding C
program, once the necessary support libraries have been created and put into
a separate (not statically linked) library.

Interpretation can also be used, unless the task makes that impractical. But
if a scripting language would be feasible, then perhaps so would an
interpreted C (bearing in mind the scripting language would have a core
written in a low-level language that is not interpreted).
It wouldn't be convenient to write everything in C.

It would, however, be possible.

As soon as you write a C utility that accepts a series of instructions from
a command line, then you've almost created a new language anyway.
 
M

Malcolm McLean

בת×ריך ×™×•× ×©× ×™,28 במ××™ 2012 10:16:53 UTC+1, מ×ת Bart:
Interpretation can also be used, unless the task makes that impractical. But
if a scripting language would be feasible, then perhaps so would an
interpreted C (bearing in mind the scripting language would have a core
written in a low-level language that is not interpreted).
tcc (tiny C compiler) has an intepreted mode. If you just give your C script a shebang (#! /usr/bin/tcc in the first line) it can run as a Linux / Unix shell script.

However it hasn't caught on. The problem is probably the libraries. Just using stdlib, you have to write too much logic to do simple things like checkfilename extensions. Use soemthing other than stdlib and you can't be sureyour script will work everywhere.
 
Ad

Advertisements

I

Ian Collins

But also much slower, otherwise no-one would be using languages such as C or
especially C++; they are hard work!

Not all applications require speed. A significant number of OS
utilities spend most of their time waiting on I/O. The Solaris package
management utilities (written in Python) are one large example. The
kernel statistics display utility (written in Perl) is another.
That's an implementation issue. There's no reason why a development
environment for C can't also be made fast with a transparent compilation
phase and with additional error checking.

Especially as typical scripts are small, and so would the corresponding C
program, once the necessary support libraries have been created and put into
a separate (not statically linked) library.

As an interpreted language, C looses its main advantage - speed.
As soon as you write a C utility that accepts a series of instructions from
a command line, then you've almost created a new language anyway.

Or the interpreter for one.
 
S

Stefan Ram

jacob navia said:
It took the systems engineers of Sun Corp SIX MONTHS to find a memory
leak in their Java system. The problem is that the GC will not
forget that if you have a single bad reference to an object it will NOT
release it, making for a slowly accumulating memory leak.
If you think that horrible bugs happen only in C THINK AGAIN.

It is well possible that this GC /was/ written in C.

After all, you are not talking about Code written /using/ Java,
but code written to /implement/ Java.

Usually, it is much more easy to write code without memory
leaks in a GCd language.
 
S

Stefan Ram

Ian Collins said:
C still dominates in drivers and kernels.

»still dominates in drivers and kernels« when it has the
/overall/ rank as number 1 in several different evaluations,
like for example

http://www.tiobe.com/content/paperinfo/tpci/index.html

, with »+1.18%« since may 2011?

Some quotes:

»=head2 What language is Parrot written in?

C.

=head2 For the love of God, man, why?!?!?!?

Because it's the best we've got.«

http://www.davidcole.net/msie/notes/ipl/perl/jul13/parrot/parrot-0.0.4/docs/faq.pod

»Here's the thing: C is everywhere. Recently Tim Bray
made basically the same point; all the major operating
systems, all the high-level language runtimes, all the
databases, and all major productivity applications are
written in C.«

http://girtby.net/archives/2008/08/23/in-defence-of-c/

OTOH,

perl -p -i -e 's/a/b/g' *

will replace all occurrences of the regular expression »a«
with the pattern »b« in all of the files in the current
directory. Now show me that in C! There is not even a
portable way to read a directory in C.

When one does some »AI-style« programming with a graph where
multiple objects link to each other in a very dynamic way,
memory management can become hard, so this is also easier to
code in GC languages.

Expressions in functional languages often involve transfer of
ownership or sharing of ownership of run-time allocated objects
and can't really be written in C. Apart from some simple cases,
one cannot write in a pure functional style in C.

One can »emulate« OOP in C, but it sometimes needs some more
complicated wording. The need for manual memory management can
become distracting.

So, C is a »multi-paradigm« language only to some extend.
 
Ad

Advertisements


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

Top