Skip to main content
added 14 characters in body
Source Link

I'm planning to write a single API that is syntactically valid in most major programming languages (to the greatest extent possible, so that only minimal amounts of code will need to be re-written when moving from one language to another). I think the simplest way to do this would be to write a group of functions that consisted entirely of function calls and variable assignments, since the syntax for function calls is almost exactly the same in all major programming languages.

Of course, I'd need to write "wrapper" functions for if-statements and while-loops, since the syntax of each of these is different in each programming language.

Here's a proof-of-concept for one "polyglot" function that should work in most programming languages:

//JavaScript syntax
function proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

//Java syntax
public static void proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

//Python syntax
def proofOfConcept():
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.

//C syntax
void proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

Would this be a useful design strategy, or is there a better way to do this? I think this would be a useful strategy for developing libraries in multiple programming languages, since the syntaxalthogh it would require a small number of "language-specific" functions to be written for function calls is almost exactly the same in all major programming languageseach target language.

I'm planning to write a single API that is syntactically valid in programming languages (to the greatest extent possible, so that only minimal amounts of code will need to be re-written when moving from one language to another). I think the simplest way to do this would be to write a group of functions that consisted entirely of function calls and variable assignments, since the syntax for function calls is almost exactly the same in all major programming languages.

Of course, I'd need to write "wrapper" functions for if-statements and while-loops, since the syntax of each of these is different in each programming language.

Here's a proof-of-concept for one "polyglot" function that should work in most programming languages:

//JavaScript syntax
function proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

//Java syntax
public static void proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

//Python syntax
def proofOfConcept:
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.

//C syntax
void proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

Would this be a useful design strategy, or is there a better way to do this? I think this would be a useful strategy for developing libraries in multiple programming languages, since the syntax for function calls is almost exactly the same in all major programming languages.

I'm planning to write a single API that is syntactically valid in most major programming languages (to the greatest extent possible, so that only minimal amounts of code will need to be re-written when moving from one language to another). I think the simplest way to do this would be to write a group of functions that consisted entirely of function calls and variable assignments, since the syntax for function calls is almost exactly the same in all major programming languages.

Of course, I'd need to write "wrapper" functions for if-statements and while-loops, since the syntax of each of these is different in each programming language.

Here's a proof-of-concept for one "polyglot" function that should work in most programming languages:

//JavaScript syntax
function proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

//Java syntax
public static void proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

//Python syntax
def proofOfConcept():
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.

//C syntax
void proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

Would this be a useful design strategy, or is there a better way to do this? I think this would be a useful strategy for developing libraries in multiple programming languages, althogh it would require a small number of "language-specific" functions to be written for each target language.

Source Link

Writing an API that is syntactically valid in multiple programming languages

I'm planning to write a single API that is syntactically valid in programming languages (to the greatest extent possible, so that only minimal amounts of code will need to be re-written when moving from one language to another). I think the simplest way to do this would be to write a group of functions that consisted entirely of function calls and variable assignments, since the syntax for function calls is almost exactly the same in all major programming languages.

Of course, I'd need to write "wrapper" functions for if-statements and while-loops, since the syntax of each of these is different in each programming language.

Here's a proof-of-concept for one "polyglot" function that should work in most programming languages:

//JavaScript syntax
function proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

//Java syntax
public static void proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

//Python syntax
def proofOfConcept:
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.

//C syntax
void proofOfConcept(){
    printSomething("This is just a proof of concept."); //the function printSomething will
    //                      need to be implemented separately in each programming language.
}

Would this be a useful design strategy, or is there a better way to do this? I think this would be a useful strategy for developing libraries in multiple programming languages, since the syntax for function calls is almost exactly the same in all major programming languages.