Java the good parts

33
JAVA: The Good Parts 자바 언어의 특징과 활용 방안의 주관적인 탐구 박성철 / SK Planet
  • Upload

    -
  • Category

    Software

  • view

    1.962
  • download

    3

description

이왕 쓰는 자바, 특징을 알고 장점을 잘 살려 보자

Transcript of Java the good parts

Page 1: Java the good parts

JAVA: The Good Parts자바 언어의 특징과 활용 방안의 주관적인 탐구

박성철 / SK Planet

Page 2: Java the good parts

이야기의 시작...

“프로그래밍 언어들을 한 문장으로 소개”http://npcode.com/blog/archives/124

Perl: Perl is a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information

Python: Python is an interpreted, interactive, object-oriented programming language that combines remarkable power with very clear syntax.

Ruby: Ruby is an interpreted scripting language for quick and easy object oriented programming.

PHP: PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

Page 3: Java the good parts

C++: C++ is a general purpose programming language with a bias towards systems programming that * is a better C * supports data abstraction * supports object-oriented programming * supports generic programming

J: J is a modern, high-level, general-purpose, high-performance programming language.

Lisp: Lisp is a programmable programming language.

Java?

자바는 공신력 있고 설득력 있는 한문장 소개를 찾지 못했다. C++ 보다도 정체성이 불분명한 녀석이다.

!

Page 4: Java the good parts

이야기의 시작...

“프로그래밍 언어들을 한 문장으로 소개”http://npcode.com/blog/archives/124

Perl: Perl is a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information

Python: Python is an interpreted, interactive, object-oriented programming language that combines remarkable power with very clear syntax.

Ruby: Ruby is an interpreted scripting language for quick and easy object oriented programming.

PHP: PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

기종기종??검종검종??

Page 5: Java the good parts

이대호 : 이승엽

Page 6: Java the good parts

@자바 백서

자바의 설계 목표

1. 단순함, 객체중심, 친숙함 2. 견고하고 안전한

3. 아키텍처 중림성과 이식성 4. 고성능 5. 인터프리터, 쓰레드, 동적

http://www.oracle.com/technetwork/java/index-136113.html

May 1996

James GoslingHenry McGilton

언어

VM

Page 7: Java the good parts

언어로서의 자바

1. 단순함, 객체지향, 친숙함 2. 견고하고 안전한

Page 8: Java the good parts

단순함, 친숙함

2.2.1 No More Typedefs, Defines, or Preprocessor2.2.2 No More Structures or Unions2.2.3 No Enums2.2.4 No More Functions2.2.5 No More Multiple Inheritance2.2.6 No More Goto Statements2.2.7 No More Operator Overloading2.2.8 No More Automatic Coercions2.2.9 No More Pointers

Java = C/C++ - WTF

Page 9: Java the good parts

견고하고 안전한...

견고성 = 정적static 타입컴파일러가 타입을 확인

안전성 = 엄격한strong 타입실행 중에 타입 확인

Page 10: Java the good parts

Unit testing isn't enough. You need static typing too.http://evanfarrer.blogspot.ca/2012/06/unit-testing-isnt-enough-you-need.html

말하길...

1. 정적 타이핑은 버그를 탐지하기엔 불충분하며, 단위 테스트를 해야 한다. 2. 단위 테스트를 장착하고 나면, 정적 타입 확인은 과잉이다. 3. 정적 타이핑은 유효한 프로그램을 오류로 분류하기도 하므로 해롭다.

사용자가 많고 테스트가 잘 장착되어 있는 파이선 오픈소스 프로젝트 네 가지를 하스켈로 1:1 포팅했더니...

The Python NMEA Toolkit: 9 오류 MIDIUtil: 2 오류 GrapeFruit: 0 오류 PyFontInfo: 6 오류

Page 11: Java the good parts

정적 타입의 또 다른 장점도구 지원

Page 12: Java the good parts
Page 13: Java the good parts

IDE

Eclipse, IntelliJ IDEA, Netbeans

* FEED BACK * 자동 완성 / 자동 제안 * 리팩터링 지원 * Boiler plate code 자동 생성

Page 14: Java the good parts

정적 코드 분석

`

잠재적 결함

낭비/과잉

잠재적 결함

빈 분

기문

테스트범위

중복

복잡성

자학

코딩 표준

PMDCheckstyleFindBugsJdepend...

Page 15: Java the good parts

객체 중심 프로그래밍

InterfacePackageEnumGeneric

Page 16: Java the good parts

인터페이스Interface

Alan kay

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme` late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.

시뮬라 67 : 범용 언어 = 알고리듬 표현 + 코드 분해프로그램을 작은 독립된 프로그램의 조합으로 보자레고 블럭

스몰토크 : 메시징생물의 세포

Page 17: Java the good parts

패키지Package

디렉토리이름 영역Namespace

모듈 : 응집의 단위

기본 가시성이름이 없어 잊혀진 존재package-private (또는 package-protected)

public < protected < package-private < private

캔트백Kent Beck과 에릭 감마Erich Gamma의 가시성 토론은익 정보 단위 테스트

Page 18: Java the good parts

내부 클래스Inner Class

클래스 = 파일 원칙 위배 (자바 1.1에서 추가)

패키지

클래스

내부 클래스

메서드

블럭

Page 19: Java the good parts

열거형Enum

C++에서 일부러 가지고 오지 않았던 특징

Java Enum = Class = Type Safe 이름 영역Namespace이 기본 제공설계 패턴 중 상태 패턴State Pattern 적용 가능

지네릭Generics

C++(template)에서 유보한 특징

알고리듬이 처리할 타입을 사용시에 지정코드 재사용 기술Object는 안녕

하지만 복잡한 상황이 생기기도...

Page 20: Java the good parts

By Jean-Michel BAUD (CC BY-NC-SA 3.0)http://images.cdn.fotopedia.com/7dctrd1a20m9m-hiXb-5pBiH4-hd.jpg

JVM 3. 아키텍처 중림성과 이식성 4. 고성능 5. 인터프리터, 쓰레드, 동적

Page 21: Java the good parts

인터프리터Interpreter

자바는 인터프리터 언어아키텍처 중립성, 이식성동적 로딩 & 바인딩 : 클래스 로더 파이선과 유사한 실행 구조

.java → .class → JVM

.py → .pyc(or .pyo) → PVM

UCSD Pascal(UCSD p-System, 1978)이 모델

자동 메모리 관리Garbage Collector

Lisp에서 나온 개념

신뢰성 향상클래스와 메모리 관리 분리 - 순수한 객체메모리 누수 문제 경감

성능 혁신의 핵심

Page 22: Java the good parts

리플렉션코드의 메타데이터를 다루는 기술

메타데이터 : java.lang.Class, java.lang.reflect.Constructor, java.lang.reflect.Field,java.lang.reflect.Method

interface Walkable { void walk(); }interface Swimmable { void swim(); }interface Quackable { void quack(); }… as(Walkable.class, p).walk(); //OK, person has walk() methodas(Swimmable.class, p).swim(); //OK, person has swim() methodas(Quackable.class, p).quack(); //Runtime Error, person does not have quack() method... static <T> T as(Class<T> t, final Object obj) { return (T) Proxy.newProxyInstance(t.getClassLoader(), new Class[] {t}, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { return obj.getClass().getMethod(method.getName(), method.getParameterTypes()) .invoke(obj, args); } catch (NoSuchMethodException nsme) { throw new NoSuchMethodError(nsme.getMessage()); } catch (InvocationTargetException ite) { throw ite.getTargetException(); } } }); }

Java duck type 예:

- 위키 백과 에서

Page 23: Java the good parts

메타 프로그래밍Meta Programming

다른 프로그램을 생성하거나 조작하는 프로그램을 작성하는 행위

* 선행 처리예) AspectJ

* 컴파일러 확장APT(Annotation Procession Tool) & Pluggable Annotation Processing API (JSR 269)예) Lombok

* 리플렉션 | 바이트 코드 생성/조작예) Spring Framework DI + AOP

“It is about programming at the meta level, that is about changing your interpreter or changing how code is compiled”

- 랄프 존슨Ralph Johnson

Page 24: Java the good parts

다 언어 프로그래밍Polyglot

JVM은 Java만의 VM이 아니다.Byte code라면 원천을 따지지 않고 실행

80:20 (또는 80:10:10) & 도구의 법칙DSL

위키 백과 JVM 언어 목록http://en.wikipedia.org/wiki/List_of_JVM_languages

Clojure, Groovy, Scala, Kotlin, JRuby, Jython, Rhino 등 90여개

Java 공식 지원 JSR 292: Supporting Dynamically Typed Languages on the Java PlatformJSR 232: Scripting for the JavaTM Platform

"It's not the progress I mind, it's the change I don't like".

- 마크 트웨인Mark Twain

Page 25: Java the good parts

중력 탈출

http://ko.fotopedia.com/items/flickr-2539421151

Page 26: Java the good parts
Page 27: Java the good parts

자바는 관리자가 좋아하는 언어?

There are heavier-weight object-oriented languages and the elephant in the room is sort of Java, you can't really make a list of modern languages without talking about it. Java is sort of the Cobalt of the 21st century, I think. It's kind of heavyweight, verbose, and everyone loves to hate it, though not everyone will admit that. But managers kind of like it because it looks like you're getting a lot done, you know, if 100 lines of Java code accomplish a task, then it looks like you've written 100 lines, even though in a different language, it might only take 5 lines. You know, it's like, you know, you can eat a 1-pound steak or you can eat, you know, 100 pounds of shoe leather and you feel a greater sense of accomplishment after the shoe leather, but, you know, maybe they're some downsides

- 래리 웰Larry Wall

Page 28: Java the good parts
Page 29: Java the good parts

코드의총량

상위 구조 재사용

하위 기능 재사용

실 작성 코드량

Page 30: Java the good parts

언어 확장 : Library자바는 언어적 한계를 설계로 해결하도록 합니다. 그래서 좀 수다스럽고 번거롭지만 지금까지는 21세기의 코볼 역할을 잘 하고 있어요. - 박성철

Calendar now = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Set<Calendar> set = new LinkedHashSet<Calendar>(); for (String element : list) { if (element != null) { try { date = dateFormat1.parse(element); } catch (ParseException e) { throw new SomeException(e); } Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date.getTime()); if (!calendar.after(now)) { set.add(calendar); } } }

Set<Calendar> set = Op.on(list).toSet().forEach().exec(FnString.toCalendar("dd/MM/yyyy")).get();

막 코딩

OP4j 사용

Page 31: Java the good parts

구조 재사용 : 프레임워크투기성 개발에 지나치게 빠지면 소프트웨어 건강에는 해롭다. 최악의 형태가 프레임워크다! 원래 나쁜 의도였던 건 아니지만, 투기성 개발의 병증을 분명히 보여주는 존재다. 자바는 다른 어떤 언어보다 특히 병세가 심하다. - 닐 포드Neal Ford

프레임워크의 진화

1. 프레임워크는 실제로 애플리케이션을 구축하기 위해 반복적으로 적용 가능해야 한다.

2. 성공적인 프레임워크를 만들기 위한 최선의 접근 방법은 프레임워크를 염두에 두지 않는 것이다.

3. 프레임워크의 추상 클래스 및 인터페이스의 목록, 이들 간의 관계는 사전 설계가 아닌 경험을 기반으로 해야 한다.

http://aeternum.egloos.com/2640343

Spring Framework!!!

Don Roberts, Ralph Johnson

Page 32: Java the good parts

내게 자바는?

이일민(Toby)“객체지향으로 인도하는 언어? (딴짓 못하게 다 막고...)”

이상민(집필좋아)“자바는 계속 진화하는 언어다” & “자바는 밥벌이다?”

차민창(Min Cha)“자바란 단순하고 깔끔한 언어라고 생각합니다. 단순함과 깔끔함이 장점이지만 한편으로 한계일 수도 있는 것 같기도 하네요.”

황장호(rath)“엔터프라이즈 환경 (아니 뭐 꼭 기업이라기보다 뭐 좀 진지하게 뭐좀 해보려는) 에서 무난하게 쓸 수 있는 언어중에 제일 자료도 많고 툴도 많고 쉽고 제일 쉬운게 자바같아요.”

“로우레벨도 아니고 하이레벨도 아닌데, 어쩌다보니 현실에선 로우레벨이 된... 좀 로우한 감이 많아서 노동은 많지만, 그래도 "그러한" 요구사항들을 충족하면서도 쉬운.”

김해영(geekinside)“딸을 유치원에 보내주는 고마운 언어”

Page 33: Java the good parts

공식 자바 정의?

The Java programming language is a general-purpose concurrent class-based object-oriented programming language, specifically designed to have as few implementation dependencies as possible.

자바 프로그래밍 언어는 범용 병행 클래스 기반 객체 중심 프로그래밍 언어다. 특히 가능한 별다른 조건 없이 다양한 환경에서 동작하도록 설계 되었다.