Tuesday, 25 November 2014

Attack of the one-letter programming languages

Attack of the One-Letter Programming Languages

From D to R, these lesser-known languages tackle specific problems in ways worthy of a cult following

Watch out! The coder in the next cubicle has been bitten and infected with a crazy-eyed obsession with a programming language that is not Java and goes by the mysterious name of F. The conference room has become a house of horrors, thanks to command-line zombies likely to ambush you into rewriting the entire stack in M or R or maybe even -- OMG -- K. Be very careful; your coworkers might be among them, calm on the outside but waiting for the right time and secret instructions from the mothership to trash the old code and deploy F# or J.
A long time ago -- long before Netflix, Hulu, and HBO battled for the living room -- people went to the movie theaters for their weekly dose of video streaming. There were usually only two movies, and you couldn't choose the order. (The horror!) The double feature began with the big stars -- the Javas and JavaScripts of the acting world -- but then it got interesting. The second feature, the so-called B movie, was where the new ideas, odder actors, and weirder scripts found their home. Some proved rich enough with exactly the right kind of out-there thinking to garner significant cult followings -- even break through to the mainstream.
The programming languages with one-letter names are one such corner of the Internet. They're all a bit out there, with the possible exception of C -- a language that once received top billing but is now lucky to be opening for the printer-driver convention.
They may not be for every job -- many are aimed at specialized tasks -- but that doesn’t mean these one-letter languages comprise a gallery of misfits. Each offers compelling ideas that could do the trick in solving a particular problem you need fixed. These languages all embody the crisp, simple nature of their names. K?

One-letter programming language: C

Long ago, when Brian Kernighan and Dennis Ritchie, aka K&R, set out to write Unix, their plan was to use B, an internal language at AT&T. But B couldn't address individual bytes, which was a big deal because the fancy new PDP-11 came with the immense-for-the-time 16-bit words. K&R added more bit-banging features to create C, which quickly became popular as it was the lingua franca for Unix. The language grew as it added object-oriented features to become C++. Apple adopted another variant called Objective-C, which it is now starting to get out from under with the introduction of Swift, if only a little.
Of course, programming is a lot different now than it was in the early days of Unix. There are so many bits and bytes that the programmers can't keep the pointers straight. Thus, most of the serious work these days uses languages that take all the power out of the hands of the coders. C lives on, though, in the hearts and minds of those who still need to tweak the bits and bytes of the lowest levels of the operating systems and boot loaders. If you're writing a printer driver or fiddling with the context-switching of the kernel, it's still a big star.
While certainly not the first one-letter programming language, C has become somewhat of a granddaddy of the one-letter programming language naming tradition, given its far-reaching popularity. Consider it the B-movie crossover cult classic that became a mainstream hit.

One-letter programming language: D

When the new millennium began, many looked at C and found it both wonderfully flexible and expressive but a bit of a pain. It was one step above assembly language, so it was easy to work with the bits and bytes flowing into and out of the CPU. On the other hand, the language did little else, and programming in C became a constant struggle of juggling pointers while trying not to add security holes.
D's creators wanted to build a language with as much expressive power, but many of the modern conveniences like garbage collection and type inference. You can write simple bit-bashing loops while knowing that the D system will clean up the messy bits of memory and prevent you from doing something truly stupid with data structures. Apple took a similar strategic path when it created Swift.
There are some features, like objects, that everyone expects and some surprises, like constructs for functional programming. If you want to make a variable immutable -- a oxymoron, I know -- you can do it and use it in a recursive function. It has most of the raw power of C but upgraded with a modern sensibility. If you're writing device drivers, now you can do it without worrying -- as much -- about memory or simple pointer errors.

One-letter programming language: F

The first big language was Fortran, and for years the language grew by adding features. Programmers half-joked that they didn't know what the next generation of programming languages would be, but they knew it would be called "Fortran."
This is half-true. Well, one-seventh true -- F is a cleaner, simpler subset of Fortran created by the Fortran Company, a group whose motto is "For Fortran Enthusiasts by Fortran Enthusiasts." The mechanisms for working with data are mostly there, so you can feel right at home writing loops, but they cleaned out the cruft (like the EQUIVALENCE statement) that confused beginners.
The language is designed to work well with the past. You can link to Fortran 77 and all the software you still have stored on dusty decks of punch cards. In fact, it's not really a stand-alone tool. You simply turn on a command-line option (-std=F), and your Fortran 95 compiler becomes an F compiler by enforcing the cleaner rules.
If you're keeping a factory or refinery running without rewriting a huge pile of legacy Fortran 77 code, now you can enjoy a slightly more modern language for writing the glue logic.

One-letter programming language: F#

F# has nothing to do with F. In fact, F# is different from F in deeper ways than C# is different from C. While F is the latest version of the classical imperative programming, F# is devoted to functional programming, the idea that software is better when it is built out of simple functions that don't mess around with outside data, often called side effects. This can lead to code that's easier to understand, faster to debug, and more amenable to compiler-driven optimization and parallelization.
Not everyone has a positive experience with functional programming, and some complain about the strange code they must write in order to shoehorn their business logic into the functional paradigm. F# is said to be "functional first," which means you can cheat. There are loops, arrays, objects, and -- gasp -- mutable variables.
There are versions available for major platforms such as Android, iOS, and some desktop operating systems. There are also tools for moving your parallelizable routines to GPUs.

One-letter programming language: M

A long time ago when acronyms actually had to have words behind them, some developers building a database for the medical world called their product the "Massachusetts General Hospital Utility Multi-Programming System," presumably because it boiled down to "MUMPS." (Hah.) When the naming trends changed, the MUMPS world renamed it M, a decision blessed by the ANSI in 1995. The name change isn't sticking, though; in the week that I wrote this, more than 20 jobs were posted on Dice.com looking for MUMPS programmers and only one of the subject lines called it "M/Mumps."
The language itself is often considered one of the earliest examples of a key-value database, the model now being rediscovered as NoSQL data stores. But you don't do your work with queries sent to a distant, mystical entity behind a curtain; you dump your data into what looks like a variable and MUMPS -- er, M does the work of storing it. It handles the caching and moves it between memory and disk.
The medical world, including the Veteran's Administration, remains one of the biggest users of the language, but there have always been redoubts in other industries such as banking where there's a need for processing large amounts of data. The M community is proud to crow that the European Space Agency wants to use it to analyze the data coming back from the Gaia mission.
If you're searching through big tables of medical records to find the cure for a disease, this can help you find the answer.

One-letter programming language: P

There was once something called P-code produced by the Pascal compiler. It was meant to be a machine-independent version like Java class files, but that has little to do with the language that Microsoft calls P today. This version is designed to make it easier to write code for all the little machines in the world, the Internet of things. These often spend most of their time waiting for instructions, then they execute it.
P asks the programmer to construct a "state diagram" filled with nodes. The input from the user will trigger the transition from one node to another. A graphical version of the code looks like a bunch of rectangular blocks representing the states with a bunch of arrows drawn between them. The asynchronous commands trigger a jump from one box to another along one of the arrows.
Microsoft has built both graphical and textual ways of specifying P. The compiler converts your state diagrams into C code, which is, in turn, compiled as usual. In the past, simply handing the state diagram to a programmer produced code that wouldn't always make the right transitions. Asking the compiler to convert the state diagram in a regimented way will generally do a better job than all but the best programmers. Microsoft recently used the techniques to improve its work with the USB stack.
If you're creating code for an elevator controller or a microwave, a car, or any other element of the Internet of things, this offers a simpler way to build out the state diagram.

One-letter programming language: R

A long time ago when mainframes ruled the earth, R was called S and researchers used it to compute statistics. The names changed when researchers added lexical scoping, but it still feels like an online scratchpad for extracting statistics from large tables of data. You load data, call functions to plumb the data for correlations, then turn these correlations into elaborate graphs.
Using R is a bit easier now thanks to tools like Rcmdr, RStudio, and a half-dozen more, with the interest in big data encouraging the creation of other options. Without R, all you have is a table full of numbers. With R, you can build fancy graphs of elaborate numbers that might even explain what's going on inside that inscrutable table.

One-letter programming language: J

Once upon a time, a manager counted the lines of software coming out of the cubicle farm and determined that programmers wrote N lines of code a day. It didn't make a difference what language was used -- the company would get only N lines out of them. The manager promptly embraced APL, the tersest, most powerful language around, created by IBM for manipulating large matrices of numbers, complete with special characters representing complex functions for further terseness.
Along the way, everyone got tired of buying special keyboards from IBM, but they loved the complex functions that would slice and dice up big matrices of data with a few keystrokes. J is one of the spinoffs that offers the power of APL, but with a normal character set.
If you have vast arrays of data, you can choose one column and multiply it by another with a few characters. You can extract practically any subset with a few more characters, then operate on it as if the complex subset were a scalar. If you want to generate statistical abstracts, the creators of J have built large libraries full of statistical functions because that's what people do with big tables of data.

One-letter programming language: K

J is not the only sequel to try to bring APL to a bigger audience by remapping everything to a standard keyboard. K comes from a different group, the crew that first built A, then A+. After that, they jumped inexplicably to the letter K, which offers many of the same extremely powerful constructs for crushing vectors and multidimensional arrays. You can express extremely elaborate algorithms for working with arrays in a few keystrokes.
It's worth marveling at the stark power of this one-line program to find all prime numbers less than R. It's barely even half a line:
(!R)@&{&/x!/:2_!x}'!R
In fact, it's less than half a line -- it's exactly 21 characters. You could probably pack a K program for curing cancer into a single tweet. If you're crunching large multidimensional arrays of business data into answers, you can save your fingers a lot of work with K.

One-letter programming language: G

A number of projects lay claim to the letter G, but one popular option differentiates itself from the pack in very interesting ways. While people talk about the Internet of things as if it were entirely new, G programmers have been using their code to build physical items from the beginning. The language is widely used to control the milling machines that turn a block of metal, wood, or plastic into an object.
Many versions of G have surfaced in the 50-plus years it's been around. As the machinery became better, G adopted a number of functions for positioning and repositioning the cutting tool. The syntax is largely unreadable to neophytes, and it is more like assembly code than any elaborate computer language. G96, for instance, is a code that changes the relative speed of the cutting tool. It's followed by the speed. This lack of abstractions may be why many operators call it "G-code" instead of thinking of it as a full language.
If you're building the next generation of computer-designed objects, start here.

Source: http://www.infoworld.com

No comments:

Post a Comment