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

J

James Kuyper

how does that do on a small screen (eg. Blackberry)?

Unlike Google, it's not a web-based news reader, and I didn't notice any
mention of mobile phone apps under their website
<http://www.mozilla.org/en-US/thunderbird>, so the answer appears to be
"not at all". Check the appropriate Blackberry location for "usenet news
reader". Android Apps lists 4, but I remember looking at them and not
being happy with any of them. I seem to recall that what turned me off
was that they all required signing up with a specific news server that
is not free, but my memory's not that reliable on such things.
 
G

Guest

Unlike Google, it's not a web-based news reader, and I didn't notice any
mention of mobile phone apps under their website
<http://www.mozilla.org/en-US/thunderbird>, so the answer appears to be
"not at all". Check the appropriate Blackberry location for "usenet news
reader". Android Apps lists 4, but I remember looking at them and not
being happy with any of them. I seem to recall that what turned me off
was that they all required signing up with a specific news server that
is not free, but my memory's not that reliable on such things.

thanks. I'd looked before without much luck
 
J

John Bode

Hi,

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

That strongly depends on the application domain.
It's close to hardware. It's perfect for operating system interfacing.

"Close to the hardware" doesn't mean what most people think it means.

Per dmr (http://cm.bell-labs.com/who/dmr/chist.html): "[BCPL, B, and C] are`close to the machine' in that the abstractions they introduce are readilygrounded in the concrete data types and operations supplied by conventional computers, and they rely on library routines for input-output and other interactions with an operating system."

And it's perfect for interfacing with *nix OSes. It was a little less perfect for VMS. It was a lot less perfect for MPE.
You can do anything with it.

For sufficiently loose definitions of "anything". Try to directly examine the contents of a register sometime.
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.

Writing Perl always makes me itch, but there are some text processing taskswhere it is *far and away* the better choice than C, to the point where choosing to do those tasks in C over Perl would indicate some level of brain damage.
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.

Yup. There are tasks for which the Python or Perl code is trivial, but theC code is much more involved.
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?)

GUI programming in C is a massive pain in the ass, full stop. Even with a *good* GUI framework. I would not develop a graphical desktop client in C unless you were willing to pay me at least triple my current salary. It's just way more heartburn than it's worth.
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?

Is it feasible to build a house with nothing but a hand saw and a claw hammer? Yes.

Would you *want* to?

Yeah, you could do everything in C. Most tasks will take you a lot more time to accomplish than using the scripting languages. You run a greater risk of making mistakes. And within six months, you'll wind up replicating the functionality of the bash or Perl interpreters just to keep from going insane.

Ad-hoc scripting is a fact of life; I need to reclaim some disk space, I can toss off something like

% find / -name "core" -mtime 30 -delete

in less than 10 seconds off the top of my head.

Sure, I could write a C program to do that for me. I could even write a C program that takes a file name pattern as an argument. And a time window argument. And I won't have anything that works any better or is any more flexible than the tool *that's already there*.
What languages do you use, and how do you decide what to use?
And how does C fit into the picture?
Thanks.

Typically, it's not my choice. Someone else makes the decision, rightly orwrongly.

I haven't written C professionally since 2004 or so; since then it's eitherbeen C++ or Java. When I'm noodling around at home it's usually C just because that's what I'm most familiar with. I'll play around with Lisp and Haskell just to see how the other half lives, and if I want to play around with something graphical I'll use Java. I'll do some prototypes in C++ to help me figure out a problem at work.

No serious craftsman artificially limits his toolbox; no carpenter is goingto decide that all he really needs is a claw hammer, no plumber is going to try to do everything with a pipe wrench, and no programmer should try to do everything in one programming language. Use the tool that's right for the job. If that tool is C, great. If not, equally great. You get an opportunity to stretch a bit.
 
F

Fred K

Hi,

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

That strongly depends on the application domain.
It's close to hardware. It's perfect for operating system interfacing.

"Close to the hardware" doesn't mean what most people think it means.

Per dmr (http://cm.bell-labs.com/who/dmr/chist.html): "[BCPL, B, and C] are `close to the machine' in that the abstractions they introduce are readily grounded in the concrete data types and operations supplied by conventional computers, and they rely on library routines for input-output and otherinteractions with an operating system."

And it's perfect for interfacing with *nix OSes. It was a little less perfect for VMS. It was a lot less perfect for MPE.
You can do anything with it.

For sufficiently loose definitions of "anything". Try to directly examine the contents of a register sometime.
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.

Writing Perl always makes me itch, but there are some text processing tasks where it is *far and away* the better choice than C, to the point where choosing to do those tasks in C over Perl would indicate some level of brain damage.
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.

Yup. There are tasks for which the Python or Perl code is trivial, but the C code is much more involved.
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?)

GUI programming in C is a massive pain in the ass, full stop. Even with a *good* GUI framework. I would not develop a graphical desktop client in C unless you were willing to pay me at least triple my current salary. It's just way more heartburn than it's worth.

Well, I've never had a problem with Motif (and it's not difficult to get Motif to work in a Windows environment).

I find it quite a bit easier than using Swing. So I am just the opposite ofyou - I would not develop a graphical client in Java unless you were willing to pay me at least triple my current salary. Especially if the target platform is Unix or Linux.
 
8

88888 Dihedral

(e-mail address removed)æ–¼ 2012å¹´5月28日星期一UTC+8下åˆ9時10分15秒寫é“:
I was not talking about using C to /implement/ a pure
functional language (PFL), but about using C to write in a
pure functional manner in C itself (i.e., using C as a PFL).


In »print(eval(input()))«, eval() is supposed to return a
meaningful value, which in a PFL has to have the type of the
image of the function »eval«. In all but the most simple
cases, such a value is a dynamically allocated graph.

not all functional languages are dynamically typed
When we write this in C: How should »eval« behave, when
a called »malloc« returns 0? The usual good practice in C
is to report such a failure to the caller. But the return
value of »eval« already has another meaning.

Moreover, when should the graph allocated by »eval« be
deallocated again? In »print«? But what should one then
call the next time one wants to print a value /not/
deallocating it?

So the need to check allocation attempts and to manage
dynamic memory in C makes such wording as
»print(eval(input()))« difficult in C.

Also, in C, blocks are not functions, so one lacks
function literals (anonymous functions) in C and
one also lacks lazy evaluation of arguments (see below).
One can »emulate« OOP in C, but it sometimes needs some more
complicated wording.
encapsulation, easy. polymorphism is a bit harder. You can do
some nasty things with structs but I'm not sure it's worth
it. Could you do some sort of Duck Typing?

You can do everything you can imagine, but when using it
in C itself, the wording might be more complicated. In a
pure object-oriented language (POOL), even blocks are
objects, so, in Smalltalk, one can implement a custom if
statement with a custom boolean type that can be used as

a > 0 ifTrue: [a := 0]

. This will set »a := 0« if a > 0. In C, one cannot write

( greater( a, 0 )->ifTrue )({ a = 0; })

In C, for an in integer of 32 bit,


a= (a>>31)&a; // if nagative 0xffffff, else 0


// this is just Boolean algebra
 
B

Ben Bacarisse

88888 Dihedral said:
In C, for an in integer of 32 bit,

a= (a>>31)&a; // if nagative 0xffffff, else 0

If a is negative the result of the shift is implementation defined.
// this is just Boolean algebra

It's more than that.

<snip>
 
M

Malcolm McLean

בת×ריך ×™×•× ×—×ž×™×©×™, 14 ביוני 2012 21:43:45 UTC+1, מ×ת John Bode:
On Sunday, May 27, 2012 2:32:50 PM UTC-5, John Reye wrote:

No serious craftsman artificially limits his toolbox; no carpenter is going to decide that all he really needs is a claw hammer, no plumber is goingto try to do everything with a pipe wrench, and no programmer should try to do everything in one programming language. Use the tool that's right forthe job. If that tool is C, great. If not, equally great. You get an opportunity to stretch a bit.

That's where the metaphor breaks down.
A plank of wood cut with a handsaw doesn't differ in any material respect from
one cut with an electric saw. A carpenter will have hand saws for small jobs
where it's not worth setting up an electrical current, and electric saws for
largescale sawing.
A better example would be artificially restricting nuts and bolts to be whole
multiples of 1/64 inch. Or having set heights for kitchen worktops.
 
P

Paul J Gans

If a is negative the result of the shift is implementation defined.
It's more than that.

It is an ancient trick going back to the days when using a
conditional jump cost many many cycles. This gave you the
result without one.

And of course it is hardware dependent. I first saw it used
on a CDC 6600 back in the day...

I wonder if somebody has tried to patent it.
 
J

John Bode

On Thursday, June 14, 2012 1:43:45 PM UTC-7, John Bode wrote:
[snip]
GUI programming in C is a massive pain in the ass, full stop. Even with a *good* GUI framework. I would not develop a graphical desktop client in C unless you were willing to pay me at least triple my current salary. It's just way more heartburn than it's worth.

Well, I've never had a problem with Motif (and it's not difficult to get Motif to work in a Windows environment).

I find it quite a bit easier than using Swing. So I am just the opposite of you - I would not develop a graphical client in Java unless you were willing to pay me at least triple my current salary. Especially if the target platform is Unix or Linux.

Heh. We *are* almost polar opposites; I got into Swing when building a test harness for some geospatial code I was working on a couple of years ago, and I found it relatively straightforward (nothing like elegant or pretty, but straightforward). Womped up some screens to display both graphical andtabular data from the same models. Didn't take that long (about a week toget the initial version up) and it was stupidly easy to extend. God knowsif I was following best practices or not, though.

I will freely admit I'm an outlier in this regard; nobody else I know findsSwing straightforward. Whoever designed it must suffer from the same sortof brain damage I do.
 
G

Guest

On Monday, June 18, 2012 5:52:07 PM UTC+1, Aaron W. Hsu wrote:

-- [...]
Programming is just another word for the lost art of thinking.

Nice. Is that original or are you quoting someone? I think every reasonably intelligent child should be taught to program.
 
R

Robert Miles

That sounds near impossible, in whatever language. Assuming you aren't
talking about a foo() merely returning a different floating point
result, but one that may or may not include floating point operations,
and if it does, then to alter the nature of all floating point
operations executed while in the lexical scope of foo()'s replacement.

Why not write a foo() wrapper, which calls foo(), then checks if it
returned a nan, and if so, change the result to a very high value?
 
B

Ben Bacarisse

Robert Miles said:
Why not write a foo() wrapper, which calls foo(), then checks if it
returned a nan, and if so, change the result to a very high value?

The problem is the words "on divide by zero". That suggests that NaNs
created by other operations should be left as NaNs.

It's probable that Malcolm McLean did not mean NaN but Inf, since divide
by zero most commonly produces Inf (or -Inf) in IEEE arithmetic. A
divide by zero only results in NaN when the numerator is also zero, but
that does not, I think, change the basic point being made.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top