6 ms·
> Looping - performing a computation repeatedly - is what programs do. In most computer languages, all loops are expressed by one of two statements: > Do While
by NOGDP 7y ago
> 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. Discarding these paradigms is the biggest re-think they need to make when they learn J.
A lot of languages have these kinds of semantics and arguably in a more streamlined / better organised way - Haskell typeclasses for example. I don't know if it's true that 'most languages' only support for/while loops, but probably not. It also doesn't take 'many years' to internalise for/while loops, these are fairly basic constructs which are learned by most novices in the beginning of an introductory programming course.
> (x + y) is an expression rather than a statement. The J programmer can embed (x + y) in a larger expression, perhaps a matrix multiplication (w +/ . * (x + y)) which adds the equivalent of three more nested loops, but is still a single expression. Expressions can be combined; statements cannot.
(x + y) is going to be an expression in almost any language...
> Many modern languages have iterators, which slightly streamline the For loop, but without addressing its fundamental deficiencies.
What are the 'fundamental deficiencies'?
This seems like a pretty low-effort write-up.
- esotericn 7y ago> It also doesn't take 'many years' to internalise for/while loops, these are fairly basic constructs which are learned by most novices in the beginning of an introductory programming course. The comment is referring to the patterns becoming ingrained in the mind through years of use, not that learning how to produce a while loop for the first time takes years.
- NOGDP 7y agoThere's not much to be ingrained after you learn how for/while loops work, and there's not much in the way of learning how map/filter, or overloaded functions work. I wouldn't even consider the overloaded '+' operator as a loop, you can think of it as a single operation, it's an implementation detail.
- inimino 7y ago> (x + y) is going to be an expression in almost any language... But the equivalent for loop is not.
- NOGDP 7y agoIt is wherever '+'/(equivalent function) overloading is a thing - C++, Haskell, Rust, etc. There isn't even a good reason to think of it as a loop, because for different types it may not be a loop at all.
- inimino 7y agoYou seem to have missed the point of the original remark that (x + y) is a statement, and you're missing the point of my clarification. > "(x + y) is an expression rather than a statement". The point isn't that (x + y) wouldn't be a statement in other languages, rather than point is that in languages the reader of the article is most likely to be familiar with, you would use a for loop to solve the problem, and obviously a for loop is a statement, not an expression. You can't compose statements as you can expressions. That was the only point the article was making there. You clearly missed it, because you went on saying that (x + y) is an expression in almost any language, which while true, is irrelevant for languages where (x + y) isn't the way you would express the operation in question. Which, by the way, includes idiomatic C++, Haskell, and Rust, in all of which overloading (+) to do something so specific would at best be seen in a purpose-specific library (like numpy) only, but isn't automatically present in the language. That means it doesn't force you to think in that way, which J does, which is the point the article is making. In most languages that most programmers use, for loops are common, and if all of those are replaced by expressions, you get a more expressive language (for dealing with arrays). That's the point that the article is making, and you haven't addressed it at all.
- DougBTX 7y agoJ has a big focus on array manipulation, the libraries in Rust for arrays provide implementations of the Add trait, so I’d disagreed that it is not “idiomatic” https://docs.rs/ndarray/0.13.0/ndarray/struct.ArrayBase.html#impl-Add%3CB%3E https://docs.rs/ndarray/0.13.0/ndarray/struct.ArrayBase.html...
- Stratoscope 7y agoJust FYI, the code-formatted block quotes in your comment need a lot of horizontal scrolling both on mobile and desktop because of the very long lines. Unfortunately HN doesn't provide any kind of nice formatting for block quotes, so it's understandable that people try to use code formatting for this. Sometimes commenters will use code formatting with manually entered line breaks, e.g. keeping lines to 72 characters or less. But that is still hard to read on mobile devices. Instead of code formatting using leading spaces, here's a good alternative for block quotes (the '>' goes in the first column, no leading spaces): > *A paragraph of block quoted text.* This renders as: > A paragraph of block quoted text. If the quote has * characters within it, don't try to italicize it, just do this: > A paragraph of block quoted text. which renders as: > A paragraph of block quoted text. Either way the quoted text will be wrapped correctly on any device. Give each paragraph its own '>' indicator and a blank line between them so they don't get wrapped together. In case you don't get a chance to edit your comment, here's a more readable copy: - - - - - - - > 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. Discarding these paradigms is the biggest re-think they need to make when they learn J. A lot of languages have these kinds of semantics and arguably in a more streamlined / better organised way - Haskell typeclasses for example. I don't know if it's true that 'most languages' only support for/while loops, but probably not. It also doesn't take 'many years' to internalise for/while loops, these are fairly basic constructs which are learned by most novices in the beginning of an introductory programming course. > (x + y) is an expression rather than a statement. The J programmer can embed (x + y) in a larger expression, perhaps a matrix multiplication (w +/ . * (x + y)) which adds the equivalent of three more nested loops, but is still a single expression. Expressions can be combined; statements cannot. (x + y) is going to be an expression in almost any language... > Many modern languages have iterators, which slightly streamline the For loop, but without addressing its fundamental deficiencies. What are the 'fundamental deficiencies'? This seems like a pretty low-effort write-up. - - - - - - - (end of reformatted version of NOGDP's parent comment, please direct any replies to the original)
- kragen 7y agoIt'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 posting voluminous comments about how your lack of understanding means there's nothing to understand. It probably won't change your life, but it might be a useful tool in your mental toolbox when you're using more mainstream languages like R, SQL, or Octave; libraries like TensorFlow, Numpy, Pandas, PyTorch, or parts of Boost; or hardware like GPUs or processors with NEON and SSE. (Related: Blub.)
- NOGDP 7y agoAre you trying to address anything I've said, or just ranting for another reason?
- kragen 7y agoBless your heart. The former.
- chris_wot 7y agoIn that case, maybe you might like to make an attempt at addressing his points.
- kragen 7y agoThere's no point in trying to explain things to someone who's aggressively defending their ignorance. (I have lots of experience being the aggressively ignorant guy.) Step one is realizing other people might know something you don't. After that it becomes useful to talk to you. Someone who's determined to dismiss what they're hearing can always find an excuse—especially in programming, where everything is Turing-complete anyway.