Live data from Hacker News

Loopless Programming

code.jsoftware.com

1–10 of 129 posts

Re: Loopless Programming

#3
I recall another language that was trying to do something similar. In most languages you have to decide about x:1 versus x:* relationships very early and it’s a painful refactor to go back and fix it. This one tried to fix it as well so that much of the time you only changed the variable declaration and the code just worked.

jQuery made a similar observation, and many of its functions are list comprehensions. If they had chosen a different default behavior for empty lists I might still be championing it today. But the silent failures were a bitter pill to swallow.

In fact I sometimes still fantasize about building a mini front end framework containing the inverse behavior and some other more modern ideas.

Re: Loopless Programming

#4
You see some of this with Numpy, where a +, for instance, has been overridden to mean addition of n dimensional arrays, and Numpy is foundational for a lot of the data science programming these days

Re: Loopless Programming

#5
post #3

I recall another language that was trying to do something similar. In most languages you have to decide about x:1 versus x:* relationships very early and it’s a painful refactor to go back and fix it. This one tried to fix it as well so that much of the time you only changed the variable declaration and the code just worked. jQuery made a similar observation, and many of its functions are list comprehensions. If they…

x^n includes x^1

Re: Loopless Programming

#6
post #3

I recall another language that was trying to do something similar. In most languages you have to decide about x:1 versus x:* relationships very early and it’s a painful refactor to go back and fix it. This one tried to fix it as well so that much of the time you only changed the variable declaration and the code just worked. jQuery made a similar observation, and many of its functions are list comprehensions. If they…

x^n includes x^1

Those weren’t exponents and this sounds like a non sequitur.

Also variance disagrees with you. A function that takes a single value may be generalized to take multiple values but it’s harder for a caller that expects a single value in return to be faced with multiple answers.

If I ask for your shipping address and get three, I can’t send the package to three places. I have to change the workflow quite a bit.

Re: Loopless Programming

#7
As far as explicit loops, I probably use write out a loop once a month and maybe not even that often. Using map/filter/reduce [as well as sugar funcs until/any/all] solves virtually all the common cases of working with lists. Granting it's not sufficient if you're writing specialized code like sorting arrays efficiently, but for general development, going higher-order is the way to go.

Re: Loopless Programming

#8
See also: array programming [0] (apparently 1970s APL, on which J is based, didn't even have explicit for/while loops).

Nowadays even common imperative languages have higher-order functions, so I don't find it very exciting. Though still quite handy in R and similar languages where you deal with array-like structures almost all the time.

[0] https://en.wikipedia.org/wiki/Array_programming

Re: Loopless Programming

#9

J is one of the strangest programming languages I've ever tried. I would reccomend giving it a go, though I wouldn't personally write actual software in it.

I recommend trying APL or K instead.

APL has weird symbols, so forces you to abandon any previous notions.

K is super minimalistic so easy to keep in mind.

But J is both huge and very different but uses e.g. brackets as individual characters (not in pairs) and other things that break your visual pattern matching. So it’s a lot more effort, IMO

After you have grokked it, if you like it - then, by all means do look at J. It is in many ways a purified APL albeit with ascii only characters, and a few decisions that look good on paper but less so in practice (like forks and trains)

I don’t write APL or K or J myself, but my C code (and some of my Python) is dramatically changed as a result of working with K in the past — it is dramatically simpler and faster, although less idiomatic for those languages.

Re: Loopless Programming

#10
post #7

As far as explicit loops, I probably use write out a loop once a month and maybe not even that often. Using map/filter/reduce [as well as sugar funcs until/any/all] solves virtually all the common cases of working with lists. Granting it's not sufficient if you're writing specialized code like sorting arrays efficiently, but for general development, going higher-order is the way to go.

I agree, the only time I write a loop out is when I need to break out of it
Post reply on HN