I think this most effectively demonstrates why I like a lot of OOP: it can be verbose. This is example function is relatively illegible: alignCenter :: [String] -> [String] alignCenter xs = map (\x -> replicate (div (n - length x) 2) ' ' ++ x) xs where n = maximum (map length xs) One of the most verbose languages I've used, Objective C, has made this a best practice. Despite the brackets (which scare people off), it…
Why I Prefer Functional Programming
11–20 of 163 posts
Re: Why I Prefer Functional Programming
#12It feels like a false choice and you can have rich FP capabilities in a language that supports objects and relationships between objects.
Re: Why I Prefer Functional Programming
#13I don't see why "Object Orientated Programming" requires for loops, over map / streams (which Java has). Is there a definition of "OOP" which requires using for/while? This doesn't really sure any OOP at all. A better example would be to show a case where OOP would be useful, say having a base class and deriving it several times (iostreams for example). Show me how FP does somewhere where (traditionally) OOP is consi…
Though I've noticed that programmers these days often equate OOP with classes. Therefore anything with classes is OOP whereas anything without isn't. This comes up a lot with languages, such as Rust, that are OOP but lack the class keyword.
Re: Why I Prefer Functional Programming
#14I'm sticking to procedural coding for the next 10 years and I will try my best to unwash young coders from poop.
Re: Why I Prefer Functional Programming
#15 void alignCenter(String[] text) {
int maxLength = 0;
for (String line : text) maxLength = Math.max(maxLength, line.length());
for (int i = 0; i
No lambdas to be found.Re: Why I Prefer Functional Programming
#16You can write mutation-style java tersely too... void alignCenter(String[] text) { int maxLength = 0; for (String line : text) maxLength = Math.max(maxLength, line.length()); for (int i = 0; i No lambdas to be found.
Re: Why I Prefer Functional Programming
#17I think this most effectively demonstrates why I like a lot of OOP: it can be verbose. This is example function is relatively illegible: alignCenter :: [String] -> [String] alignCenter xs = map (\x -> replicate (div (n - length x) 2) ' ' ++ x) xs where n = maximum (map length xs) One of the most verbose languages I've used, Objective C, has made this a best practice. Despite the brackets (which scare people off), it…
Personally I like to combine both approaches. In swift I would write something like this:
let l = ["abc", "ab", "abcdef", "abcdefgh"]
width = l.reduce(0, { max($0, $1.count) })
let centered = l.map({
(line: String) -> String in
var padding = (width - line.count) / 2
return String(repeating:" ", count: padding) + line
})Re: Why I Prefer Functional Programming
#18Re: Why I Prefer Functional Programming
#19I think this most effectively demonstrates why I like a lot of OOP: it can be verbose. This is example function is relatively illegible: alignCenter :: [String] -> [String] alignCenter xs = map (\x -> replicate (div (n - length x) 2) ' ' ++ x) xs where n = maximum (map length xs) One of the most verbose languages I've used, Objective C, has made this a best practice. Despite the brackets (which scare people off), it…
Re: Why I Prefer Functional Programming
#20I prefer functional programming because referentially transparent functions are easier to reason about and test. Brevity of control flow hasn't brought me much benefit.