Slashdot Mirror


Building a Programmer's Rosetta Stone

Did you ever run into the problem where you knew how to do something in one programming language, but really needed to do it in another? That's what Rosetta Code is all about. A variety of programming tasks are solved using as many languages as possible. You can examine existing tasks, or create your own.

49 of 215 comments (clear)

  1. Re:I don't know about firehosing it by Marxist+Hacker+42 · · Score: 2, Informative

    Posted to Technocrat.net- as I'm "semi-paid contributing editor" there, it hit the front page immediately of course.

    --
    SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
  2. No Fair! by Watson+Ladd · · Score: 4, Insightful

    A lot of the tasks assume imperative programing, e.x. assigning values to an array. This should be about algorithms that we can all implement, not code fragments that assume a particular style of programing.

    --
    Inventions have long since reached their limit, and I see no hope for further development.-- Frontinus, 1st cent. AD
    1. Re:No Fair! by Short+Circuit · · Score: 5, Informative

      I would be happy to see other types of programming represented in Rosetta Code. I only included what I already knew. Rosetta Code should be about many things I don't already know. Once the server's no longer slashdotted, stop by blog.rosettacode.org, and I'll make a point to bring up how to add your own programming tasks. (Really, you just have to add a template to the top of of the page. But there are some guidelines.)

    2. Re:No Fair! by frakir · · Score: 5, Funny

      I program in Malbolge, you insensitive clod!
      http://en.wikipedia.org/wiki/Malbolge_programming_ language

      I hope next windows ver will be coded in Malbolge and open source.

    3. Re:No Fair! by Dunbal · · Score: 2, Funny

      I hope next windows ver will be coded in Malbolge and open source.

            You mean it's not? ;)

      --
      Seven puppies were harmed during the making of this post.
    4. Re:No Fair! by nuzak · · Score: 2, Funny

      > I hope next windows ver will be coded in Malbolge and open source.

      If something's written in malbolge, I don't think it really matters if it's open source.

      --
      Done with slashdot, done with nerds, getting a life.
  3. Re:Here's better by Rosco+P.+Coltrane · · Score: 3, Interesting

    Oops, I broke the link. Here it is: polyglot programs

    --
    "A door is what a dog is perpetually on the wrong side of" - Ogden Nash
  4. It may prove useful. by Z00L00K · · Score: 3, Interesting
    But as a seasoned programmer I also know that some tasks can't be ported. A more efficient method is to actually resolve the problems at link time since most object files doesn't really care about which language you use. Some tasks are better off in one language than in another and porting the "problem" may prove a herculean task ending up as the major time-consumer for a project.

    Of course there are also cases when you will need to port the solution to a different language. This may be the cause when the project specifications requires a specific language like Ada.

    As with all programming; your mileage may vary.

    --
    If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    1. Re:It may prove useful. by arevos · · Score: 4, Insightful

      But as a seasoned programmer I also know that some tasks can't be ported. A more efficient method is to actually resolve the problems at link time since most object files doesn't really care about which language you use. If you look at the programming tasks the website attempts to translate, you'll notice that they are extremely basic and generic. I don't think the aim of the website is to translate some complex library into another language; rather to provide a learning resource where programmers can see how to map simple tasks from one language to another, which presumably will help them better understand a new language. Remember that the original Rosetta stone was used for a similar purpose.

      This site could be useful, but MediaWiki doesn't seem the best tool to use, and the content so far is rather sparse. I'm uncertain whether this will prove a success; it's an interesting concept, but many interesting concepts have fallen by the wayside.
    2. Re:It may prove useful. by arevos · · Score: 4, Insightful

      Just out of curiosity, why not? And what would you suggest instead? A Wiki is essentially just an editable website. It must be manually ordered; tables of contents put in, pages linked to other pages, and so forth. This is find for data that has a very general structure, such as an encyclopaedia or a manual of some kind. But the Rosetta Stone concept is highly structured, cross-referencing programming languages with programming problems, and it seems to me as if this cross-referencing would be better done automatically, rather than making several Wiki pages and maintaining them manually. The site concept would be better suited to some sort of customised CMS, or perhaps something designed from scratch.
    3. Re:It may prove useful. by Raffaello · · Score: 2, Insightful

      Only if you're allowed to write an interpreter or compiler for the more powerful language in the less powerful one.

      This is what has been called the "Turing Tarpit." In a formal logical sense, all turing complete languages are equivalently powerful. But that means that punching holes in a paper tape by hand is technically as powerful as a high level language. We have high level languages so that we don't have to twiddle ones and zeroes.

      High level languages themselves differer in expressiveness. They can all accomplish the same tasks, but some languages make certain tasks a whole lot easier. For some language pairs, the only way to easily accomplish certain tasks in the less powerful language is to write what amounts to "an ad-hoc, informally-specified bug-ridden slow implementation of half of " the more powerful language.

      As a consequence, there is no "basic" or "generic" list of programming tasks. Tasks that one has become accustomed to do in many languages are a non-issue in some other languages. "Design Patterns" in some languages don't exist in certain others because the language itself makes them unnecessary (see Google's director of search quality, and AI expert Peter Norvig's treatment of the subject especially this slide)

      A site like Rosetta Code could only be useful for languages that are so similar that they essentially differ mostly in surface syntax. For languages much different than this their whole paradigms are different, and many of the tasks themselves are no longer the same.

    4. Re:It may prove useful. by Short+Circuit · · Score: 2, Informative

      Just out of curiosity, why not? And what would you suggest instead? A Wiki is essentially just an editable website. It must be manually ordered; tables of contents put in, pages linked to other pages, and so forth. I make use of as many MediaWiki features as I know how. There's one template for programming languages, one for compilers, one for interpreters, one for programming tasks, etc. Adding the template to a new page automatically adds the page to the related category, and the category index pages are the primary tool for browsing the site.

      In short, our Tables of Contents are automatically updated for us by the wiki engine. It's cool.

      This is find for data that has a very general structure, such as an encyclopaedia or a manual of some kind. But the Rosetta Stone concept is highly structured, cross-referencing programming languages with programming problems, and it seems to me as if this cross-referencing would be better done automatically, rather than making several Wiki pages and maintaining them manually. The site concept would be better suited to some sort of customised CMS, or perhaps something designed from scratch. The benefit of using a wiki, and why I chose to use it, is that in each of these intermediary pages, one can place descriptive information about the relationship. The net effect is that an encyclopedia forms around the structured data. This has only happened in a couple places, such as the page about LAMP, and the page about GCC, but it's something I want to see continue.

  5. Usage by mgiuca · · Score: 5, Insightful

    I'm not sure the right idea is to "know how to do something" in a particular language. If programmers are encouraged to learn algorithms specific to a particular language, how will they ever adapt once their pet language sinks? (By using an algorithm repository to re-learn rote code?)

    At any rate, I think this site has already encountered a problem which is only going to escalate as it grows: code isn't cross-indexed properly at all. For example, there are many "programming tasks" with solutions in C, but there is nothing on the C page. I think this problem stems from the fact they used MediaWiki.

    MediaWiki's great for something like... well, Wikipedia. But it doesn't support a cross-referenced database like this. The wiki concept is good for this site, but the server needs to be running some software designed better to the task.

    1. Re:Usage by Short+Circuit · · Score: 3, Informative

      I'm not sure the right idea is to "know how to do something" in a particular language. If programmers are encouraged to learn algorithms specific to a particular language, how will they ever adapt once their pet language sinks? (By using an algorithm repository to re-learn rote code?) Rosetta Code was largely inspired by a page on Wikipedia where the classic "Hello World" example was shown in a few hundred languages.

      Rosetta Code takes the concept behind Hello World, and spreads it to other tasks.

      At any rate, I think this site has already encountered a problem which is only going to escalate as it grows: code isn't cross-indexed properly at all. For example, there are many "programming tasks" with solutions in C, but there is nothing on the C page. I think this problem stems from the fact they used MediaWiki. Actually, this is (almost) intentional. I want people to be able to learn about the languages they're using. I've been filling in the pages as I've had the opportunity. (I'm a full time college student, and president of a student organization.) Check the page on GCC, for example.

      MediaWiki's great for something like... well, Wikipedia. But it doesn't support a cross-referenced database like this. The wiki concept is good for this site, but the server needs to be running some software designed better to the task. I'm open to suggestions. (And assistance, if it'll go that far.)
    2. Re:Usage by cp.tar · · Score: 3, Insightful
      I'm not sure the right idea is to "know how to do something" in a particular language. If programmers are encouraged to learn algorithms specific to a particular language, how will they ever adapt once their pet language sinks? (By using an algorithm repository to re-learn rote code?)

      But this kind of thing should be very good for someone learning a new language - you know how to do it in one language, now you're looking it up in another one... like learning the most common phrases first when learning a natural language.

      I hope this project will amount to something; it can be really useful.

      --
      Ignore this signature. By order.
  6. if you like this... by taybin · · Score: 3, Informative
    1. Re:if you like this... by mgiuca · · Score: 2, Informative

      Another great one: HanoiMania. 111 solutions to the "Tower of Hanoi" recursive problem, some in very creative and bizarre environments (as outlined in the summary at the top).

    2. Re:if you like this... by Coryoth · · Score: 3, Informative

      Also worth looking into is LiteratePrograms which provides a wide range of algorithms written (and documented - hence the "literate" part) in a wide variety of languages. Currently there are over 50 different "Hello World" programs in different languages, including such things as AliceML, AspectJ, Haskell, and Oz, as well as all the usual suspects. More to the point, it also includes a decent variety of more interesting algorithms, including basic sorting algorithms (quick sort, merge sort etc.) in a wide variety of languages, right the way up to a basic GUI file manager in GTK. It's a Wiki, and still growing, but it seems to be well ahead of RosettaCode at the moment.

    3. Re:if you like this... by Dan+East · · Score: 2, Interesting

      As far as actual usefulness goes, the 99 Bottles of Beer site is worthless. The C version implements a Linux Kernel Driver! Now what's the point in that? Why not output to stdio? The C++ version doesn't even use OOP or implement a single class! It uses recursive templates and thus doesn't contain a single piece of runtime logic.

      However the real nail in the coffin is that the fundamental algorithm used to generate the song varies widely from one language to another, thus no real comparison between languages is possible.

      Dan East

      --
      Better known as 318230.
  7. One task that isn't on there by antifoidulus · · Score: 4, Funny

    "How to bring a hooker back to life" Damn, I really neede....I mean, was interested in how you would do it in Perl, for curiosity's sake....

    1. Re:One task that isn't on there by Anonymous Coward · · Score: 3, Funny

      use Hooker::Transactional;

      Hooker::Transactional->get_last->rollback;

      Dude, CPAN has EVERYTHING! :)

    2. Re:One task that isn't on there by patio11 · · Score: 2, Funny

      >>
      I mean, was interested in how you would do it in Perl, for curiosity's sake....
      >>

      There's more than one way to do it.

  8. Should I be impressed? by Fulkkari · · Score: 4, Insightful

    The site has absolutely no real content. There are only a couple of pages on the whole site. The most advanced thing found there is something along the lines of how to open a file with mIRC scripting (no C/C++/Java) and that bash scripts (usually) start with #!/bin/bash. Oh, please. Should I be impressed?

    --
    I demand the Cone of Silence!
    1. Re:Should I be impressed? by LiquidCoooled · · Score: 3, Insightful

      It got to the frontpage because its an interesting idea.
      The firehose will help with things like this.

      I agree it was empty and its implimentation feels flawed, but it gives a baseline for thoughts other people may be having.
      I know *I* have been thinking about this since I saw it and how it should/could be once filled.

      It gets a thumbs up from me.

      --
      liqbase :: faster than paper
  9. Been Done by WED+Fan · · Score: 3, Informative

    It's already been done. Planet Source Code does this already, and it's been around for ages. You can find code examples and complete projects.

    Then for projects in the .NET set there are a number of online translators that do C#VB.NET. Very good for moving code between different types of projects.

    Now, something that would be truely useful would be a service that would do translations from a wider variety languages.

    --
    Politics is the art of looking for trouble, finding it everywhere, diagnosing it incorrectly and applying the wrong fix.
    1. Re:Been Done by Inferger · · Score: 2, Informative

      It's been done before in another program called XTRAN too.

    2. Re:Been Done by Zontar+The+Mindless · · Score: 3, Informative

      Planet Source Code is not that hot. There's heaps of trivial examples that just aren't done very well - like a "new" PHP4-style class for connecting to MySQL which hard-codes "localhost" for the server name. I guess the guy hasn't heard of mysqli?

      The quality of the writing itself is pretty bad, too. People who are purporting to teach you something ought to be a bit more... well... literate.

      Neither am I inclined to be overly impressed when a site throws 175+ JavaScript and CSS errors in Firefox in just the first 2-3 pages. (I didn't bother counting the errors after that point.)

      --
      Il n'y a pas de Planet B.
  10. Will they support these programming styles ?!? by ctrl-alt-canc · · Score: 3, Funny
  11. Re:Erm... by lexarius · · Score: 2, Informative

    Apple, which currently has a product called Rosetta, which allows PPC code to be executed on Intel chips by translating it dynamically or something.

  12. Re:minus 4, T8oll) by Short+Circuit · · Score: 2, Informative

    I had to get it started. My hope is that other people will contribute with languages (and tasks) that they know.

  13. New? by d34d.10n · · Score: 2, Interesting

    Although the idea seems nice, it still has a long way to go. The site currently only contains a few mIRC and bash scripts.

    Anyway, I'm looking forward to when it's filled with code from different languages.

    PS: an applet or an IDE plug-in like those from Koders would be really cool.

  14. Pointless, don't bother! by Anonymous Coward · · Score: 3, Informative

    Did you even bother looking at the site first? Perhaps not as it's slashdotted. The idea isn't bad, but it's just a nearly empty wiki. Not many languages, and looking at some tasks, most of the stuff wasn't very useful. For example, I looked at the file I/O task, and there were no versions for C, C++, Java, C#, VB (not that I'd want that), PHP (idem) nor anything like that - but there was a mIRC scripting version...

    Might be worth posting somewhere once there's actual useful content, but just not now.

    But then again, I'm sure the editors didn't even look at it either before posting. There's nothing news worthy or interesting there - yet.

    1. Re:Pointless, don't bother! by JoshJ · · Score: 5, Insightful

      Right now it may be "pointless" for someone looking at it. It is certainly not "pointless" for contributing to it. Posting it to /. , technocrat, and similar means that it will get exposed to a lot of potential contributors.

    2. Re:Pointless, don't bother! by Zadaz · · Score: 2, Insightful

      Then add something.

      Whoops, my fault. Being a hater is easier.

    3. Re:Pointless, don't bother! by Marxist+Hacker+42 · · Score: 2, Insightful

      It must have hit the front page.

      The whole idea of a wiki is for the community to build the content. The Rosetta Code is rather new, of course it's not complete. But it's a damned good idea, and deserves wider advertising so that the wiki will be filled!

      However, having said that, I agree, which is why I wasn't sure about firehosing this journal entry just yet. Better to let the professional FOSS experts at Technocrat have a crack at it first.

      --
      SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
    4. Re:Pointless, don't bother! by Reverend528 · · Score: 2, Funny
      I looked at the file I/O task, and there were no versions for ... Java

      Well, that would be pushing the limits of the MySQL LARGETEXT field.

  15. In a more focused form by aero6dof · · Score: 3, Informative

    Sourceforge has hosted to Programming Language Examples Alike Cookbook project for a while now. It does something similar, filling out "Perl Cookbook" recipes for a fairly wide range of languages...

    http://pleac.sourceforge.net/

  16. Re:Right tool for the job by Frumious+Wombat · · Score: 4, Interesting

    Years ago my copy of Kruse's "Data Structures" came with examples of how to do all the then-hip dynamic data structures (linked lists, trees, etc) in languages without pointers. This became useful when writing high-level Fortran-77 programs, as it allowed moving beyond Gomputed Goto and Arithmetic If for algorithms. In the same vein "Numerical Algorithms" (Teukolsky, Vettering, et al.) showed how to get decent array performance and add various oversights (such as complex numbers and complex arithmetic) to C-type languages.

    >>>I see this ending up as an effort to shoehorn concepts unique to one language to another language (building web sites in COBOL *shiver*).

    I once saw a series of cgi-bin routines written in Fortran-77 because that's what the web-site designer knew, and the schedule was too tight for her to learn Perl in time. (for those of you who started programming after compiled languages gave way to Python/Perl/Ruby/WombatCode6000, get a copy of G77, and try to compare two strings of different lengths) It's no big deal; given enough time one Turing-complete language can accomplish the same work as any other Turing-complete language. It's just the degree of pain you're willing to endure that's the limiting factor.

    As for the F77/cgi-bin programmer, She's a full professor now (though not in Comp. Sci, alas),

    --
    the more accurate the calculations became, the more the concepts tended to vanish into thin air. R. S. Mulliken
  17. LiteratePrograms by Chris+Rathman · · Score: 2, Interesting

    One project that deserves a look here is the LiteratePrograms project. The goals are somewhat different from Rosetta, with more emphasis on teaching of algorithms and the ability to run code directly from the wiki.

    As one who has worked on a couple of multi-language problem sets (SICP in other programming languages and OO Shapes), I can appreciate the amount of work it takes. We can always use more sites that teach programming in various unique fashions.

  18. Re:Right tool for the job by Short+Circuit · · Score: 2, Interesting

    I wouldn't expect all tasks to be solved in all languages. For example, I wouldn't expect someone to solve the File I/O task in UDB DB2.

    I would expect to see an eventual segregation between things like database tasks and web development tasks. I simply haven't known enough about programming to collect the requisite data myself.

  19. Re:Simple Tasks - Not Progamming Wars by seebs · · Score: 2, Funny

    I can beat that. The language Greet has the specification that an empty input file (or indeed, any other) is a program directing the language to print "Hello, world!"

    In fact, K&R presents a complete Greet interpreter very early on.

    --
    My blog: http://www.seebs.net/log/ --- My iPhone/iPad app: http://www.seebs.net/seebsfrac/
  20. But... by Brandybuck · · Score: 2, Insightful

    But all Real Programmers know all languages! At least that's what Slashdot keeps telling me...

    AC: Stupid article, the guy could have used Haskell and solved his problems
    BB: But maybe he didn't know Haskell?
    AC: Then he deserves get fired!

    --
    Don't blame me, I didn't vote for either of them!
    1. Re:But... by arevos · · Score: 2, Insightful

      An old saying: "Jack of all trades, master of none."

      This is true for programming as well. You can aquire a deep understanding of a few languages, or basic survival skills in dozens. Aquiring a deep understanding in dozens of languages is a truly exceptional feat. I agree that it's difficult to acquire a deep understanding of most languages. One can study Java and all its related libraries and frameworks for years and still not learn it all. Indeed, my last job was as a Java programmer, and whilst I'm pretty familiar with several web frameworks, libraries and GUI toolkits, I have little knowledge about, say, the SecurityManager class, or J2ME, or JMS.

      But on the other hand, I disagree that a deep understanding of a single language is more useful than a working knowledge of a dozen (as you seem to imply). A good programmer needs to know the limitations of the environment that he or she is working in, and the only way to do this is via comparison. Furthermore, learning different languages exposes you to different ways of thinking about a problem; if you don't learn a good spread of languages, your perspective is severely limited, and this naturally affects your ability to solve problems efficiently. To use a metaphor, I believe stepping back and seeing the whole wood is more important than gaining detailed information about a single tree.

      Finally, I'm not sure I'd say that the only alternative to a deep understanding is "basic survival skills". Perhaps instead:

      You can aquire a deep understanding of a few languages, or a good working knowledge in dozens.
  21. Re:I don't know about firehosing it by Dunbal · · Score: 2, Interesting

    "In the 1980s capitalism triumphed over communism, In the 1990s it triumphed over democracy."

          And in the 2000's, it's well on the way to triumphing over common sense... with apologies to the author.

    --
    Seven puppies were harmed during the making of this post.
  22. Re:Nice idea, but by multipartmixed · · Score: 2, Informative
    Your thinking around loops actually shows (to me, anyhow) why these Rosetta-stone-type projects are actually counter-productive in the long run. (I can also argue that using cross-language keywords is also poisonous).

    Why?

    Your C-language for-loop example uses the same crappy example as nearly every crappy text of the "learn C in 7 days [assuming you already know BASIC)" genre. Giving the first example this way --- as "a for-loop is something that counts, here's how you make it count" is ... so... bogus. And serves to completely POISON programmers' minds. I can't BEGIN to count how many programmers I've met who are confused about basic for-loops in C because they think they have to count.

    A for loop in C is simply the exact, beautiful, expression of the iteration concept:

    for (LOOP_INITIALIZER; LOOP_INVARIANT; PROPELLER)
    {
      EXPRESSION;
    }
    See? Has nothing to do with numbers.

    You're saying: execute LOOP_INITIALIZER, evaluate LOOP_INVARIANT, if it's true, perform EXPERSSION, evaluate PROPELLER and go back to the part of this sentence where we evaluated LOOP_INVARIANT.

    Because of this craputidinous teaching, I am constantly faced with programmers who cannot understand a loops of these types:

    for (a = arr; *a; a++)
      do_shit();
     
    or
     
    for (a = db_get_stuff(); a; a = db_get_more_stuff())
      do_shit();
     
    or even
     
    for (a = fgets(file, line, sizeof(line); a && !ferror(file); a = fgets(file, line, sizeof(line))
      do_shit();
    ...and these people have freakin' degrees in computer science. That final (contrived) example, BTW, is a fine way to avoid doing stupid shit like

    do
    {
      a = fgets(file, line, sizeof(line);
      if (a)
      do_shit();
    } while(a && !ferror(file));
    .... So: Why is the for-loop superior in every way to this while loop example?

    Look carefully.

    Loop control in the for statement is on the same line of code as the loop-construct keyword. In the above while-statement, loop control is at the beginning, middle, and end of the block. That's just BEGGING for a maintainer error. Yet 99 out of 100 C programmers prefer the second form... because it looks more like BASIC... they don't understand the beauty of the for-loop... they simply think ("Oh, I don't have any numbers to count, so I'd better use a while-loop"). That's CRAP! It's broken thinking, and it encourages buggy programs.

    It all comes down to people teaching to the lowest common example [denominator], rather than actually exploring the concepts behind the language.
    --

    Do daemons dream of electric sleep()?
  23. While you wait by CCFreak2K · · Score: 2, Informative

    for the site to come back, you can use this.

    --
    "Beware of he who would deny you access to information, for in his heart he dreams himself your master."
    1. Re:While you wait by Short+Circuit · · Score: 2, Funny

      That's actually the page that inspired the site.

  24. Akima's infamous spline? by the_greywolf · · Score: 2, Interesting

    That's one thing I want to see rewritten in several different languages.

    Just so I can make sense of the damn thing and I won't look at my call to ITPLBV() and wonder, "What the fuck does THAT do?"

    --
    grey wolf
    LET FORTRAN DIE!
  25. PLEAC by meiao · · Score: 2, Informative

    There is the PLEAC (Programming Language Examples Alike Cookbook) which uses (or should use) the same examples for many programming languages.

    Many languages are close to complete the provided examples.