Apr-04-2019, 04:46 AM
(Apr-04-2019, 03:44 AM)micseydel Wrote: If you like functional programming, you might want to checkout Scala. It doesn't have break or continue for its loops, some might find that frustrating but it sounds right up your alley :)That sounds like a great tip, Mic. I've heard of Scala and glanced at a Scala program or two, so I'll learn more about it because you like it. For me, THE language to admire us Haskell because you can write gorgeous code in it. I could hardly believe my eyes when I read a recursive quicksort that some clever programmer crammed into three lines. But I beauty won't convince any thoroughly practical programmer to trade, say, C++, for concise elegance. I prefer theory to practice. Since I've stopped programming professionally, I don't need to care what languages are popular in the industry.
(I actually today wanted to use one of those constructs in Scala, noticed that it could be re-written in a more functional style, and proceeded to do that instead. Also Scala does have some utilities for simulating a break or continue I think, they're basically just exception handling.)
qsort :: (Ord a) => [a] -> [a] qsort [] = [] qsort (x:xs) = qsort less ++ [x] ++ qsort more where less = filter (<x) xs more = filter (>=x) xsTo shorter that program, you move the filter function calls to the lined with the ++, concatenation, operators on it and leave out the line with the "Ord" on it. Since the program is polymorphic, your computer can use it to sort any sortable data.
I feel almost embarrassed to admit that before I tutored computer science students, I programmed professionally in Cobol. Since then, the standard probably has changed to remove the "alter" statement, a truly evil invention. When Cobol first came out, main memory was tiny. To save it, the altar statement would make the machine do something awful.
After you typed "ALTER 250-PRINT-PAYROLL-REPORT" TO PROCEED TO 350-CALCULATE-STATE-INCOME-TAX.", each time the program seemed to tell the machine to print the payroll report, it would calculate the income tax instead. So if you wanted to torture your enemies, you could include a file full of alter statements to make the program behave unintelligibly. The trick is to hide the alter statements from the reader.
I haven't pulled that sadistic stunt.