4

I realize that it is impossible to have one language that is best for everything.

But there is a class of simple programs, whose source code looks virtually identical in any language.

I am thinking not just "hello world", but also arithmetics, maybe string manipulation, basic stuff that you would typically see in utility classes.

I would like to keep my utilities in this meta-language and have it automatically translated to a bunch of popular languages. I do this by hand right now.

Again, I do not ask for translation of every single possible program. I am thinking a very limited, simple language, but superportable.

Do you know of anything like that? Is there a reason why it should not exist?

Roman Zenka
  • 3,514
  • 3
  • 31
  • 36
  • I expect many people will soon recommend Python. I won't recommend it because I've never used it, but it seems to be the sort of thing people answer this type of question with. – FrustratedWithFormsDesigner Dec 09 '10 at 16:47
  • Okay, but can I take Python source code, automatically translate it to Java, and use it from my Java program? Can I translate it to C# and C? I do not want to embed the code, I want my code to be written directly in the target language, because dealing with polyglot projects can be a deterrent for many people. – Roman Zenka Dec 09 '10 at 16:48
  • 4
    The language is called pseudocode, and it is translated into real languages by a machine called "programmer". –  Dec 09 '10 at 16:51
  • @delnan: You get it! My point is - there must be a subset of "pseudocodes" that is translatable to a lot of languages automatically. It would form a simple "pseudocode" language. I could have my basic libs written in this and have them travel with me as I switch languages. – Roman Zenka Dec 09 '10 at 16:53
  • 2
    Now, on a more serious note: (1) machine-generated code may work, but it will very rarely be maintainable, let alone elegant or idiomatic. (2) Why should I bother writing such nearly-trivial programs in *yet another*, **limited** language, when I can write it myself in every language I care about? I.e. I don't think such a language you yield much benefit, certainly not enough to justify the work it takes to create this language and a significant number of top-notch backends. –  Dec 09 '10 at 16:55
  • @delnan: Trivial does not have to mean small. The code can be trivial in the sense it uses only a single loop and some multiplications and additions. In practice it does some obscure form of FFT and it has 50 pages. You will be in pain rewriting this over and over. – Roman Zenka Dec 09 '10 at 16:58
  • 2
    But how often do need to write something this complex, in several languages? Often enough that creating a whole language with several backends is easier? And if you need to share code between several languages, either wrapping those parts in command-line tools or using CLR languages might be easier (and also much better from a DRY perspective). –  Dec 09 '10 at 17:01
  • @delnan: My goal would be to have an automated "sniffer" that would walk through your existing codebase and pick stuff that is "simple" and translate it into the "pseudocode" for you. Then you would know that at least this part of your project is language-agnostic in a sense. It could also be a metric of your codebase's portability. And you could have useful, familiar libraries written once and available in virtually every language you like. Code reuse across languages! I have a hunch this would be useful a lot... – Roman Zenka Dec 09 '10 at 17:07
  • @delnan: Good point on DRY. You would repeat yourself, many times, for each language once. But we do that already, by hand. – Roman Zenka Dec 09 '10 at 17:18

5 Answers5

3

Check Haxe, and its Wikipedia page. It's open source and its main purpose is what you describe: generating code in many languages from only one source.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Jem
  • 2,255
  • 18
  • 25
1

I did some looking and found this. https://www.indiegogo.com/projects/universal-programming-language looks interesting

Shawn
  • 3,031
  • 4
  • 26
  • 53
  • That person has no idea how to do it - they just want to "hire experts" and "buy hosting" and somehow the rest will follow. I do not think it will get funded, and if it will, it will fail to deliver... – Roman Zenka Jan 14 '15 at 04:33
  • I mean.. OH MY GOD. They call iOS and Android "programming languages". But thanks for pointing out that there are people with similar dreams to mine. I just wanted something WAY more achievable... just a tiny subset of all these languages for just the most basic calculations. – Roman Zenka Jan 14 '15 at 04:34
  • whoever comes up with something that works for the masses will do well with it, if it's even possible at all – Shawn Jan 14 '15 at 15:25
1

Just about any language that you choose is going to have some feature that doesn't map to another in a natural way. The closest thing I can think of is probably a useful subset of JavaScript. Of course, if you are the language author you can limit it as much as you want, providing only constructs that are common to just about any language (loops, conditionals, etc.)

For purposes of mutability, an XML representation would be best, but you wouldn't want to code in it.

Buggieboy
  • 4,636
  • 4
  • 55
  • 79
  • @eschneider: Not an example of what? It seems to have satisfied the person who asked the question. – Buggieboy Dec 09 '10 at 21:59
  • real mature retaliation Buggieboy, At least I commented why. Ref: Do you know of anything like that? Is there a reason why it should not exist? –  Dec 09 '10 at 22:52
  • I liked the idea of starting with a subset of JavaScript, that's all. Does it answer the question? Well, I see nothing I can download and try right now, so no. Is it a good idea worth a point? IMHO yes, JavaScript was for some reason not on my radar, and having the pseudocode similar to something that used to have connotations of a language used to do simple things sounds good. – Roman Zenka Dec 10 '10 at 16:26
1

If you find that there is no universal language, you can try a pragmatic model-driven development approach, using a template-based code generator.

On the template you keep the underlying concepts of an algorithm. Then, you would add code for this algorithm in one or more specific languages (C++,Java,JS,Python) when necessary. You would have to do it anyway, whatever the language or approach you choose. A configuration switch would pick the correct language for any template you apply.

AtomWeaver is a code generator that works with templates and employs ABSE as the modeling approach.

Rui Curado
  • 951
  • 5
  • 12
0

A classic Pascal is very simple. Oberon is another similar option. Or you could invent your own derivative language similar to the pseudocode from the computer science textbooks. It's trivial to implement a translator from one of that languages into any decent modern imperative language.

SK-logic
  • 9,605
  • 1
  • 23
  • 35