Tag Archives: languages

Why I don’t use Groovy

It’s a Python/Ruby knockoff. If you like Python or Ruby but want the JVM, just use Jython or JRuby.

The best thing about Groovy, and the thing that separates it from Java, is closures. Though it looks like they’ll be coming to Java soon, so stay tuned.

SPARK/Ada

Cheetah wearing an M1 helmetThat’s a Cheetah wearing an M1 helmet. Yeah, SPARK/Ada is that goofy. Pascal was considered unsafe for military projects, so they made Ada. Then Ada was considered unsafe for military projects, so they made SPARK, lulz.

Modern languages with type safety include Haskell, OCaml, and Coq. Because our critical systems are too precious for antiquated technology.

Chicken Scheme for the Soul

chicken scheme logoRemember the child-like glee of writing your first computer program? It’s damned hard, but also fun. You feel in control, the god of a tiny universe. Anything is possible! But as you’ve matured, your smile may have faded. Programs are no longer for enjoyment, but for verification. Design, unit test, implement, commit, doze, repeat. Has programming become a bore? It’s time to rekindle the fire.

If you haven’t learned Lisp yet, it’s highly recommended. Don’t worry that your boss still wants you to use Java. Don’t worry that it feels… alien. When it finally clicks, you’ll learn to program as you never have before, and you can take that knowledge back into the corporate, very much non-functional world. You can return to the barren moor of C# armed with Lispy methodology in a .NET environment.

There isn’t just one Lisp. There are lots and lots and lots of Lisps, and it’s hard for a newbie to decide between them. For now, we’ll introduce you to a friendly little hen called Chicken Scheme. It’s a language with round corners, a relaxed type system, and a focus on practical programming.

How practical? Chicken Scheme comes with both an interpreter (csi) and a compiler (csc). If you prefer one tool or the other, it’s perfectly fine to use just that. Or, you can test your code with csi and compile your finished projects with csc. But do try the interpreter at least once; it could change the way you program.

Installing Chicken Scheme is fairly easy. Macs use MacPorts.

sudo port install chicken

Linux uses the package manager of your choice.

sudo apt-get install chicken

.
Windows uses the chicken-iup installer.

It’s time to have some fun! Fire up the interpreter by opening a terminal and entering csi.

$ csi
CHICKEN
(c)2008-2011 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.7.0
#;1>

Chicken can add numbers.

> (+ 2 2)
4

Chicken can reverse lists.

> (reverse (list 1 2 3))
(3 2 1)

Chicken can test list elements for evenness.

> (map even? (list 1 2 3))
(#f #t #f)

Chicken can test list elements for <PROPERTY-OF-YOUR-CHOICE>.

> (map (lambda (element) (* element 2)) (list 1 2 3))
(2 4 6)

If you can learn to write lambdas, you’re well on your way to becoming a first-class functional programmer!

Starting to get the hang of it? Play around, don’t limit yourself to the code in a tutorial. It doesn’t take long to program something big and practical like a unit test framework (~ a day).

If you’re lost, login to Freenode IRC join the #chicken room. The folks there are friendly, competent, and hilarious. Finally, if you find Chicken Scheme isn’t doing what you want it to do, you can customize it. Sometimes all you need to be happy is a little ~/.csirc config file :)

MATLAB is horrid

matlab logoI wouldn’t even steal MATLAB, it’s that awful. The syntax is inconsistent, the GUI cumbersome, and the documentation next to useless. Hardly any of the examples are self-sufficient:

fnint

Examples

The statement diff(fnval(fnint(f),[a b])) provides the definite integral over the interval [a .. b] of the function described by f.

That’s not an example! Specify f, a, and b so that readers can understand how to call fnint. MATLAB’s documentation sucks!

In contrast, the newLISP manual is excellent. Here’s the documentation for the abs function.

abs

syntax: (abs num)

Returns the absolute value of the number in num.

(abs -3.5) → 3.5

Oh my God, it tells you how to call abs, it tells you what abs does, and it gives an explicit yet concise example of how to use it in real life. newLISP is free and its documentation is light years ahead of MATLAB’s. I blame it on corporate-style thinking; IBM’s articles are similarly dense/yet void of content.

I played with many different possible syntaxes for fnint and never found the right one. I tried defining a function fun in fun.m and calling integrate(fun, [0 2]). I tried using an anonymous function integrate(@(x) x + 1, [0 2]). I tried using a symbolic function integrate(‘x+1′, [0 2]). None of these worked. I tried using combinations of the above with the MATLAB fnint function. Still didn’t work. If you, dear reader, can elucidate the secret syntax for integrate and fnint, please comment.

Finally, my girlfriend and I came up with an integration function that not only works, it has decent syntax.

function y = riemann(f, xmin, xmax)
	delta = 0.0001;

	y = 0;

	for t=xmin:delta:xmax
		y = y + delta * f(t);
	end
end

fun = @(x) 5 * exp(1) ^ (-(x-3)^2);
riemann(fun, [0 2])

ans =
	0.6970

You still need to declare riemann in a file called riemann.m., and either evaluate the last two expressions fun … and riemann(fun… in the MATLAB interpreter or declare them before the riemann function in riemann.m.

And that’s a hassle. I’ll admit, even Erlang doesn’t let you declare functions in the interpreter, so I don’t expect MATLAB to let you. But it would be nice if the MATLAB interpreter language were a subset of the MATLAB script language and not a derivative.

The GUI

There’s no good reason to use a GUI interpreter. It just gets in the way. Except in the case of Windows, where the Command Prompt has pre-2000 conventions for copy and paste. I still would rather use the terminal.

matlab -nodesktop

You shouldn’t have to add a flag (a long one at that) just to keep the GUI from loading. And guess what? On Windows, the flag doesn’t do jack.

MATLAB exists to do integration of arbitrary functions, and it’s awful at it. There’s no reason to use this proprietary, non-free, dysfunctional language when perfectly decent alternatives exist.

That Ol’ Wheel

ancient wheelGreenspun’s Tenth Rule states:

Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.

Just because it’s a joke doesn’t mean it’s not true. We programmers have been reinventing the wheel for ages, and not in a good way. While playing around with the Graphviz library and its corresponding Haskell wrapper., I constructed a family tree akin to the History of Programming Languages poster. O’Reilly’s hasn’t been updated in quite some time, so I started the hopl project on GitHub.

main = putStr $ printDotGraph $ graphToDot langParams langGraph

Everything else is just minor details. But seriously, langGraph is a simple data structure containing the links between hundreds of programming languages.

hopl image

As you can see, technology starts out quite distinct. Then everything borrows from everything else, and you get mutts like Kahlua (Java + Lua), IronRuby (Ruby + C#), and over eight different implementations of ANSI Common Lisp.

From the perspective of an individual programmer working for a single organization in a timespan of a few years, it makes perfect sense to modify pre-existing tools to work with internal mechanisms; that’s why we have PostScript and Groovy. But James Strachan remarks of his own duplicated work:

I can honestly say if someone had shown me the Programming in Scala book by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I’d probably have never created Groovy.

Look again at this massive family tree. There seem to be two types of programming language development: blind releases and feature stealing. Either your language stagnates of its own accord or through feature creep, becomes an abomination.

Some programming languages’ syntax is so terribly verbose (Common Lisp), cryptic (Perl), or inconsistent (C++) that there is a strong tendency to create a “better” version of it (newLISP, Groovy, Ruby, Java). Every language has its pros and cons, but the abundance of language remixes is mere duplication. For example, there are only a few good reasons to switch from Python to Ruby. They’re basically the same damn language.

I cannot emphasize enough the overabundance of code duplication just inside the Common Lisp community. What do we learn from practically incompatible code bases? That the best language standard is an implementation. Good luck getting multithreaded code to work on AllegroCL, LispWorks, SBCL, CLISP, ECL, GCL, ABCL, CCL, CMUCL on Mac, Windows, and Linux. Now try multithreaded code in Java. It’s freakin’ easy.

Languages are experiments. Just look at Frink. It really has no reason to exist, save the author’s interest in unit conversion. There are whole communities for statistical languages (R), graphical languages (Smalltalk, Objective C), mathematical languages (Mathematica, MATLAB, Octave, Maple, Magma, SAGE). The purpose of a language defines its data structures, which defines the syntax. Every language discussed so far is turing complete; they could each run code in the other given enough time and memory. The three letters S, K, and I could do the same as in the SKI combinator calculus. Languages are also a matter of convenience; else we would have stopped at assembly or even earlier.

Back to Strachan’s comment. Why should we use Groovy when there’s Scala? Heck, why even use Scala when there’s already Haskell?

Like religions, programmers simply keep the first faith they met, for better or worse. Java fundamentalists are leery of Scala, downright fearful of Haskell. It’s the same with Microsoft developers, Lua.NET, and pure Lua. You might counter that these bridge languages exist to program in one language and operate structure in another (e.g. Nu connects Lisp code to the Mac user interface). But a simple library would have done that, and just about every language has a foreign function interface just for that purpose.

Some programming languages exist to make the impossible possible (Lisp, Haskell, Erlang, Prolog). Others exist to make the possible slightly easier (C++, Shell, Processing). I wish developers would just write libraries rather than incessantly creating bastard hybrids. Or better yet, publish algorithms that any developer can implement in his language of choice.

Favorite Programming Languages

code commentsI’m obsessed with programming languages. Typical day: Start a project in Perl, encounter obscure bug, rewrite in Erlang, repeat.

In Order Of Likelihood Of Thinking “I’ve Got A New Project, I’ll Use This Language For It”

Haskell

Pros:

Strictly typed. No null-type errors, no guessing what the hell a value is, or which obscure flags a function accepts as input.

Lazy evaluation. Infinite data structures, won’t run any code unnecessary for computation.

Functional. Can map over lists, using anonymous functions to specify filters. Can write functions that manipulate other functions. Can compose multiple functions together.

Pure. Code with no side-effects. Parallel programming is built-in and damn easy.

Code with side-effects is managed using monads.

Multiplatform. Mac, Windows, Linux.

Excellent, free book: Real World Haskell.

Quick tutorial: Learn You A Haskell.

ghci Interpreter.

ghc --make has all you need to build a stand-alone executable.

Cabal package management.

Quickcheck makes unit testing a breeze.

F# is Haskell for .NET.

#haskell is filled with helpful PhDs.

Cons:

Programs typically take more work before they compile. However, once they compile, bugs are rarely present.

Obscurity results in few tutorials, minimal documentation.

Cabal suffers from dependency issues.

Common Lisp

Pros:

Macros. Code that writes code that writes code. Can write custom code blocks.

Quicklisp package manager.

Functional.

Excellent, free book: Practical Common Lisp.

Another good book: Land of Lisp.

Cons:

Common Lisp implementations vary WILDLY in capabilities, tab completion, syntax, error traces, operating system support, package systems, maintenance, and openness to resolving fundamental design flaws (e.g., shebangs, threads, command line options).

Lisp syntax too uniform (Lots of Irritating Superfluous Parentheses).

Obscurity results in few tutorials, unreadable documentation.

Merely obtaining a Common Lisp platform is a pain.

No de facto standard. SBCL is the most popular, CCL is the easiest to install, and LispWorks is the most complete. Some only run on Windows. Some only run on Mac OS.

#lisp community is a bunch of assholes.

Ruby

Pros:

Monkeypatching. Can modify core behavior with easy, normal syntax.

Object oriented. Smalltalk-inspired OO, that is. Everything is an object. Along with monkeypatching, makes Ruby really flexible (e.g. Rails).

Some functional ability. directory.files.lines.words.letters.collect { |letter| letter.upcase } is typical.

Scripting and excellent POSIX support. Think Perl but with good OO.

RubyGems package manager.

Searchable, intuitive, detailed documentation with RDoc.

Multiplatform. Mac, Windows, Linux, even Haiku. Comes built-in on Mac.

Tutorial: Why’s (poignant) Guide to Ruby.

JRuby is Ruby for JVM.

IronRuby is Ruby for .NET.

Cons:

Slow.

OO permission issues.

RubyGems issues, especially in Ubuntu Linux.

Python

Pros:

Scripting.

Choice between functional and OO programming.

Multiplatform. Mac, Windows, Linux. Comes built-in on Mac and most Linux flavors.

Free book: Dive Into Python.

C-style names for standard library functions. No having to guess and search for functions.

OO without the inconveniences of permissions.

Jython is Python for JVM.

IronPython is Python for .NET.

Slowly gaining industry and academic acceptance. Python is a radical language for rebel programmers. That’s a joke. Try Scheme, ML, or LLVM.

Cons:

Confusing “self” object syntax. There shouldn’t be a need to specify “self” as a function parameter.

Whitespace scope. Introduces tabs-vs-spaces problems. Coding over a remote ajaxterm connection, or any terminal without a tab character, is impossible.

Multiple package systems. PyPM, Eggs, something called “PackageManager”.

Java

Pros:

Multiplatform. Mac, Windows, Linux. Comes built-in on Mac.

Excellent, highly organized documentation.

Major industry and academic support. If a programmer doesn’t know Java, he’s been out of the field for a long time.

Many books and tutorials.

Like C++, but with consistent syntax.

Good error traces.

Cons:

Verbose. Hello World takes way too many unexplained symbols.

Too few tutorials for common behaviors like generating JAR files.

Idiots gushing about how cool and object-oriented Java is. You still have to explicitly cast objects to retrieve them from ArrayLists. Primitives don’t have method calls. Read a freakin’ book. OO has been around since the 70’s. It’s not cool, it’s expected.

Obsession with colossal, overly complicated libraries like Spring and Struts. Woo, enterprise! Let’s Web 2ify our persistent relational databases.

Obsession with heavyweight text editors like NetBeans and Eclipse.

Stand-alone executables must be bundled with the hefty JVM.

C

Pros:

Fast.

Imperative is intuitive.

Can be multiplatform (Mac, Windows, Linux) if the program doesn’t use OS-dependent function calls. In particular, getting getoptlong to work on multiple platforms is a pain.

Major industry and academic support. Many tutorials, docs, and program code available.

THE book: The C Programming Language.

Foreign Function Interface (FFI) allows C to be called from almost any programming language.

Cons:

Verbose.

Malloc and free suck. Use Boehm GC instead.

NodeJS

Pros:

Event-driven, asynchronous programming. Good for servers, GUIs, etc.

NPM package manager. Super easy package creation.

Functional programming with the Underscore library.

node-quickcheck makes unit testing a breeze.

Multiplatform (Mac, Windows, Linux).

JSON configuration format is easy to read and write.

Cons:

Very new.

Slow.

Library is based on the ECMA standard. The ECMA standard is retarded. Example: Any NaN object never equals another NaN object.

Very hard to determine the type of an object. Example: typeof(o) returns “object”, but o could be an OO object or a simple hash.

Disorganized standard library (not even counting differences between Microsoft’s, Apple’s, Opera’s, Mozilla’s, and Google’s JavaScript engines).

Obscurity results in few tutorials, minimal documentation.

Erlang

Pros:

Green threads. Super easy threading and message passing syntax.

Agner package manager.

Multiplatform (Mac, Windows, Linux).

Triq makes unit testing a breeze.

Inspired a cool NoSQL database, CouchDB.

Cons:

Unintuitive syntax overall. Line endings include blanks, commas, semicolons, and periods.

Having to specify function arity.

Syntax like Haskell’s, but bludgeoned over the head a few times. Let’s make functional programming arduous.

Disorganized docs.

Poor scripting support. erl hates shebangs and is oblivious of recursive calls until a module is compiled.

The command to quit erl is top secret. It’s actually q().

Too many package managers, and some packages are only found in specific package systems.

Processing.js

Pros:

Built-in animation library.

Faster than Java applets.

Less platform-restricted than Flash, not a dying language like Flash.

Not flash.

Multiplatform: Runs in a browser.

Cons:

Runs in a browser.

Slow.

Not well documented.

Perl

Pros:

Quick to code.

Excellent POSIX support.

Multiplatform. Mac, Windows, Linux. Comes with Mac and any Linux.

CPAN package manager, with very many libraries.

Many books and tutorials.

Ubiquitous.

Cons:

Inconsistent syntax. Example: lists that contain lists.

Objects have to be “blessed”.

Syntax so cryptic, there are yearly obfuscated code competitions.

Though ubiquitous, not well-supported in industry due to obfuscation.

Hard to debug due to obfuscation and shallow error traces.

Scheme

Pros:

Smaller, more consistent standard library than Common Lisp.

Functional.

Major implementations (Racket, Chicken Scheme, MIT Scheme) are multiplatform (Mac, Windows, Linux) and have good package managers.

Rack has many tutorials.

Chicken Scheme has super easy stand-alone executable creation.

SRFIs are implementation-independent libraries full of useful functions.

Cons:

Books tend to be too technical.

“Racket” changes its name on a whim. Also known as MrEd, DrScheme, MzScheme, and PLT Scheme.

Obscure.

Smalltalk

Pros:

Took OO ideas from Simula and ran with them.

Squeak and GNU Smalltalk are popular implementations.

Squeak has an excellent GUI interface for examining objects.

Everything’s an object, even booleans.

Cons:

Squeak only runs inside a VM. No command line.

Obscure.