News for hackers. Stuff that matters.
Re:Why I Prefer Functional Programming by 0xcoffee on Thursday September 19, 2019 @04:56PM (#21020678)
Obligatory C#:

    var input = new string[] { "abc", "ab", "abcdef", "abcdefgh" };
    var maxLength = input.Select(e => e.Length).Max();
    var output = input.Select(e =>
    {
        var padding = (maxLength - e.Length) / 2;
        return new String(' ', padding) + e;
    });
Most modern `oop` languages these days all support functional constructs and achieve the same thing in same amount of code & style. Language and oop/functional style are not mutually exclusive anymore, which this article seems to overlook by comparing both languages and styles at the same time.
Re:Why I Prefer Functional Programming by fnord123 on Thursday September 19, 2019 @05:51PM (#21021077)
This looks like the Java if the Java was written by someone who knows Java:

    List<String> alignText(List<String> texts) {
      int maxLength = texts.stream().mapToInt(String::length).max().orElse(0);
      return texts.stream().map(text -> {
        var spaceCount = (maxLength - text.length()) / 2;
        return " ".repeat(spaceCount) + text;
      }).collect(Collectors.toList());
    }
Re:Why I Prefer Functional Programming by p2t2p on Friday September 20, 2019 @03:46AM (#21024144)
/nit Move the lambda to private method and replace it with method reference and it’ll be just perfect
Re:Why I Prefer Functional Programming by fnord123 on Friday September 20, 2019 @05:36AM (#21024827)
Good feedback. +1
Re:Why I Prefer Functional Programming by n4r9 on Friday September 20, 2019 @08:51AM (#21026101)
I tend to avoid doing a Select followed straight by a Max when you can just pass the select function directly into the max. Also multiline lambda expressions feel ugly but that's probably just me! This is what I would do these days:

    string pad(this string e, int padLength) => new String(' ', padLength) + e;
    var input = new string[] { "abc", "ab", "abcdef", "abcdefgh" };
    var maxLength = input.Max(e => e.Length);
    var output = input.Select(e => e.pad((maxLength - e.Length) / 2));
Re:Why I Prefer Functional Programming by rienbdj on Friday September 20, 2019 @01:59AM (#21023674)
Sadly C# is still missing a few important ML features that making functional programming more difficult than in a true ML.
Re:Why I Prefer Functional Programming by n4r9 on Saturday September 21, 2019 @05:04AM (#21034271)
It would be interesting if you could mention which feature/s you think it most sorely lacks. Some of the recent syntax additions have made it really easy to write concise functional code. I don't even use curly braces much anymore. What about f#?