The Universal Standard Library
clintonforbes.blogspot.com.au
clintonforbes.blogspot.com.au
Some of these functions change the string in-place (C), and others return a new string (Objective-C). Some languages have both options (Lisp), while others can't because strings are immutable (Python). Some languages define strings as arrays of characters, and others have some other opaque array-like structure made up of characters, and others have no concept of a character at all (just "length-1 strings"). And so on.
The biggest differences between languages are not names, but semantics. My editor will happily remind me of the proper name in any language, but that's the least of my worries since I've got to mentally shift gears anyway. The algorithm I write for different kinds of strings can be completely different.
I'm reminded of a similar issue with GUIs a few years back, when Redhat (I think) made themes to unify the look of GNOME and KDE, even though they still worked differently. The conclusion reached was that they should have unified the behavior first (always a good thing), rather than unifying the appearance first (which led to more confusion).
But that could be a problem for programming languages, since these differences are pretty fundamental.
Side Comment: If Oracle prevails in copyrighting an API this problem will get worse.
I ran smack into a variant of this problem playing around with ARM chips, libc. Its one of the places where gcc has really let me down, because if you get an ARM cross compiler its expecting anything and everything. The various flavors of C library are all bulky and nicely modularized but somehow less useful. And of course there are things in there which assume an OS (stdio for example) or at least a model that the code adheres to) but embedded systems are sometimes not that easily adapted.
And there are libraries provided by the manufacturers which have copyright notices in them about how this code can only be compiled to run on their (the manufacturer's) brand of ARM and when I look at the code I keep thinking "Hmm, I bet if I dug up the code I wrote for SunOS 4.0 when I was but a wee kernel hacker to make libc work with shared libraries, that a lot of it would be eerily familiar :-)
So what it boils down to are that there are 'things' and the useful things are 'memory abstraction (bcopy/memcpy etc)' string abstractions 'str' and character abstractions 'is' and then io abstractions (open/close/read/write/seek/rewind) and then thread abstractions (fork/sleep/wake/longjmp/yield) and suddenly your USLS is basically an OS API (or it could be) and you're back to square zero.
So rather than a universal library, why not universal VIM code? VIM is already syntax aware based on your language you could add the ability to insert the appropriate code to do what you wanted to do while you were editing. So if you had a variable and you typed if a:upcase == b:upcase it would syntactically awarely conver a:upcase to 'strtoupper(a)' or u"$a" or a->upper() or what ever the language you were writing in needed. Sort of a markdown for library calls. Then you train your fingers to type the markdown and be done with it.
Back to the topic: I think the real obstacle to this USLS idea is that each language has its own idiomatic way to name things, so a common across languages naming scheme or convention will likely look somewhat alien in each of them, and we all know the importance of source code aesthetics for programmers. This might change only if polyglot programming becomes very common.
This makes me lol. Marx should have included that in his Communist Manifesto right after the bit about taking despotic measures to guarantee freedom for the proletariat.
PHP = strtoupper($str)
Ruby = "Hello".upcase
Since Ruby is a method on the string object and PHP takes the string as an argument. To make them the same you would need to do either
PHP = upcase($str)
Ruby = "Hello".upcase
In which case you lose context in PHP or
PHP = strtoupper($str)
Ruby = "Hello".strtoupper
In which case you are repeating yourself in ruby.
Common Lisp's is actually called STRING-UPCASE, not string-upcase, though with the default reader settings that will work too.
Oh, yes... here it is: http://xkcd.com/927/
In your face, 16th century papacy!
The fundamental problem with this approach is that either your language is too different from the host for the library to map perfectly or it's too close to the host too be terribly interesting.
Well, "strupr" is not part of ISO C at all. In fact I'm having a hard time finding out just which libc it comes from. Unfortunately the only uppercase function in the standard C standard library is the one you write yourself using toupper().
A mapping/grouping of related functions in each language that allows you to perform searches like:
"toUpperCase in Ruby" "upcase in Python"