5 ms·
map/zip/range isn't cryptic once you get used to it. You start thinking them as additional CS concepts, which you just apply in one "chunk" to problems. This
by nostrademons 13y ago
map/zip/range isn't cryptic once you get used to it. You start thinking them as additional CS concepts, which you just apply in one "chunk" to problems. This is working-as-intended: it's you learning how to think at a higher level so that you can solve more complicated problems quickly. Once you've done this you can actually "back port" this knowledge to traditional programming languages: I often think of Java or C code in terms of "Oh, this is a map" or "this is a fold over a tree traversal".
There are a bunch of other, legit readability problems with typical Haskell style: the fetish on single-character variable names is just nuts (it comes from math, where it's customary because mathematics culture arose before computers and autocomplete), and once you get into point-free style, combinator libraries, and monads/arrows things really get nuts. In general I've found that abstractions should only be used when they're re-used frequently, so you can internalize them, and Haskell tends to encourage rather overzealous abstracting. But map/zip/range show up all the time in typical industrial programming, and learning how to think of it as a unit frees up brainpower to think about higher-level algorithms.
- pekk 13y agoAfter people learn something they don't find it entirely cryptic any more, but that doesn't mean it isn't cryptic. No evidence that using map instead of loops "frees up brainpower."
- porlw 13y agoThere are many common operations in programming, and it's worthwhile building a consistent syntax for them. Over time, as one layer of abstraction solidifies it's possible to see common patterns at the next level up. It saves brainpower because you you don't need to analyse the logic within the structure to understand what the operation is intended to produce. E.g. in the old days: 10 I=1 20 PRINT A[I] 30 I=I+1 40 IF I <= 10 THEN GOTO 20 You need to parse the logic to realise "Ah, this is a for loop". The I variable and the IF statement are bookkeeping code that doesn't have any relevance to the actual effect you're trying to produce. This construct is common enough that the for-loop was developed. Likewise with the if/else construct and others. The old fogeys would say "we don't need this structured programming nonsense, gotos are more flexible. I can easily look at this and understand what's going on". Structured programming is now widespread enough that we don't think of it as anything special, it's just part of "programming" in general. Now there are several common operations that we do when looping over a list of items. Things like maps, folds and gathers are just building another level on top of structured programming, hiding the bookkeeping code and making similar operation similar, so you can concentrate on the unique aspects of the program.
- loup-vaillant 13y agoWhat to you mean by "cryptic"? Something you struggle with? An abstraction? You're not used to maps, folds, and filters (the bulk of sequence comprehension), so they don't free up your brain power. But seriously, they're not complicated, and using them instead of regular loops often reduce the amount of code by a factor of 3 to 5. Simple code, where the same idioms come back over and over —just like in regular loops, only shorter. Don't tell me that doesn't free brainpower, eventually.
- emsy 13y agoCryptic to me means that I have to translate (decrypt) the code in order to understand it. I have no problem when list comprehension is used to achieve a simple, single goal. But when I see whole algorithms implemented with list comprehension, I find that rather stupid. Amount of code is not my most important metric when writing code. Time is. I don't care if code is 3 to 5 times smaller when everybody that encounters it need 10 times longer to understand it.
- loup-vaillant 13y agoAssembly was cryptic in the same sense: you had to translate it to get to the "real" machine code. Fortran was cryptic in the same sense: you had to perform even more complex translation to get to the "real" assembly. In other words, you're doing it wrong. You think in sequential terms, loops… and are translating list comprehension to that. Just don't. There are more direct ways. In a list comprehension, there's generally a filter part, and a map part. While they are interleaved during the execution, they are logically separate, and you should think of them that way. I once specified the processing of a sequence of data as a pipe of maps and filters. A colleague came to me and told "how can you waste all that memory, generating all those lists around?". Dude, this is a specification of the end result, not a computational model. Of course I won't generate 10 big arrays. Simply put, you need to separate the "what" from the "how".
- seanmcdirmid 13y agoFunctional orgami is hella hard to debug. Their is a reason functional programming relies so heavily on equational reason and pure FP relies heavily on static typing: the alternative, actually debugging programmers, is so painful that you just want to avoid that at all costs. A loop is way easier to debug than a filter or a map, you just step through it. Who cares about code length? Haskell doesn't become a usable language until someone comes up with a decent dataflow debugger, if that's even possible.