Introduction

<< >> Contents Help

# 1. Introduction

This book will tell you enough about J for you to use it as a language for developing serious applications, but it is about more than learning the J language: it is also about 'thinking big' in programming, and how programming in J is fundamentally different from programming in C. C programs deal intimately with scalars (single numbers and characters), and even when they combine those scalars into arrays and structures, the operations on the arrays and structures are defined by operations on the scalars. To ensure that each item of an array is operated on, loops are created that visit each element of the array and perform a scalar operation on the element.

Writing code in a scalar language makes you rather like a general who gives orders to his troops by visiting each one and whispering in his ear. That touch-of-Harry kind of generalling can achieve victorious results, and it has the advantage that the orders can be tailored to the man, but its disadvantages are significant: the general spends much mental energy in formulating individual orders and much breath in communicating them individually; more significant, his limited attention is drawn toward individuals and away from the army as a whole. Even the great Rommel was overtaxed at times.

The J programmer is, in contrast, a general who stands before his army and snaps out orders to the army as a whole. Every man receives the same order, but the order itself contains enough detail for the individual men to act appropriately. Such a general can command a corps as easily as a platoon, and always has the 'big picture' in mind.

OK, maybe you're not Rommel, but you are a working programmer, and you suspect that very few practical programs can be represented as array operations—matrix multiplication maybe, or adding a list of numbers—and that, even if a wide range of programs were possible, the set of operations supported must be too vast to be practical: wouldn't we need an array operation for every possible program?

The first half of this book is devoted to showing you that it is indeed possible to write meaningful programs with array operations. We take the approach of looking at the different ways loops are used, and seeing what facilities J has for producing the same result using array operations. We will find that J contains a couple of dozen array-processing primitives and a dozen or so very cleverly chosen pipe-fittings that allow those primitives to be connected together to provide the limitless supply of array-processing functions needed for practical programming.

Interspersed with the elaboration of more and more intricate array operations are treatments of other matters of use in practical programming: structure definition, input and output, performance measurement, calling DLLs, modular programming. Eventually we will see how to use if-then-else and do-while in J, though you will have learned more elegant ways to get the same results.

The last portion of the book is devoted to the optional topic of tacit programming, J's language for functional programming. Tacit programming is an extremely terse way of expressing algorithms, one that allows programs that have been compressed from a page of C into a few lines of J to be compressed still further.

<< >> Contents Help