11

So we all know that learning a programming language is a tiny portion of getting productive on a platform. It takes far longer to learn the Java libraries than it takes to learn the Java Programming Language, same goes for C#, JavaScript, Python, Ruby ... etc.

As programmers we can easily make the observation that a for loop or an array is a for loop or an array in any programming language. Once you learn the concept you don't need to re-learn it sure the syntax is different but zero effort is spent re-learning the concept. Obviously this is not the case with standard libraries, which means we have to re-learn how do common tasks such as files manipulation, talking to a database, doing networking on every platform that we use, this is inefficient and painful, there must be a better way out there.

The W3C DOM is an example of a cross language library that is supposed to have the same function names and the same semantics no matter the programming language. W3C DOM is hard to use but at least once you learn it in one language/platform it is the same in others.

Is there a set of cross language libraries defined anywhere for the most common tasks that a developer circa 2011 would care about.

  1. File IO operations
  2. Networking
  3. Process management
  4. Database Access
  5. Collections and data structures
  6. Cryptography, Digital Signatures, Cryptographic hashes
  7. Anything else that is useful which does not involve UI code

Clarification: I am not interested in APIs that are bound to current platform like .NET or the JVM because those are tied to a single company and in many cases they APIs are showing their age and if they were re-designed today would be much cleaner/better. Also being primarily a Java developer watching Oracle take over Java sue Google has been a true horror show. I really don't want the hours that I invest in mastering a platform to be tied to controlled by a single entity, but rather be some sort of open source project, where the best designs win.

Clarification: I am looking for APIs that are the same in lots of different languages not tied to a single language. For example consider reading the contents of a text file. I have to open the file, read the contents, ... etc I would be looking for an API where function had exactly the same name in all the various languages, the same parameters, in the same order, with the same return data, same error handling semantics. I am aware of different programming paradigms so I am okay with an OO version of the API, a functional version ... etc.

2
  • Sounds like you want to have just one language. Never going to happen.
    – duffymo
    Oct 4, 2011 at 22:42
  • 1
    I started a web site, loyc.net, that I hope will someday be a community devoted to issues like this. Certain features are becoming standard in most languages - closures, dictionaries, exceptions, some kind of automatic memory management (at least refcounting), some kind of genericity (in statically typed languages), some kind of "interfaces", some kind of inheritance, generators/async - but there's still substantial variation, hindering standardization. If somebody is working on the problem of mapping the same concepts to various languages, let me know!
    – Qwertie
    Jun 10, 2017 at 10:15

6 Answers 6

4

An interesting question... I think that there is greater opportunity for libraries that perform more specialized functions to be developed with multiple language bindings (and you are starting to see this with various web services). Unfortunately, the abstractions provided tend to be fairly simplistic and often feel "alien" despite the efforts of developers to make the language bindings as natural as possible. Perhaps a better way to say it is that they tend to be unidiomatic. The low level POSIX APIs, for example, do in fact represent a kind of lowest common denominator for a standard library, but the challenge is that different languages (can) approach even these basic abstractions very differently in their quest to make them "natural" for that language. Another problem (as alluded to in previous posts) is that by their very nature, standard libraries have to be agreed upon and this can be extremely challenging by itself. Unfortunately this process often leads to APIs that really satisfy no-one. (for example... do we REALLY have to support 36 bit words or the Coptic Calendar? Depends on your point of view. Should the API be object oriented, functional or something else like streams? Also depends on your point of view. Just pointing out that this is perhaps a more complicated issue than one would think.

It should be noted that there have been efforts to provide better (at least more consistent) APIs for standard things. One example is Plan9, an operating system in which EVERYTHING is a file. Overall, reviews have been mixed.

3

That's a good question. Such library will be a good asset for every developer, but it can not be standard, because standard libraries are very conservative, and it takes time for the ideal API to settle down. There is also a problem with backward compatibility that once code is entered standard library, it can not change. In Python community there is a joke that good modules enter standard library to die.

This library can start, not as a library though, but as a community/recipe site that will concentrate on the collaboration process, because it's not easy for one man to persuade all others that the chosen API is the best. You really have to convince everybody.

I can not say for other languages, but in Python community there is a concern about moving stdlib out of the core so that it could evolve more rapidly. There is an proposal labelled PEP 413, but it is not enough. The plan could be to:

  1. Define namespaces (modules in Python)
  2. Gather stats for actual function usage (static analysis + public repository spider)
  3. Get the best from all the languages
  4. Analyze, debate and vote (or just use that you like) - this requires user story database that enlists common problems, ways to solve them and contains summaries (Python Cookbook in CHM once was a very nice example of such summaries). There is one more very important function of the database - detect conflicting use cases.
  5. Agree on the license (or just accept that Public Domain is the only copy/paste compatible way)

So, the answer is - there is no such cross-language library. Because there is insufficient communication between parties. Because there is no intuitive platform to do this.

2
  • I was thinking of starting a web site as an offshoot of loyc.net devoted to suggesting common "interfaces" and how they would work - not just the usual stuff like lists, dictionaries, strings and file access, but representations of colors, points/vectors, iterators/ranges, graphs, geometry, syntax trees, unit tests, logging, parallel processing, symbolic math, GUIs, whatever. Another idea: a binary cross-language interoperability system built on top of WebAssembly (which is likely to take over the world). If someone is starting a project in one of these areas, let me know!
    – Qwertie
    Jun 10, 2017 at 10:33
  • @Qwertie interfaces is a good idea. And interfaces are specific for a task at hand. I like Go for switching people obsession from OOP to interfaces. There are no ideal interface that can satisfy all tasks. But to realize that, tasks should be put first. As automatic tests. Like exercism.io but public domain for unrestricted experiments. Jun 11, 2017 at 14:58
1

Yes, there are a few. Windows, MacOS X, Linux... :)

More seriously, the .Net and Java runtimes both support many languages, so if you stay within the set of languages they support, then you can keep your library knowledge.

2
  • 1
    Java runtime??? Other than Java and Scala, name one... Oct 4, 2011 at 22:47
  • 1
    @SevaAlekseyev JRuby,Jython,Erjang,Rhino...?
    – µBio
    Oct 4, 2011 at 22:48
1

The following things come to one's mind:

  • Microsoft .NET - rather tightly bound to the Microsoft ecosystem (but keep Mono in mind), has bindings to many languages, design is somewhat Java-inspired. Does most of the things you've listed.

  • Qt - roots very firmly in C++, has bindings to other languages, not as heavyweight as .NET, but does not feel as alien on *nix and MacOS. Database support is very primitive, crypto support is nonexistent.

1

I guess the obvious use-case is to ease developer transition to new languages, and porting of code.

OpenGL code can look pretty similar across some languages, but not all. The DOM is an excellent example. The very minimal JSON parse/stringify interface may be the most widely ported and unambiguous library!

But what you really want, a full set standard cross-language API, I have not seen.

As martin rightly points out, there are issues with the scope of such an endeavour. Having to cater to the lowest common denominator means losing any language features which are not available in all of the languages in our desired spectrum. That could mean

  • no first order functions
  • no generics/templates/polymorphism
  • the need to free() unused memory
  • static typing, forced pass-by-reference
  • operability without closures
  • convoluted event listeners
  • and the ability to function in both multi-threaded and single-thread environments (return vs callback).

Whilst it might be frustrating to lose the very features that we have chosen a language for, there could still be benefits from such a project. A narrower scope is likely to provide better results.

The Haxe language may be of interest to someone considering such a project. It already has a minimal standard library (and Stax), and can export to a number of different languages, including C++, Flash, PHP, Neko, Javascript and more recently C# and Java. (I do not know if the final results look the same in all languages.)

Whilst CommonJS and Narwhal are language-specific (Javascript), they may be notable as attempts to create a standard library interface.

Processing has been ported to a few languages, so there may be some useful libraries there.

There must be a large number of specific examples, like JSON. For example, the Fuse virtual filesystem interface is accessible from C, Python, Java and many more languages. And I would be surprised if someone haven't tried creating an implementation of the 2d Canvas API for languages than Javascript.

Apache have released a lot of same-domain software in different languages, and may have produced some similar looking libraries.

1

There is a library that does exactly what you say. It is called turboCommons and you cand find it on GitHub:

https://github.com/edertone/TurboCommons

Not the answer you're looking for? Browse other questions tagged or ask your own question.