New project, "Code to Code"

Marc Lanctot lanctot-yfeSBMgouQgsA/PxXw9srA at public.gmane.org
Wed Dec 17 20:05:21 UTC 2008


Madison Kelly wrote:

> First and formost, I want to standardize on actual article being called 
> 'Foo to Bar', then within it I would like to have all functions in their 
> own section that can be linked to individually.
> 
> With that structure in place, It would be relatively easy to create an 
> interface that does just what you want. I agree though, my current UI is 
> terribly simple, but I meant it to be a framework that can be expanded 
> on more than a final product. :)
>> For example, suppose I want to find out how to implement a method 
>> override in a subclass via inheritance in C++, I know Python, and I 
>> know Java. It doesn't matter to me what my source language is as long 
>> as it exists for one of those two, so I can easily choose the source 
>> language without wading through all the other "source language" pages 
>> looking for the concept.
> 
> So something like a searchable index? IE:
> 
> "Show me source languages showing how to use function X in language A"?
> 
> This would be great, any suggestions on how to implement that in a wiki? 
> The closest thing I can think of is the "What links here?" special page 
> for the section talking about the function.

No this is not what I meant.

Maybe it's easiest to illustrate with an example. I have lots of 
experience with language X and Y, but now because I work for company C I 
have to use language Z. (bummer!)

So, I coding along happily (or unhappily, as it were) in language Z and 
I find myself not knowing how to pass variables by reference.

Step 1: I invoke Code-to-Code. First thing I do is lookup "passing 
variables by reference in function calls". I find it, I'm happy. I get 
sent to a page (this concept's profile) called "Passing variables by 
reference to functions". I also see a list of source/target languages.

Step 2: I notice my target (Z) is there, let's say Z = C++.

Step 3: I choose my source (X) is there, let's say A = Java.

Step 4: I click "GO!" and bam, up pops up an example side-by-side. On 
the left we have:

void function(int i, ObjectType o)
{
   // i is passed by value, therefore changes are local
   i += 4;

   // o is passed by reference.. changes inside persist
   o.somefunction();
   o.somepublicfield = somevalue;
}

On the right:

void function(int i, int & j, int * k, my_type * ptr, my_type & ref)
{
   // i is passed by value, changes are local
   i += 4;

   // j is passed by reference, changes persist
   j += 4;

   // k's address is passed by value, but you can use it to change
   // the value of the variable it is pointing to in memory
   // changes persist if you do this
   (*k) = 4;

   // but not if you do this. address value in k is local
   k = 0x08fe82a6;

   // changes value of somemember in object pointed to by ptr
   o->somemember = somevalue;

   // same deal except via a reference
   ref.x = 4;
}

On the bottom:

Note1: in Java, all object types are passed by reference whereas all 
primitive data types are passed by value.

Note2: In C++, all primitive data types are passed by value unless you 
use a reference or pointer. There are two way to pass something "by 
reference": using a pointer or using a reference. Bla bla bla...

> If you have any ideas you would like to try, by all means please 
> experiment on the project wiki.
> 
>> There's also the advantage that you can quickly assess whether or not 
>> the concept exists in your collection, and and even better advantage: 
>> you can put a pseudo-code version on the concept's profile.
> 
> True, I think this would be a very useful feature. Again though, how to 
> implement... ?

I guess what I'm trying to say is that I would use this as a reference 
and not as a way to learn a new language. IMO, you shouldn't use a tool 
like this to learn a new language, because (as Lennart Sorensen pointed 
out) you'll miss some of the intended ways for the language to be used. 
It should used only as a reference, and as such should be indexed first 
by programming concept and *then* by source/target languages.

Now, if you're using a wiki (without adding any custom code of your own) 
then implementation of this may be problematic. Ideally you'd need to 
build your own database back-end so that you control how the data is 
served. Can you extend a wiki to do this kind of thing? I don't know. 
All I know is if I was using it, I would not want to search all n 
possible source languages (two clicks and two page loads each) to find 
out that what I was looking for wasn't there. In fact, if I had to do 
this I wouldn't use it at all because Googling would be faster.

Marc

-- 
What a season to be beautiful without a reason.
   -- The White Stripes
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list