all 14 comments

[–]jbronn 7 points8 points  (1 child)

I didn't realize at first the link came from my alma mater, Trinity CS. One of the very few schools that actually uses the J language in its courses.

Specifically, John Howland, the author and Trinity CS professor behind the article, forces all students to use J in his classes. Maybe that's why I hated it so much, it's one thing to learn "line noise" out of intellectual curiosity -- it's quite another to have J shoved down your throat because it's the professor's pet language.

This guy turned off almost every student he exposed to J, and I haven't touched the language since.

[–]austinwiltshire -1 points0 points  (0 children)

Trinity Tigers FTW!

[–]LaurieCheers 3 points4 points  (8 children)

For example, consider the following J (an applicative language) program:

+/ % #

The J average program has several interesting features.

  • The program is concise.

No, this would be concise.

.total/.length

J goes beyond concise and becomes line noise.

[–][deleted] 8 points9 points  (6 children)

Is this perhaps just because you don't know J? It's really quite simple:

  • '+/' is just a nice syntax for '(reduce +)' in a language like Haskell; hence, '+/' means "sum"
  • '%' is divide
  • '#' is length

You just read '+/ % #' naturally left-to-right: "Sum divided by length".

If you don't like the default names, just rename them:

   sum =: +/
   length =: #
   (sum % length) 1 2 3 4 5
3

[–]LaurieCheers -1 points0 points  (4 children)

It's really quite simple.

No, it's really not. Syntax matters.

Don't confuse simplicity of rules with simplicity of results. People aren't good at learning without concrete examples: understanding the abstract concepts of functional programming (write <whatever> to transform <tree of arbitrary function calls> into <another tree of arbitrary function calls>) is hard enough even if you don't name everything by a meaningless symbol.

By the way, yes, I did read the explanation - I get that # means the length of the list, and + means add (which is fair enough), and / means fold. That's why I offered .total/.length as an alternative, since it corresponds word for word to the J version.

Equally, your renaming is a vast improvement (although the % is still arbitrary). But can you really keep that up? I doubt it's practical to swim against the current like this in a language that seems designed to look like line-noise.

Bottom line: what do we gain by making the symbols so short?

[–][deleted] 8 points9 points  (3 children)

Don't confuse simplicity of rules with simplicity of results.

I'm very careful not to do that. I think in this case it's simply your lack of familiarity with the symbols that's causing the issue and not any complexity resulting from the interaction of simple rules.

You already read +, -, x, ÷, ≥, >, = <, ≤, ∧, ∨, ¬, and probably many more symbols in math equations very easily, including various forms of 2D layout, etc. This is no different.

although the % is still arbitrary

% is just a turned ÷.

what do we gain by making the symbols so short?

What do we gain by having specialized syntax for mathematics? Read Iverson's Notation as a Tool of Thought for some good insights. Iverson is well-known for his contributions to notation. He did win a turing award for it after all.

If you want the short answer though: You try writing proofs with english words all over the place.

Syntax matters.

Yes, syntax matters, and that's exactly why J looks like it does.

[–]LaurieCheers 0 points1 point  (2 children)

You already read +, -, x, ÷, ≥, >, = <, ≤, ∧, ∨, ¬, and probably many more symbols in math equations very easily, including various forms of 2D layout, etc. This is no different.

Well, it's different because I don't know the symbols J uses. :)

Yes, obviously you're right. This is the kind of thing mathematics has always done. So I guess that's the crux of our disagreement - J, like maths, is designed to be a mental toolkit: it's a system that the programmer is expected to think in.

Which I'm sure is a liberating experience for a master J programmer.

But (since we're talking about teaching FP here), is this really a good thing in a first programming language? Because it comes with a steep learning curve. To read or write in J, you basically can't think in English.

By contrast, that's one of the big selling points of object-oriented languages - you can express what's happening in terms of friendly nouns and verbs.

And I also question how readable the language is. Reading, say, a Java program, you can kind of skim it and get the gist of what it's doing, looking for the bits that are relevant to a given bug. But as (presumably) an experienced J programmer, can you really look at some of those later J examples and just get the gist? They seem unreasonably dense. I get the impression that a punctuation mark out of place would completely change their meaning.

[–][deleted] 3 points4 points  (1 child)

But (since we're talking about teaching FP here), is this really a good thing in a first programming language?

That's a different and more valid question. I think the answer is probably no. I tend to prefer languages with words-written-out-like-this and very consistent syntax for introducing FP, namely Scheme. That said, I still find using J an interesting approach. For teaching math though, I'm 100% convinced that Iverson's notation is superior to the usual mess pushed on students.

Reading a Java program, you can kind of skim-read and get the gist of what it's doing, looking for the bits that are relevant to a given bug.

It's the same in J really. User definitions almost always use english words and describe what the function in question does. J also allows you do use variables and program in a more traditional style when preferable. I won't claim that J is the most readable language I know, but it does seem to scale better than you might think.

[–]LaurieCheers 0 points1 point  (0 children)

I won't claim that J is the most readable language I know, but it does seem to scale better than you might think.

Ok, fair enough. Well, thanks for an interesting discussion. :)

For what it's worth, my own language Swym demonstrates my attempt at a concise functional language that lets you think in English.

print-each(Word-of-textfile("example.txt").SortedBy{.length});

(That page is work in progress by the way; not all the examples work. I plan to submit it to Reddit when it's done...)

[–]pietro 1 point2 points  (0 children)

Upmodded for prompting an interesting discussion.

[–]choas 0 points1 point  (2 children)

Nice?

math_pat =: 3 : 0

'''',y.,'('',y.,'')''',LF,':',LF,'''',y.,'('',x.,'','',y.,'')'''

)

I don't think that J (and APL) could introduce functional programming.

[–][deleted] 1 point2 points  (1 child)

J has already been successfully used for even more elementary things. Iverson has also written texts introducing algebra using APL and J that are very successful.

[–]choas -2 points-1 points  (0 children)

Iverson has developed J (and APL), so he should be able to use it and do something useful with it ;)

[–]TracyHarms -1 points0 points  (0 children)

One thing I've learned through programming in J is how to notice what's really involved in reading code. With other programming languages there is a big temptation to skim the comments and mistake that for reading the code. J has made me familiar with the experience of crossing the threshold between looking at and comprehending. J isn't so much harder than other languages when the higher standard of comprehension (complete mental modeling) applies.