Functional programming and non-functional programming

后端 未结 8 1397
情书的邮戳
情书的邮戳 2020-11-28 18:02

In my second year of University we were \"taught\" Haskell, I know almost nothing about it and even less about functional programming.

What is functional programming

8条回答
  •  情深已故
    2020-11-28 18:25

    I find What Is Functional Programming? to be useful

    Functional programming is about writing pure functions, about removing hidden inputs and outputs as far as we can, so that as much of our code as possible just describes a relationship between inputs and outputs.

    Prefer explicit when param

    public Program getProgramAt(TVGuide guide, int channel, Date when) {
      Schedule schedule = guide.getSchedule(channel);
    
      Program program = schedule.programAt(when);
    
      return program;
    }
    

    over

    public Program getCurrentProgram(TVGuide guide, int channel) {
      Schedule schedule = guide.getSchedule(channel);
    
      Program current = schedule.programAt(new Date());
    
      return current;
    }
    

    A functional language is actively hostile to side-effects. Side-effects are complexity and complexity is bugs and bugs are the devil. A functional language will help you be hostile to side-effects too.

提交回复
热议问题