views:

977

answers:

8

I came across J/K/APL a few months ago while working my way through some project euler problems, and was intrigued, to say the least. For every elegant-looking 20 line python solution I produced, there'd be a gobsmacking 20 character J solution that ran in a tenth of the time. I've been keen to learn some basic J, and have made a few attempts at picking up the vocabulary, but have found the learning curve to be quite steep.

To those who are familiar with these languages, would you recommend investing some time to learn one (I'm thinking J in particular)? I would do so more for the purpose of satisfying my curiosity than for career advancement or some such thing.

Some personal circumstances to consider, if you care to:

  • I love mathematics, and use it daily in my work (as a mathematician for a startup) but to be honest I don't really feel limited by the tools that I use (like python + NumPy) so I can't use that excuse.
  • I have no particular desire to work in the finance industry, which seems to be the main port of call for K users at least. Plus I should really learn C# as a next language as it's the primary language where I work. So practically speaking, J almost definitely shouldn't be the next language I learn.
  • I'm reasonably familiar with MATLAB so using an array-based programming language wouldn't constitute a tremendous paradigm shift.

Any advice from those familiar with these languages would be much appreciated.

+5  A: 

I think your 3 points show that you don't NEED to learn J. However, I can't think of any situation where learning a new language is harmful.

Taking time to learn something you are interested in (or any new language) always improves your other programming skills. You learn different approaches to problems that you may be able to implement differently with other languages.

Plus, with the minimal syntax of J, it would be a good language to ensure you are getting correct results when you implement a solution in another language.

JTA
+17  A: 

Thousands of years ago, I was an APL programmer. By thousands, I mean back in the '70's when the custom character set meant we had special printing terminals with the APL keyboard and character set, and IBM selectric typeballs with the special characters, etc.

I went to a lecture by Ken Iverson on "Why APL Was Cool".

His thesis was this. Once upon a time long division was a serious mathematical undertaking, reserved for graduate students. Notation for things like repeating decimal expansions involved a large pile of mathematical symbolism. Once upon a time even something like a "negative" number was required elaborate notation.

Over the years -- as we came to a better understanding of these abstractions -- we came up with much more compact notation for complex concepts.

The point of APL (and J and K) is to summarize big algorithms into tidy notation.

Nowadays, I'm a Python programmer. I find that my early exposure to APL warped my brain by forcing me to ask "what's this mean?" and "is this a reusable operation?" and "what's a pithy summary for all this algorithmic fluff?"

Also, as I pursue the Project Euler problems the "functional programming lite" of Python backed by my "Gin-soaked recollections of APL" are both very helpful in tackling the exercises.

S.Lott
Thanks for that Steven - will be interesting to see how much it affects my own Python. Also if you don't mind me asking, what is your username on Project Euler? Do you post your Python solutions?
ozan
On ProjectEuler, I'm "slott". No, I don't post my solutions. I'm only level 1, right now -- I have two to go to get to level 2.
S.Lott
+1 for thousands of years ago. But never give details - that just spoils the fun.
Jesse Millikan
I don't know... "back in the '70's" "Ken Iverson" sounds like details to me. I guess I could say "Syracuse University". But too much starts to get tedious. What details do you think are necessary?
S.Lott
+5  A: 

I used to work as an APL programmer for several years back in the 1970s. I love the language, but have not used it for years.

It is a great language for some things, but I really can't invision using it for web development for example.

What it is great for is statistical and matrix operations. You can solve a liner programming problem in 3 characters. It is much easier to prove the correctness of that LP implementation than one which takes pages in C for example.

So if you want to learn it for the joy of learning, I say go for it. To enhance your job prospects, well there are probably lots of other things to learn which will impress a potential employer more.

JonnyBoats
In finance, knowledge of Q/Kdb+ can be quite a resume helper
Scott Weinstein
+4  A: 

Back in the eldar days I was an APL language developer, coding in 370 assembler. I ported J to OS2, but never learned how to use it for real work. I'm currently working in Java and PHP and was evaluating Python. After the first 3 sections of the Python tutorial I was struck by the many similarities it had to APL, that brought me here.

I'd strongly recommend learning APL or J as an intellectual exercise. It will change your way of thinking about programming (warp your brain) and probably help your Python coding. Also there are a few jobs out there for APL and J programmers, and probably less programmers than jobs.

+3  A: 

I make my living with APL since 1980. I am looking foward to continue to do so for some more years to come. It's not only great fun to use APL, the language offers outstanding debugging features. Modern implementations are fully fledged functional languages and are object-oriented as well.

I met many people over the years asking me how long I guess I would be able to continue with APL. Those guys were dbase and PL/1 and ALGOL and Pascal and Forth and C and Focus and other programmers. Got it?!

+2  A: 

J is a bit like a genie: it needs to be kept inside a bottle. Maintaining a lot of batch software in J is a serious pain. Maintaining interfaces (Windows or web based, because yes, you can setup J to answer to Apache to produce a web output) in J is an experimental, little known circle of hell.

On the other hand, using J is fine if you want to: parse, sift, analyse, crunch, etc some data to fiddle with it, to figure out the fine grain of an algorithm, or to impress the internets with the shortest possible way to calculate how many triangles fit in a circle or what not.

I came very close to adding J as a deal breaker on my careers profile on careers.stackoverflow.com, but I ultimately left it out. To me, using J is fine, producing J, however, is not.

EDIT:

That was a while ago. I still think poorly of complete J solutions in production (that is, all your MVC). Since the original response, I've used J as a COM in a C# project, where J is provided with a large matrix that would be clunky to manage in C#, with great satisfaction.

Part of our work is to make data models and code speak. It's not easy bridging that quality and J's very terse syntax. Several frameworks, unlike J, have easy-to-work-with IDE's, and have enough support to allow one to arrange code in a humanly readable way. J's über-matrix capabilities do not compensate for what it lacks.

MPelletier
+3  A: 

I have worked in J and APL for most of the last 25 years and can thoroughly recommend both. I still revert to one or the other when I have any form of ad-hoc data analysis to do and I have used it in Project Euler as well.

If you are interested in Project Euler then J is definitely the one to choose. Its support for infinite precision integers and primes make it a very good fit.

Duncan
+4  A: 

J is my primary programming language for Project Euler and for personal use at work. I've never come across a better language for array processing, and the tacit programming paradigm is both useful and thought-provoking once you get the hang of it. (Useful because it's thought-provoking, in fact.) Reaching entry-level competence in the language is difficult, and reading other people's code is an intellectually disciplined activity, but perseverance has major payoffs because of the language's power, flexibility and conciseness.

That said, the reason why I reserve it for personal use at work is that (1) nobody else at work uses it, (2) the learning curve is steep enough so that it's not reasonable for me to ask my colleagues to pick it up, and (3) the fact that you can build intricate programs in one line of code makes it challenging to read a line of code, especially if you didn't write it yourself. (I expect to spend at least half an hour studying a line of code that uses ten or more operators, unless they were used in such a way that I understand the underlying principles thoroughly.)

Some examples of fun J features:

1) Any function defined to operate on a single number can be made to operate on arrays of arbitrary rank. For example:

totient=: * -.@%@~.&.q:

NB. Finding the totient of 10
totient 10

NB. Finding the totient of all numbers from 1 to 10
totient"0 (1+i.10)

It's exactly the same function, just operating on the atoms (single-element components) of a 1xN input array. Similarly, you can take a function defined to work on rank-two arrays (matrices) and apply it to any array of higher rank just by using the " (rank) conjunction.

2) You can take just about any theoretically invertible function in J and invert it by 'iterating it backwards'. For example,

NB. Converts an array of binary digits to a decimal number
(#.) 1 0 1
5

NB. Converts a decimal number to an array of binary digits
(#.^:_1) 5
1 0 1
estanford