For performance, write it in C - Part 2, comparing C, Ruby and Java

M

M. Edward (Ed) Borasky

Chad said:
Why? Why not just remember that it's a separate language? I've
experienced a little negative transferrence of knowledge between Ruby
and Perl because of their similarities, but once I got past that minor
hurdle my growing knowledge in each language has only helped with my
ability to learn more about the other. If you aren't doing the same,
you're doing something wrong.
I learn for two reasons ... either because I need to or because I want
to. I needed to learn FORTRAN because management thought macro assembly
was unmaintainable. I needed to learn Perl, because my "awk" scripts had
become unmanageable and my boss said, "Perl's the best language for that
sort of thing now." Which it was. I *wanted* to learn Lisp, Forth, R,
and Ruby. I don't *want* to become a better Perl programmer. I just want
to be "good enough" at it.
Yeah, you can still run Java on a Mac. Of course, for the purposes you
describe, I suspect Smalltalk would have been a better choice for those
applications in most cases. Smalltalk is underrated and marginalized to
the point that almost nobody thinks of it when choosing a language for a
project, though, unfortunately.
Smalltalk is a member of my list of the half dozen pivotal programming
languages. The other five are macro assembler, Fortran, Lisp, APL and
Forth, Smalltalk was/is truly a marvelous environment. But when these
applications were designed, I don't think anyone was giving away a run
time/compiler/interperter/environment for Smalltalk.

I did try Squeak at one point. I found the GUI so counterintuitive after
years of Windows and Linux desktop usage that I gave up on it. After I
build a couple of projects in Ruby, I might go back to Squeak. Is there
another freely-available Smalltalk implementation?
 
P

pat eyler

etc., etc., etc.

could you guys please take this to private email. It's no longer about Ruby,
it's no longer interesting, it's no longer appropriate for this mailing list -
newsgroup - forum.
 
C

Chad Perrin

I learn for two reasons ... either because I need to or because I want
to. I needed to learn FORTRAN because management thought macro assembly
was unmaintainable. I needed to learn Perl, because my "awk" scripts had
become unmanageable and my boss said, "Perl's the best language for that
sort of thing now." Which it was. I *wanted* to learn Lisp, Forth, R,
and Ruby. I don't *want* to become a better Perl programmer. I just want
to be "good enough" at it.

What does that have to do with "unlearning" Perl?

Smalltalk is a member of my list of the half dozen pivotal programming
languages. The other five are macro assembler, Fortran, Lisp, APL and
Forth, Smalltalk was/is truly a marvelous environment. But when these
applications were designed, I don't think anyone was giving away a run
time/compiler/interperter/environment for Smalltalk.

I did try Squeak at one point. I found the GUI so counterintuitive after
years of Windows and Linux desktop usage that I gave up on it. After I
build a couple of projects in Ruby, I might go back to Squeak. Is there
another freely-available Smalltalk implementation?

I think there are a couple others. I haven't much looked into it beyond
Squeak, I'm afraid.
 
C

Charles Hoffman

I don't think I've ever needed lexical closures.

Oh no ohh no... I think Chad hit it pretty well on the head with "well
you don't *need* switch statements." There are plenty of things in
programming languages you don't *need*, but once you've gotten into
them, you find yourself missing them when you have to do without them.
The programming I get paid to do is largely in PHP and ActionScript 2.0
for Flash; once I got the hang of using anonymous functions in
ActionScript, which are (or at least try to be) lexical closures, I
found my life getting a lot easier. For writing very event-driven code,
such as responding to a GUI and responding to callbacks generated by
remoting, anonymous functions, (despite a strong orthodoxy in much of
the Flash community against their use) can be a great way to write
smaller, clearer code.

I submit to you that you use lexical closures all the time and don't
even know it. You mention below that you've written Java, and I presume
you've written other object-oriented stuff. Guess what? Objects are
full of closures. The methods of an object are closures on the object
itself. If they weren't, you wouldn't be able to access instance
variables from them. Unless they started making everything global, and
then you may as well write in Fortran IV.
A working programmer needs to know C, plus whatever languages are used
in his or her shop. Regardless of what the designers and communities for
those other languages intend(ed) them to be, they are in fact occupying
an economic niche. They are special-purpose languages by that definition.

I only kinda-sorta know C; the university I went to didn't use it as one
of its main teaching languages at the time (CS I and II were done in
Java, CS III in Ada 95, and I took a Programming Languages course that
used Scheme quite heavily). I picked up a little of C in an Operating
Systems course, just enough to do some programming assignments involving
POSIX threads in Linux. I've yet to have need of C in my paid work, but
should the occasion arise, I'll learn it then.

Enough languages these days have inherited so many characteristics from
C, and C itself is a nice small-enough language with excellent
literature on it, that I don't think it will be a major problem for any
reasonably experienced programmer to learn it when needed, and for the
same reason, I don't think anyone really *needs* to know C unless
they'll be working on certain kinds of projects such as a Linux kernel
module to drive some special device (the company I work at has a project
going on currently that includes just that, and also involves Java, PHP,
and ActionScript 3.0, and of course the usual amount of SQL).
In this sense, Ruby is on the edge of becoming a special-purpose
language as the engine underneath Rails.

So? C has already become something quite like a special-purpose
language as the engine underneath *nix. And why not? Writing Unix is
what C was pretty much invented for. This doesn't imply that you can't
do plenty of other things with it, nor that no one doesn't do other
things with it, but a large amount of C's usage today falls in a certain
niche. Probably the biggest part of C's importance is the influence it
has had on other languages and on programming in general. I think it
would be just fine if Ruby followed a similar trajectory.

--ch--
 
C

Chad Perrin

Oh no ohh no... I think Chad hit it pretty well on the head with "well
you don't *need* switch statements." There are plenty of things in
programming languages you don't *need*, but once you've gotten into
them, you find yourself missing them when you have to do without them.
The programming I get paid to do is largely in PHP and ActionScript 2.0
for Flash; once I got the hang of using anonymous functions in
ActionScript, which are (or at least try to be) lexical closures, I
found my life getting a lot easier. For writing very event-driven code,
such as responding to a GUI and responding to callbacks generated by
remoting, anonymous functions, (despite a strong orthodoxy in much of
the Flash community against their use) can be a great way to write
smaller, clearer code.

1. Sorry to hear you have to make your money primarily by writing PHP
and ActionScript.

2. That's a pretty silly orthodoxy.

3. I didn't know you could do anything like a closure in ActionScript.
Good to know. Thanks.

I submit to you that you use lexical closures all the time and don't
even know it. You mention below that you've written Java, and I presume
you've written other object-oriented stuff. Guess what? Objects are
full of closures. The methods of an object are closures on the object
itself. If they weren't, you wouldn't be able to access instance
variables from them. Unless they started making everything global, and
then you may as well write in Fortran IV.

I tend to subscribe to the Schemers' view, rather than the Java
programmers' view: objects are like big, fat, complex, inelegant
closures. This is one of the reasons that I tend to be put off slightly
by languages that don't support lexical closures -- I like having the
ability to write my code with closures rather than objects sometimes.

So? C has already become something quite like a special-purpose
language as the engine underneath *nix. And why not? Writing Unix is
what C was pretty much invented for. This doesn't imply that you can't
do plenty of other things with it, nor that no one doesn't do other
things with it, but a large amount of C's usage today falls in a certain
niche. Probably the biggest part of C's importance is the influence it
has had on other languages and on programming in general. I think it
would be just fine if Ruby followed a similar trajectory.

. . except that I think it would be a shame if Ruby's niche were so
narrow as to be focused entirely on Rails.

If C is for Unix, Perl is for system administration, and PHP is for
lightweight server-side web programming, while Ruby is for Rails, it
sounds to me like Ruby's going to go the way of the dinosaurs pretty
quickly while the other three will be around for some time to come.
Luckily, I don't believe that Ruby's major niche will be any more tied
to Rails than Perl's was to CGI programming: CGI was Perl's gateway
drug, and Rails is Ruby's. In neither case is that likely to be the
thing for which the language is used most in the long run, I think.

Ruby, I predict, will have a rich and varied life ahead of it, and Rails
will only be a small (if interesting) part of that.
 
C

Charles Hoffman

1. Sorry to hear you have to make your money primarily by writing PHP
and ActionScript.

Meh, it's a living. It's my first paying gig out of school, and anyway
I like the company more than I like the code ;) I'd like to try to
influence the company to consider Ruby more often. If any progress
happens in AMF4R (an open-source AMF remoting library for Ruby that
seems to have been at a standstill for a long time), that has a good
chance of happening.
2. That's a pretty silly orthodoxy.

I agree. I think the Flash world hasn't traditionally been populated
with really serious programmer-types until very recently.
3. I didn't know you could do anything like a closure in ActionScript.
Good to know. Thanks.

It's based on the same ECMAScript standard as JavaScript. Not that the
implementation is all that great -- the type system is pretty busted in
AS 2.0. Haven't worked in 3.0 yet, though.
 
P

Peter Hickman

Isaac said:
Perhaps you could post the 5x5 Java and C programs on your website then
folk like Charles O Nutter can satisfy themselves that the numbers are
not bogus.

I will put together some pages tonight to get all the source code up.
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top