ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 함수형 프로그래밍 설계 -1
    프로그래밍/Java 2017. 6. 29. 00:14
    반응형

    Java에서 Kotlin으로 넘어가야하는 시점에서 함수형 프로그래밍이란 무엇인지 공부를 시작해보려고 한다. 사실 음식도 모르고 먹을때 보다 알고 먹으면 더 맛있듯이 프로그래밍 언어도 알고 사용하면 더 재밌다.

    그래서 일단은 Java8 공부하면서 의식의 흐름을 담아보려한다.


    Lambda란 도대체 무엇인가?

    Lambda란 그리스 문자(Greek Alphabet)로 Λ, λ를 지칭한다. 

    들어갈 (입) 모양의 한자처럼 생겼다. 

    수학 분야에서 사용되고 있고 함수를 표현할 때 사용된다고 한다. 

    f(x)의 f같은 의미인 것 같다. (추측)


    Lambda Expression

    람다 함수, 람다식 같은 표현이다. 프로그래밍 언어 중에서도 익명함수(Anonymous Function)을 의미한다. 나는 막연히 Java에서만 있는 방식인 줄 알았는데 C#이나 스칼라에서도 지향하는 방향이다. 왜 객체지향 Java에서 함수형을 지원하기 시작했냐면, 평소에 사용하는 코드보다 Lambda Expression으로 표현하면 간단하게 표현될 수 있는 방법이 많기 때문이다. (그래서 객체지향인 Java에서는 익명클래스를 Lambda Expression으로 표현하는 방법을 많이 볼 수 있다. 하지만 나는 개인적으로 Builder패턴처럼 사용하는 병렬처리 방식이 더 마음에 든다.)


    C#

    A lambda expression is an anonymous function that you can use to create delegates or expression tree types. By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls.


    Java

    One issue with anonymous classes is that if the implementation of your anonymous class is very simple, such as an interface that contains only one method, then the syntax of anonymous classes may seem unwieldy and unclear. In these cases, you're usually trying to pass functionality as an argument to another method, such as what action should be taken when someone clicks a button. Lambda expressions enable you to do this, to treat functionality as method argument, or code as data.



    위에 말을 짧게 요약하자면 Lambda식 표현이란 내가 원하는 일을 대신 수행해줄 코드를 말한다. 특히 여러 갈래로 작성될 수 있는 함수들을 하나의(고차원) 함수로 만드는 특징을 가진다. (누군가 비슷한 일을 하는 코드를 Ctrl c+v 하지 않아도 내가 작성한 함수를 이용한다는 의미이다..) 

    반응형

    '프로그래밍 > Java' 카테고리의 다른 글

    URL과 URI  (1) 2021.02.15
    가비지 컬렉션 (Garbage collection)  (0) 2020.10.19
    Java Collection  (0) 2015.03.21
    오버로딩(method overloading) vs 오버라이딩(overriding)  (0) 2014.07.30
    이름이 붙은 반복문  (0) 2014.07.29
Designed by Tistory.