(I talk about myself in the post more than usual. I'm expressing opinions more than usual, rather than observations and advice. Caveat lector. Also, this post is link-rich.)
The stack
After reading Eric S. Raymond (ESR)'s posts on the post-"C" world, I realized that I, too, live in that world. What would my ideal language stack look like for 2018?
For context, here are ESR's posts I have in mind:
- The long goodbye to C
- The big break in computer languages
- Language engineering for great justice
- C, Python, Go, and the Generalized Greenspun Law
Read them? Good. So this is the language stack I have in mind:
Each of these languages hits a sweet spot, and displaces an earlier language which was itself a sweet spot of its time:
An interesting general trend here: Not just replace a language with a more modern equivalent, but also move programming further away from the hardware. As ESR points out, Moore's law and improving language engineering have raised the bar.
(ESR's thinking has evolved over time, a sign of someone who has given deep and sustained thought to the subject.)
About my experience with these languages
Python
I have moderate experience in Python spread out since the mid-90s. At that time, I was undecided between Python, Ruby and Perl. Over my career I worked heavily in Perl (it paid well, then), some in Ruby (mostly at ThoughtWorks), and gravitated strongly to Python, especially after using it at Macquarie commodities trading where it was central to their business.
Kotlin
I've been a Kotlin fan since it was announced. It scratches itches that Java persistently gives, and JetBrains is far more pleasant a "benevolent dictator" than Oracle: JetBrains continually sought input and feedback from the community in designing the language, for example. Java has been my primary language since the late 90s, bread and butter in most projects. If JetBrains keeps Kotlin in its current directions, I expect it to displace Java, and deservedly so.
Go
This is where I am relying on the advice of others more than
personal experience. I started programming with "C" and LISP
(Emacs), and quickly became an expert (things being relative) in
C++. Among other C++ projects, I implemented for INSO (Microsoft
Word multilingual spell checker) a then new specification for
UNICODE/CJKV support in C++ (wstring
and friends). I still love "C" but could do without C++. Go seems
to be the right way to head, especially with garbage collection.
With Ken Thompson and Rob Pike behind it, intelligent luminaries like ESR pitching for it, and colleagues at ThoughtWorks excited to start new Go projects, it's high time I make up this gap.
What makes a "modern" language?
I'm looking for specific things in a "modern" language, chiefly:
Good community
Varying and strong:
You can explore the figures at TIOBE and StackOverflow.
Kotlin is the interesting case. Though low in the rankings, because of 100% interoperability running on the JVM, it's easy to call Java from Kotlin and call Kotlin from Java, so the whole Java ecosystem is available to Kotlin natively.
Further, Google fully supports Kotlin on Android as a first-class language, so there is a wealth of interoperability there. (The story for iOS is more nuanced, with Kotlin/Native including that platform as a target but in progress.)
Lastly, Kotlin/Native is bringing similar interoperability between Kotlin and Go.
(This is related to having a rich ecosystem.)
Garbage collection
(A quick primer (2011) on garbage collection.)
Among Go's advantages over "C" and C++ is solid garbage collection out of the box, though Boehm a valiant effort. It's only been since 1959. No modern programmer—short of special cases—should manually manage memory.
Kotlin gets a head start here. It's built on the JVM (when targeting that environment), which has arguably the world's greatest GC (or at least most tested). It definitely gives you a choice of garbage collectors. There's too much to say about GC on the JVM for this post except that it is first-rate.
Python has garbage collection. Though not as strong as the JVM, it continues to improve. It is unusual for GC to become a limiting factor in a Python program; you will know if it does.
(If you are in "C" or C++, and want some of the benefits of GC, do consider the Boehm-Demers -Weiser garbage collector. No, you won't get the fullest benefits of a language built for GC, but you'll get enough to help a lot, even if just for leak detection.)
Static type inference
Kotlin really demonstrates where Java could improve by leaps rather than baby steps: automatic type inference. At least Java is heading in the right direction. Don't tell the computer how to run your program when it can figure this our for itself! Keep your focus on what the program is for.
Interestingly, Kotlin and Go have strong
typing out of the box, but not Python. Python
has built-in support for typing, and an
excellent optional implementation, mypy
,
however this is type declaration not type
inference, so it loses a bit there. And none of the
common alternatives (Ruby, Perl, PHP, etc.) have type
inference either. I'll need to check again in a few years, and
possibly update this choice.
(Paul Chiusana writes on the value of static type checking.)
Rich ecosystem
Of the languages, Kotlin is a standout here. Because it is a JVM language, it is 100% compatible with Java, and can fully use the rich world of Java libraries and frameworks. The main weakness for Kotlin is lack of tooling: because more advanced tools may make assumptions about bytecode, Kotlin's particular choices of emitted bytecode sometimes confuse them.
(JetBrains has surveyed on the state of ecosystems for programming languages, related to having a good community.)
Close behind is Python, "batteries included" and all, and it has a better organized and documented standard library than Java. For some problem domains, Python has a richer ecosystem, for example, SciPy and NumPy is the best math environment available in any language. (Some specialty languages like MATLAB deserve mention—an early employer of mine.) I may need to reconsider my ranking Kotlin over Python here.
Go is, frankly, too new to have developed an equivalent ecosystem, and full-blown package management is still a work in progress.
Concision and convenience
A common thread in recent language development is lower ceremony: fewer punctuation marks and boilerplate; make the machine do more work, you do less. Kotlin provides the most obvious example compared to Java. Go is know for cleanness and brevity. And Python ranks high here as well.
(Donnie Berkholz writes an interesting post on ranking language expressiveness.)
Code samples
The classic "Hello, World!" showing three things:
- Writing a "main" callable from the command line
- Using standard output to print to console
- String formatting to build the output message
This doesn't, of course, give a sense of how these languages in their full spectrum, but does give a first taste.
Java
Java in a file named MyStuff.java:
package my.stuff; public final class MyStuff { public static final String LANGUAGE = "Java"; public static void main(final String... args) { System.out.println(String.format("Hello, World, from %s", language)); } }
Kotlin
Kotlin in a file named my-program.kt:
package my.stuff const val LANGUAGE = "Kotlin" fun main(args: Array<String>) = println("Hello, World, from $LANGUAGE")
Go
But also compare Go to C++:
package main import "fmt" const Language = "Go" func main() { fmt.Println("Hello, World, from", Language) }
C++
And C++:
#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }
Python
And for completeness, Python compared to Perl and BASH:
#!/usr/bin/python language = 'Python' print('Hello, World, from {}'.format(language))
Perl
Any Perl:
#!/usr/bin/perl use strict; use warnings; my $language = "Perl"; printf("Hello, World, from %s\n", $language);
BASH
Unfairly simple:
#!/bin/bash language=BASH echo "Hello World, from $language"
See also
Update
As usual, I never catch as many problems in my writing as I do
after reading it posted publically. Many small edits, and an
added, explicit mention of wstring
.
No comments:
Post a Comment