General Question

Hobosnake's avatar

Do any other fluther users use J (the programming language)?

Asked by Hobosnake (796points) August 22nd, 2010

So I’ve been getting into learning J and it’s just amazing. It’s a bit difficult to learn though due to its difference from the typical C++/Java/etc. clone today, but that’s what makes it awesome; as not only can it do so much more in so much less code; you can confuse experienced programmers with the code itself.

Are any other flutherites using/learning J?

Observing members: 0 Composing members: 0

16 Answers

Vortico's avatar

Interesting. How can it confuse experienced programmers, and how is this an awesome thing?

Also, is this one of those languages great for mathematics and scientific computation?

phaedryx's avatar

I’ll provide a link: http://www.jsoftware.com/

J is too terse and unreadable for my tastes. However, I’m going to follow this thread because I’m curious how others feel about it.

If I were learning J, I’d use http://projecteuler.net/

Hobosnake's avatar

@phaedryx I’m struggling to learn it myself. It confuses experienced programmers at first glance because the syntax has very very little in common with the typical Java/C clone that is most commonly seen today. Types don’t need to be specified nearly as often, and operators are much more plentiful and usually follow a more complicated symbol format involving one or two characters and can be monadic (such as ^:5, meaning 5 squared) or dyadic (such as 4%2, meaning 4 divided by 2). Also interesting is the array-focused nature of J, and its capability of functional-level programming.

While I know all that, I can’t say I’ve written much code with it.

@Vortico To answer your question regarding mathematics and scientific computation, it is amazing. Whereas most languages’ primitives are severely limited when it comes to very large or specific numbers, J can have numbers hundreds of digits long. I used it to find the factorial of 52 (for which I only had to write !52x, the x puts the number in standard notation rather than scientific). It also supports complex numbers (the square root of one).

This is one of those times I want to make a futurist remark, but I’ll be careful. This has a TON of potential though. More people need to discover J.

Vortico's avatar

@Hobosnake I’m still a little skeptical. Python and Mathematica do everything you’ve mentioned, including dynamic typing, arbitrary precision, and complex mathematics.

In Python:

>>> (1j+2) ** 2
(3+4j)
>>> import math
>>> math.factorial(52)
80658175170943878571660636856403766975289505440883277824000000000000L

And in Mathematica:

(1 I + 2)^2
3 + 4 i
52!
80658175170943878571660636856403766975289505440883277824000000000000

Hobosnake's avatar

@Vortico Really? I actually started with python but didn’t learn much about it. I doubt the ease of using arrays still applies, but whether or not that is the case, I know they aren’t function-level. I’m not really trying to convince you to learn J, I’m just kind of conveying my interest and wondering if anyone shares it.

phaedryx's avatar

@Hobosnake
good luck, J is a fairly unknown language that hasn’t caught on beyond a few niche applications.

Hobosnake's avatar

@phaedryx thanks! Yeah I tried to learn it several months ago but mostly gave up on it. Now that I’ve found some books on it (thankfully there’s a free online one), I think I’ll be able to learn it this time.

Vortico's avatar

@Hobosnake Python is actually pretty decent for arrays and other forms of lists of data. They may be of the form [1, 34, “stuff”, -6.5914] or {“firstname”: “Bob”, “lastname”: “Smith”, “IQ”: 87}.
Lists can be accessed and manipulated in many ways, and the array sizes and datatypes aren’t picky like in C or Java.

Python isn’t used in all scientific areas, but it’s definitely enough for what my needs are.

I really feel like I’m taking over the thread now, so I apologize. :(

Hobosnake's avatar

@Vortico Haha don’t worry about it. I’m interested in any input. I guess the main way J is praised is for its conciseness. It kind of requires a different way of thinking though, which is why a lot of experienced programmers don’t switch to it, but its users claim the difficulty of making the switch is entirely worth it.

As examples I’ll give a squidoo article and a downloadable book designed for C programmers wanting to learn J. At least read the intro to see where I’m coming from.

Hobosnake's avatar

@Vortico also, arrays are easy in J for different reasons than they are easy in Python. For example, to set up a list of numbers you simply need to set up a sequence of numbers separated by spaces, such as

p =. 0 1 2 3 8 9 4

to make a multi-dimensional array, you simply need to specify dimensions using the $ operator dyadically (arguments on either side) in the following format

p =. 3 3 3 $ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 (...) 27

(although a list such as this one could be more easily created by invoking the primitive i. monadically – single argument – with the number 27, which is usually used to cycle through arrays without the use of a loop)

p =. 3 3 3 $ i.27

The above array would be displayed (by simply writing the array name alone on a line) as:

0 1 2——9 10 11——18 19 20
3 4 5——12 13 14—- 21 22 23
6 7 8——15 16 17—- 24 25 26

(with better spacing, of course).

arrays of any dimensions are a bit like matrices in that they can simply be added together, provided they have the same dimensions:

1 2 3 + 4 5 6

yields the result

5 7 9

Single (0-dimensional) arrays can also be used with any array with similar ease:

5 * 1 2 3

yields the result

5 10 15

Same goes for other operators and even “verbs” (functions) you design yourself.

Also worth noting are “adverbs”, which modify the verbs themselves, such as the / adverb, which effectively places the verb between each item in a list (as J is an interpreted rather than compiled language, this isn’t exactly what happens; it doesn’t modify the actual compiled code as would a preprocessor directive in C)

as such, the simple verb below would yield the sum of any array:

sum =. +/

similarly, the following verb would return the highest value in any array:

greatestVal =. >./

did I mention the notation for writing functions is that easy?

Vortico's avatar

Woah! That is strange, yet amazingly useful!

Python can add and multiply arrays, but in a completely different manner:

>>> [1, 2, 3] + [4, 5, 6]
[1, 2, 3, 4, 5, 6]
>>> 2 * [4, 5, 6]
[4, 5, 6, 4, 5, 6]

Multiplying the J way could be coded with:

>>> [2 * a for a in [4, 5, 6]]
[8, 10, 12]

This somewhat shows the intended uses for J and Python. Since summing two array elements for each element position would most likely be used for mathematics and other scientific fields, J might be optimized more for that area. Python on the other hand deals with a lot of database access, web apps, networking, and GUIs.

timtrueman's avatar

I think this might be relevant for your consideration: http://www.scipy.org/NumPy_for_Matlab_Users

SciPy/NumPy makes advanced math (such as matrix math) very easy. I’ve used it quite a bit and it’s great and easy to use.

Hobosnake's avatar

Yeah, one thing I guess I’m trying to figure out with this question is if or how well J handles GUIs, reading/writing files, Graphics, etc. At any rate, however, it’s a pretty badass calculator, if such a thing exists :D.

Vortico's avatar

@Hobosnake I looked through the J Software website, and it doesn’t look like it’s designed for GUIs. Not to worry about though, because command-line is probably good enough for the people who write in J. Maybe a Java or C wrapper is available for the GUI if needed.

Read/write, I’m sure. Graphics. Maybe, but I don’t think you’re using it for the right application if you need that.

For a badass calculator, you really can’t beat Mathematica. It’s extremely difficult to get a hold of you don’t have connections with a university, but it’s worth trying. ($3000+ without education discount). For simple one-line calculations as opposed to multi-line programs, Wolfram Alpha is a great demonstration of the computing power behind Mathematica.

Hobosnake's avatar

@Vortico let’s say I were able to obtain an education discount; how much would it cost me then, just out of curiosity?

Vortico's avatar

I got mine for $140 on a Standard license. Compare this to the cost of a textbook, and it’s close to nothing. :)

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther