Re: Looking for programming examples in any programming language
- From: Michael Mol <mikemol@xxxxxxxxx>
- Date: Thu, 27 Sep 2007 04:56:49 -0000
Sorry for the extremely late reply...I've been away from a computer
for most of the last week.
On Sep 19, 1:28 pm, rem6...@xxxxxxxxx (Robert Maas, see http://tinyurl.com/uh3t)
wrote:
I started something like that too, sticking strictly toFrom: Michael Mol <mike...@xxxxxxxxx>
applications that can be run on Web servers, using CGI or
equivalent method for submitting encoded form contents to
applications and getting back the next Web page with results and
next form to submit.
<http://www.rawbw.com/~rem/HelloPlus/hellos.html>
<http://www.rawbw.com/~rem/HelloPlus/CookBook/CookTop.html>
Cool. I added them to the list:
http://rosettacode.org/wiki/Help:Similar_Sites
Just a tiny suggestion: Since these are two stages within a single
effort, rather than two independent efforts, it might be better to
include them as a single <li> instead of two separate <li>s. I.e.
currently they display (in lynx, brackets added by me around links):
* [Beyond Hello World]
* [CookBook]
and it'd probably better to show as:
* [Beyond Hello World] including the [CookBook]
The proposed HTML would be (indented more than necessary here):
<li> <a href="http://www.rawbw.com/~rem/HelloPlus/hellos.html"
class="external text"
title="http://www.rawbw.com/~rem/HelloPlus/hellos.html"
rel="nofollow">Beyond Hello World</a> including the
<a href="http://www.rawbw.com/~rem/HelloPlus/CookBook/CookTop.html"
class="external text"
title="http://www.rawbw.com/~rem/HelloPlus/CookBook/CookTop.html"
rel="nofollow">CookBook</a>
</li>
Change made.
I've got Google Alerts set up to let me know when the site is mentioned,
Hmm, I'm curious how that works. I'm thinking of setting up my own
prioritized Web-based alert system and I wonder whether it'd be
possible to feed Google Alerts into my system.
<http://www.google.com/alerts>
Google Alerts are email updates of the latest relevant Google results
(web, news, etc.) based on your choice of query or topic.
Sigh, the only way to interface would be to poll my e-mail on a
regular basis to detect new e-mail from Google Alerts, and *then*
generate an alert via my system. Oh well, for this purpose polling
once or twice per day should be fast enough service. But I wonder,
if my Web site got very popular, how quickly the flood of Google
Alerts would fill up my 1gb Yahoo! Mail account.
Hmm, I did a Google search just now, and neither URL produced even
one match. Do you know how to search for a URL via Google?
As far as I know, you can't search by URL. Typing in a full URL
actually induces GoogleBot to index the site. Instead, I have an
alert set for the site name.
However, if you wanted to have alerts pumped into your system, you
might consider setting up a box running Sendmail that redirects emails
to a particular address into a shell script. But that's more a
question for another newsgroup.
Early on, I wanted to include something I'd seen on O'Reilly's
Books Online. When I had their Programming Perl book in my
bookshelf, there was an excellent in-page applet that allowed you
to test the code. I can't possibly think of a better way to help
someone understand the code they're learning about than to have it
in an in-page applet. However, I didn't think it was possible to
do that for such a broad range of languages.
Hmm, I thought Java was the only language supported for applets in
the standard Web browsers (Mozilla Firefox, MicroSoft Internet
Explorer, NetScape Navigator/Communicator). Do you know of a sample
applet using Perl that I could try? But note even Java applets
don't work in most places. When I took a course in distributed Java
at De Anza College, only one of the three Web browsers supported
Java applets in the lab, and none of them worked in the
instructor's office so I had to get the instructor to come into the
lab and specifically use the one working browser to demo my
homework assignment. Here in my current apartment complex, Java
applets don't work at all in either of the two browsers available
(Firefox and IE).
O'Reilly's site had a Java applet that interpreted and ran Perl code
through what looked like a simulated terminal.
I find it strange that Java doesn't work for you. It's a minor hassle
for me, as I run Ubuntu Linux, and needed to install Sun's (or IBM's )
Java runtime to get it to work. But I haven't had a Windows box give
me real Java headaches since Win95 OSR2.
Drop me an email and I'll see if I can help you through it.
You've got an excellent approach there, but I'd have to be
careful not to tax my shared hosting account in the case that
someone built bad code.
I have the same problem here (single user among several hundred on
a Unix shell account). I have to be almost paranoid to avoid "using
too many CPU cycles" in anything I write. So-far the admin hasn't
complained about any of my CGI applications, so I seem to have been
sufficiently cautious.
I was Slashdotted early on, and the results weren't pretty. (The
server at Dreamhost crashed twice under the strain, and had a peak
load average of over 160.) If I were to add in-browser code testing
ability, my site popularity would probably go way, way up again.
A virtualized solution might work, though.
Can you post a URL that describes this method?
Just something I thought of. Taking a common virtual machine (like
Java) and using it as a target for multiple languages, as well as as a
target for other virtual machines (like Parrot) that can already run a
large number of languages. I need not point out that a virtual
machine within a virtual machine would be terrifically wasteful;
However, PCs are continually growing faster, and increasingly complex
apps are already being targeted for virtual machines. (.NET, Java,
Flash...)
I wonder if the folks behind the Perl Parrot interpreter have
made enough progress that code could be compiled with Parrot as
its target.
I totally don't believe it'd be possible for Parrot to properly
implement the full semantics of various programming languages
(Common Lisp and Java for example; because of EVAL called from
runtime code, and explicit Class objects, respectively).
IMO You really need to run the code in an actual proper runtime for
the language being demonstrated.
There's nothing preventing such a runtime from being written in an
interpreted language. Again, that's likely to be slow. More
difficult, though, would be compilers that could run from within the
browser, and hand execution over to to the compiled code. However, if
someone actually wrote it, I'd use it. :-)
It's somewhat ironic that this would be somewhat easier for the
esoteric languages than the popular ones; The people who add and
update pages typically do it because they love their language, or
love the challenge. I expect that this becomes more true with
rare languages like E or Seed7. (The actual creater and maintainer
of the Seed7 language adds code to RC as, I suspect, a way to
advocate the language. (Though I invited him to...)
I find it sad that nobody has contributed any code for decoding
HTML form contents except in C and C++. My guess is that none of
those esoteric languages are even capable of accessing Unix shell
variables (to get QUERY_STRING for the GET method, or
CONTENT_LENGTH for the POST method).
Or maybe nobody likes my site, they only like your site,
so they refuse to contribute to mine, sob.
Those would be environment variables, which are supported under a
large number of languages. Certainly Java, Perl, PHP and Python, in
addition to C++. And, of course, any decent UNIX shell. E, which, as
I understand it, is built on top of Java, should be able to do it.
Like I said, the stuff on Rosetta Code is under the GNU FDL. Anyone
should be able to use it.
I don't know that I would want to involve functions in every code
example, but I like the idea of listing input and output
variables in the snippet header.
I agree. I only suggested output-callback functions in cases where
the primary output was not a value but a *decision*, a change of
flow. The callback would present some I/O-dependent way of "tracing"
the decision, such as printf("Yes decision"); or printf("No decision");
For cases where the result is a value rather than change of control
flow, of course the piece of code would simply assign a variable,
which is then passed to the I/O-dependent display, such as text in
Web page or text to stdio etc.
For example, the example of telling which number is larger is
actualy two separate actions:
- Comparing the two numbers, to produce a boolean result.
(For 3-way comparison < = > it's a 3-valued result or two booleans.)
- Using that/those boolean(s) to effect flow control to print
different messages in the 2 or 3 cases.
For a standalone complete demo, you seem to prefer conflating those
two operations, and in fact also conflating parsing input and
formatting output too, to make a self-contained demo that does all
of input->compare->controFlow->appropriateOutput. But like I said,
such a demo works only in one of several I/O environments (for
example stdio but not CGI nor GUI nor RDBS nor RMI nor RPC nor
..). If you're going to separate the specific I/O environment from
the innerds of the demo, then IMO you might as well go all the way
and separate the comparison from the flow-control. Any decent
programmer wishing to learn five new languages in a weekend already
understands how a complete program includes all/most elements of
input & calculation & comparison & flowControl & output, hence
would be more interested in "how do I compare two numbers in this
language" rather than "show me a complete program that does more
than I really want and doesn't even work from inside RMI and let me
figure out which tiny part is relevant to my actual needs".
Of course in addition to examples of how to do each single task
within a program, at some point the newbie needs to see a complete
program. For that purpose a simple Hello World plus decoding of
input (CGI or RDBS or stdio or RMI etc.) would suffice, just once
for each language/IO combination, not separately for each task
demo.
Summarizing: For each language/IO combination we need Hello plus
input decoding and output formatting. I've done that for CGI for
six languages and would like help extending that to other
languages.
Others would do likewise for stdio and GUI and RPC and RMI and SQL/RDBC etc.
Then for each language/primitiveTask combination we need examples
of the form:
- List/description of input variables given
- List/description of output variables to be computed
- Code that sets the output variables (usually just a single line of code)
For flow of control tasks, instead have:
- List/description of input variables
- List/description of callbacks to demonstrate which control path was followed
- Code that calls one of output callbacks (usually just a single line of code)
For specialized input-parsing tasks, instead we have:
- Description of input syntax
- List/description of input variables
- Code that sets the input variables
For specialized output-formatting tasks, instead we have:
- List/description of output variables
- Description of output syntax
- Code that generates the output syntax (usually just a single line of code)
I started a thread at our Village Pump to discuss it and potentially
organize efforts at changing the code snippets across the site.
Though I may have been a bit brief: http://villagepump.rosettacode.org/index.php?topic=3.0
If you like, go ahead and modify the CookBook link I added to
Rosetta Code. (See above for the URL.)
I'm a bit shy about modifying somebody else's Web site, except
where I see a clear mistake that I'm sure I can correct quickly,
and even then most of the time I'm too shy to correct the mistake
unless it's egregious.
So do it anonymously; Rosetta Code doesn't require people to log in
anymore. (Not since I added CAPTCHAs to ward off bots, anyway.) If
there's something wrong with your changes, someone else will be quick
to fix it, while keeping the spirit of the change.
Also I understand Wiki sites don't allow direct HTML editing, they
use special tokens to implicitly represent HREFs, and I'm not
expert at doing that right, usually trash it horribly whenever I
try to include my own links in my own new Wiki sections, hence
would not at all be comfortable modifying somebody else's Wiki links.
It's not that they don't allow it. The code (usually) remains intact,
and works like it normally would. Wiki-format code is preferred, as
it makes editing easier for the folks who don't know HTML. But if
someone uses plain HTML, it's no biggie. Someone else could easily go
in and change it to wiki code. If not, no harm done.
However, the format for an external link is fairly simple: [http://url
Text of the link] ... Everything after the URL becomes the text of the
link.
When I created Rosetta Code, I had a very narrow mental picture
of what I thought it would become. I created it as a wiki,
Which pretty much makes it infeasible to include any live demos on
your server, due to very likely chance of somebody deliberately
including malicious code.
If run on the server, this is very true. I'm still hopeful for a
client-side solution, though.
... Eventually, the site structure stabilized into the form it
has today. Most of the tasks assume that data being operated on is
already in the local scope. There is at least one task (User
Input) that addresses how to obtain the data from the user.
I'll have to take a more complete look through your site someday,
in particular to see whether input is indeed usually already in
local scope (and post a complaint whenever it isn't), and to see
how output is handled (whether you implicitly assume that stdio is
always available, which wouldn't be the case in a GUI or RMI
environment, and is always in plain text not HTML or XML format,
which wouldn't be the case in a CGI or SOAP environment), and to
see whether you clearly separate the main task from the
stdio-specific output printing, and to see whether your
input-parsing section deals *only* with plain stdio or includes
other environments such as CGI and GUI and SOAP etc.
There are discussion pages tacked on to all of the pages, and people
occasionally post such complaints, or go in and fix them. It works
out over time; The nice thing about a wiki system is that anyone can
come in and fix things up.
While I've long known that Rosetta Code's tasks need better
categorization, I've lacked the knowledge to be able to do that ...
If everything is broken down into fundamental pieces, keeping input
collection+parsing separated from calculations separated from tests
separated from control flow separated from output
formatting+presentation, it should in theory be relatively easy to
categorize the micro-tasks. But if several different micro-tasks
are conflated into a full demo application, categorizing may be
impossible to do with logical concistency.
For example, sorting an array, and outputting the resultant array,
are clearly in two clean categories, but a demo that includes doing
the two together, is that more computation or is that more
formatting output? What if sorting is two lines of code, or a
single call to a built-in library routine, but formatting output is
three lines of code or twenty lines of XML?
It feels like the difference between a demonstration problem and a
homework assignment. Since RC's focus has been towards demonstration,
more complicated tasks are probably best left off. Or thrown in a
"Challenge" category or some such.
Back to the problem with Wiki not supporting live demos: In my
Hello Plus site I've solicited people with access to unusual
languages to set up live demos on their own CGI site and provide me
with URLs for live demo itself and display of source code of live
demo, but so-far nobody has contributed even one such example. But
your site seems to be more popular, so maybe if you make a similar
solicitation there, using my site as examples of the kinds of
live-demos and show-source-scripts we'd like, somebody might set up
a demo+source for your site. Or not. Shot in dark, right?
I'll have to look into it.
.
- Follow-Ups:
- Re: Looking for programming examples in any programming language
- From: Robert Maas, see http://tinyurl.com/uh3t
- Re: Looking for programming examples in any programming language
- From: Robert Maas, see http://tinyurl.com/uh3t
- Re: Looking for programming examples in any programming language
- References:
- Looking for programming examples in any programming language
- From: Michael Mol
- Re: Looking for programming examples in any programming language
- From: Robert Maas, see http://tinyurl.com/uh3t
- Re: Looking for programming examples in any programming language
- From: Michael Mol
- Re: Looking for programming examples in any programming language
- From: Robert Maas, see http://tinyurl.com/uh3t
- Looking for programming examples in any programming language
- Prev by Date: Re: Mathematical models for loop calculations
- Next by Date: Unlock the drive
- Previous by thread: Re: Looking for programming examples in any programming language
- Next by thread: Re: Looking for programming examples in any programming language
- Index(es):
Relevant Pages
|