Live data from Hacker News

Loopless Programming

code.jsoftware.com

111–120 of 129 posts

Re: Loopless Programming

#111
post #86

Earlier quoted context omitted.

> safe to assume Assuming that because something is popular it must be good is an example of assuming that things are as they should be, or deriving ought from is[1]. Assuming that because something is unpopular, it must be "wrong" is worse. Do you make all your technical decisions based on what is most popular? Do you always assume that whatever has not become popular must be "wrong"? [1]: https://en.wikipedia.org/w…

Except I'm not assuming it's wrong because it's unpopular. Read the original comment, I clearly stated why it's wrong. My last comment was giving you a possible explanation as to why the witnessed behavior has occurred. Also, please show me one successful software package (and by successful, I mean largely consumed by consumers and a product leader) that does not use looping techniques. Like all technical decisions,…

> Except I'm not assuming it's wrong because it's unpopular. Read the original comment, I clearly stated why it's wrong.

Except you clearly are. The only other reason stated in the original post seems to be "because it's similar to what the hardware does", which in my opinion is completely irrelevant - how does that in any way change how useful it is to program with?

> Also, please show me one successful software package (and by successful, I mean largely consumed by consumers and a product leader) that does not use looping techniques.

Must functional programming languages have no loop construct or using loops is heavily discouraged.

> Like all technical decisions, they are made by using the most correct and appropriate choice.

I don't believe that you're naive enough to think that one decision is correct in all scenarios, or that programming paradigms cannot evolve over time.

> Which is why the industry has been using pre and post condition loops since the beginning.

Congrats, we're back to "it's popular so it's good".

Re: Loopless Programming

#112

That table if alternatives to loops is really interesting. I wonder if there is a similar table for C++ in some form on another website?

cppreference.com

The Standard Library algorithms explicitly implement such a taxonomy.

Re: Loopless Programming

#113

Earlier quoted context omitted.

From someone who has experience in mostly SQL, Python, Linux commands, and a smattering of other languages that I've played with (Haskell, Common Lisp, F#, Ada, Prolog, Julia, Forth, Fortran...etc) I can say that J and modern APL systems are completely different in a lot of ways. Yes functional languages have a lot built around map/fold/filter that is very similar to J's tacit programming, but the implementation make…

It seems to me like it is terse because this is a DSL for dealing with vectors and arrays of numbers. Sure the equivalent C for loops are a lot more wordy for the problems that this language solves, but you'll drive yourself crazy trying to write a simple event loop for your GUI in J.

You're not too far off in my opinion. Yes, you can write beautiful code dealing with arrays, scalars, and matrices, but as you pointed out...it breaks down for other tasks. Opening files in J uses numeric handles that if I recall look something like this (5:!1) which is a little weird, but perhaps not hard once you learn it. It should be noted that Dyalog APL has easier to use primitives for CSV, JSON, SQl, and XML. It also has full interop with .NET on Windows including GUI. J also has GUI capabilities that people use, but it did not appear straightforward.

Re: Loopless Programming

#114
post #102

Swift provides many of the required Collection operators to go loopless - map, reduce, flatMap, compactMap (eliminate nil values), filter, first, contains, prefix/suffix, ... there’s even an OSS library that gives a compile time guarantee that a Collection is non-empty. There are only some instances where I ever need a loop: - map cannot produce a Dictionary, so Dictionary manipulations usually require a loop - Somet…

> - map cannot produce a Dictionary, so Dictionary manipulations usually require a loop Assuming you meaning mapping over a list, some sort of fold function could produce a dictionary, in some languages, such as Elm. [1] [1] https://package.elm-lang.org/packages/elm/core/latest/List#f...

[deleted]

Re: Loopless Programming

#115
post #58
post #11

> Looping - performing a computation repeatedly - is what programs do. In most computer languages, all loops are expressed by one of two statements: > Do While - repeat a code block until a condition is met > For - repeat a code block, with a loop index indicating how many times the block has been repeated. > Programmers trained on scalar languages have spent many years internalizing the Do-While and For paradigms. D…

It's disappointing to see someone aggressively defending their ignorance like this. It's okay if you don't understand what the article is saying, but it's unfortunate that you are blaming that on the article. Maybe your time would be better spent solving some coding challenges in J or another array language like Dyalog APL, Kona, or A+, then comparing your solutions with others’ using the same language, rather than p…

I agree with you on the fundamentals but that first paragraph isn't helpful. The second paragraph is fine.

I suffer from the same annoyance about the same thing, so I know where you're coming from; I still do it myself and ought to moderate my own comments when I do. But blunt statements about others' ignorance only lead to pain instead of pleasure, and drive people further away. Not only does accuracy in such blunt statements not help, it makes their effects considerably worse. One of my teachers had a Ph.D. in psychology from Stanford and told me that he learned one thing from his Ph.D.: punishment is not good for learning.

In case it helps with bona fides, we're somewhat licentious about bending the rules in favor of APL and its family on HN. Of the great alternative programming universes (Lisp, Forth, Prolog, ?) it is surely the least understood.

Re: Loopless Programming

#116
post #115
post #58

Earlier quoted context omitted.

It's disappointing to see someone aggressively defending their ignorance like this. It's okay if you don't understand what the article is saying, but it's unfortunate that you are blaming that on the article. Maybe your time would be better spent solving some coding challenges in J or another array language like Dyalog APL, Kona, or A+, then comparing your solutions with others’ using the same language, rather than p…

I agree with you on the fundamentals but that first paragraph isn't helpful. The second paragraph is fine. I suffer from the same annoyance about the same thing, so I know where you're coming from; I still do it myself and ought to moderate my own comments when I do. But blunt statements about others' ignorance only lead to pain instead of pleasure, and drive people further away. Not only does accuracy in such blunt…

I appreciate the feedback! I'm not a user of J or APL in any regular way, but I feel that there's something going on there that I don't understand (and, due to spreadsheets serving APL's 1970s constituency better than APL did, perhaps nobody ever will). I suspect that J itself is fatally flawed, but I don't understand its merits well enough to be sure how to fix it.

My frustration comes from the quality of the discourse rather than from some feeling that my favorite language is being slighted. Perhaps it's unfair of me to be so demanding of others when I'm so often stubbornly ignorant myself, but I would like people to just not post middlebrow dismissals of this sort (and to tell me when I'm doing something similar); they make rational discussion impractically difficult to find in the interstices between the aggressive posturing. (As inimino said, https://news.ycombinator.com/item?id=21302174 "This is why we can't have nice discussions about programming languages." I believe that's actually true.) Can you imagine biologists attempting to discuss the evidence about the evolution of a particular signaling pathway at a conference where Creationists are shouting that evolution doesn't create new species?

Clearly the folks voting on HN have different preferences.

I want to emphasize that it's not the poster's cluelessness that I'm criticizing. Everyone starts out clueless about everything and stays that way about most things; there is nothing wrong with that. Nor is it their willingness to spout off about their cluelessness — expressing your misconceptions is very often the quickest way to get people to correct them, which happened in this case; both inimino and I wasted our time laying some deep knowledge on the dude. Rather, it's their persistent refusal to notice their own lack of understanding — and the public approbation of that refusal — that I think poisons the well of rational discourse. That's what reminded me of my encounter with Kent Hovind on the streets of Berkeley.

Think, by contrast, of Leibniz's ideal: Quando orientur controversiae, non magis disputatione opus erit inter duos philosophos, quam inter duos computistas. Sufficiet enim calamos in manus sumere sedereque ad abacos, et sibi mutuo (accito si placet amico) dicere: calculemus. Think of the pleasant collegiality that in fact exists among mathematicians, where a few minutes of discussion commonly suffices to convert an opponent into an ally, and the youngest and least experienced can point out an error made by the most respected with the full expectation that their correction — if correct — will be gratefully accepted. In this case, at the other extreme, we have a controversy which is easily resolved with three minutes watching YouTube, but which instead spawned a long thread of aggressive comments, complete with boasts about how easy it is to understand while loops. This is the kind of thing that led to JWZ's famous gibe.

How can we foster an environment more like Leibniz's ideal, if not by pointing out the most egregious discrepancies in behavior? Perhaps my arrogance is not the way — this is IIRC why you didn't want to work with me at Skysheet — but what is?

Re: Loopless Programming

#117

Earlier quoted context omitted.

You can say this now but not long ago map/filter/reduce were almost esoteric.

I'd say even just 5 years ago they were weird FP features, with LINQ being the most mainstream version. Now Go is the only mainstream language without them hehe.

You can write your own LINQ in Go with a very short program. See https://github.com/nukata/linq-in-go for example.

Here is a self-contained excerpt:

  type Any = interface{}

  type Enumerator func(yield func(element Any))

  // Select creates an Enumerator which applies f to each of elements.
  func (loop Enumerator) Select(f func(Any) Any) Enumerator {
    return func(yield func(Any)) {
      loop(func(element Any) {
        value := f(element)
        yield(value)
      })
    }
  }

  // Range creates an Enumerator which counts from start
  // up to start + count - 1.
  func Range(start, count int) Enumerator {
    end := start + count
    return func(yield func(Any)) {
      for i := start; i 
Now you can write the following:

  squares := Range(1, 10).Select(func(x Any) Any { return x.(int) * x.(int) })
  squares(func(num Any) {
    Println(num)
  })
  // Output:
  // 1
  // 4
  // 9
  // 16
  // 25
  // 36
  // 49
  // 64
  // 81
  // 100
I'd say it is so elegant in Go!

Re: Loopless Programming

#118
post #18

Tl;dr : APL has implicit loops because almost everything is an array, and mentioning an array implies a loop to process it. In C++, nowadays, people are encouraged to use Standard Library algorithms in preference to most loops; and to make an algorithm out of any loop that can't be cleanly replaced with a Standard one, and call that. The reasoning is similar to that explained in the article, except that saying which…

From what I've read, your last paragraph is true, but only because the naming often isn't necessary. The importance of abstraction in a codebase that is 60 pages of code is high, but it fades away if the equivalent J program can be 5 pages of expressions. Instead of defining some numerical operation that is only 5 characters long, just use the 5 characters in the 2 to 3 places where it is needed in your 5 pages of co…

The naming is never necessary, in any language. Even where a function is called, the name may be uninformative.

A name is an opportunity to provide useful information about intent to the reader. Open-coding, however concise it may be, fails to communicate intent.

Re: Loopless Programming

#119
post #116
post #115

Earlier quoted context omitted.

I agree with you on the fundamentals but that first paragraph isn't helpful. The second paragraph is fine. I suffer from the same annoyance about the same thing, so I know where you're coming from; I still do it myself and ought to moderate my own comments when I do. But blunt statements about others' ignorance only lead to pain instead of pleasure, and drive people further away. Not only does accuracy in such blunt…

I appreciate the feedback! I'm not a user of J or APL in any regular way, but I feel that there's something going on there that I don't understand (and, due to spreadsheets serving APL's 1970s constituency better than APL did, perhaps nobody ever will). I suspect that J itself is fatally flawed, but I don't understand its merits well enough to be sure how to fix it. My frustration comes from the quality of the discou…

At the risk of taking this too meta... there's something interesting here about online communities like HN.

In everyday human interactions, we have a lot of contextual and social cues about who is more experienced, respected, expert, even who is older; in short, all kinds of social hierarchical information that guides and constrains our behavior. Online, especially in a community of sufficient size that most interactions are between strangers, as here, we lack these cues and must approach each other as equals, or at least as unknowns. It's very democratizing, and sometimes it's incredibly aggravating.

There are things a professor can say to a student that a student can't say to a professor. The professor can police students' behavior and ask a student to leave. So we would not expect this kind of "aggressive defense of ignorance" in a classroom, because there is someone there who is responsible for creating a different environment, as part of an effective, millenia-old tradition of inquiry.

The zen master can whack the novice with a stick. Sometimes leading to enlightenment, sometimes just to the master getting some peace.

As with the professor, it's the relationship and the environment that makes this acceptable. You won't get far by telling strangers on the street that they are woefully uninformed, or by whacking them with a stick. Online, we're essentially all strangers on the street.

Certain basic life skills and attitudes can be communicated and acquired almost immediately when you can get whacked with a stick that can hardly be acquired online at all. Online communities seem to be a terrible place to learn humility, for example.

In response to these realities of online engagement, there are community-level and individual-level approaches. Leaving the former aside, as an individual there are two things I find helpful, one is detachment and the other is to remember the audience.

The "wrong on the internet" compulsion maybe comes primarily from expectations developed offline, where we can talk sense into people, generally within some institution that facilitates this (school, church, work, etc) and which generally doesn't exist online. This can be annoying. Perhaps it's this annoyance that largely leads to endless online arguments. Sometimes you want to communicate to someone, gently but unmistakeably, that you know more about the topic at hand than they are likely to learn in the next ten years. This is likely something that would be communicated automatically and invisibly by environment and context offline, but is almost impossible to communicate at all online. Online, the distinguished biologist and the earnest creationist high school student appear to have equal weight, especially to the high school student. Sometimes you feel the need to communicate to someone that their ignorance of the topic is matched only by their ignorance of their own ignorance, but you can't. You wouldn't be heard, the environment doesn't support it, and anyway it looks bad. If we're all as equals, or at least unknowns, the next person who copies your strong style, more likely than not, will lack the experience that justifies it.

Remembering the audience means that any interaction in a public forum is more likely to influence bystanders than the one directly addressed. It's like a debate, in which debaters address each other but actually aim to persuade the audience. Unfortunately this usually means it's all rhetoric and favors shallow attention-getting over deep discussion and exploration, but that's another topic. Anyway, you can reply to the person but aim more to persuade the audience, which in general is bigger and more likely to be swayed by your reasons than someone who is already arguing against them.

Beyond promoting your position, trying to encourage better discourse, from the audience, rather than the person addressed, seems to help.

Re: Loopless Programming

#120
post #116

Earlier quoted context omitted.

I appreciate the feedback! I'm not a user of J or APL in any regular way, but I feel that there's something going on there that I don't understand (and, due to spreadsheets serving APL's 1970s constituency better than APL did, perhaps nobody ever will). I suspect that J itself is fatally flawed, but I don't understand its merits well enough to be sure how to fix it. My frustration comes from the quality of the discou…

At the risk of taking this too meta... there's something interesting here about online communities like HN. In everyday human interactions, we have a lot of contextual and social cues about who is more experienced, respected, expert, even who is older; in short, all kinds of social hierarchical information that guides and constrains our behavior. Online, especially in a community of sufficient size that most interact…

Those are wonderful points, and I really appreciate them. I am persuaded that it is important to set a good example of behavior for the kids. (And, perhaps, for myself when I'm talking about things I'm even more ignorant of than I am about J; an example is linked below.)

There is some amount of "social hierarchical information" available, if you look carefully — the original poster in this thread has "karma" of 47, while you have 2957, I have 12549, and dang has 52985, plus 29993 as gruseom, although that's less visible. But of course most of the people at the Hackers Conference don't have HN accounts on here at all, so this is at best a poor guide; and, even for those hackers with accounts on the site, surely it would be a grave error to consider me senior to, say, lutusp, lispm, davewiner, Arnt, tonyg, kens, masswerk, or DonHopkins, simply because my account has higher karma. An even more extreme example is my friend johncowan, who has 6 karma and is one of the major authors of R7RS.

High karma is perhaps more an indicator of the kind of poor impulse control that results in wasting our time trying to educate the deliberately clueless, or in my case just going off half-cocked on topics I don't know enough about, than of actual seniority. All of the people in that list are more accomplished hackers than I am, but they have less karma in large part because they post less, perhaps because they're hacking.

To some extent, spelling, vocabulary, and punctuation are similar signals, but consider https://news.ycombinator.com/item?id=20404735, written by someone who apparently really knew what they were talking about, in depth, in a way that I absolutely did not — "Lol" or no "Lol". And even at best those indicators only serve to indicate social background and literacy, which are only weakly correlated with competence.

I wonder if there is at least something we could do to make voting more thoughtful; for example, put the voting arrows at the end of the comment rather than its beginning, or even after all the replies to the comment. (People could collapse the replies to find the arrows if they were really determined to vote without looking at the responses.) Or use a PageRank-style or Advogato-style trust metric rather than raw vote count, so that the votes of people like the ones I listed above would count for more; or, like lobste.rs, request a reason for downvoting. Fundamentally, though, I think there's a kind of insuperable conflict between thoughtful discussion and hair-trigger interactivity. Long comments rarely get many votes, either up or down, because they take too long to read.

I'm really sick of seeing thoughtful comments like vkou's in https://news.ycombinator.com/item?id=20395050, mine in https://news.ycombinator.com/item?id=20276994, and eloff's in https://news.ycombinator.com/item?id=20275006 (although it was mistaken) punished by downvotes and even flags like we're filthy spammers.

Again, I really appreciate your thoughtful reply. Maybe we should set up an "Old Hats" mailing list or something for discussions like these. Maybe it's possible to rescue HN from the "finance-obsessed man-children and brogrammers" JWZ refers to.

Post reply on HN