[Kotlin 깃북] Ch3 코틀린 사용을 위한 기본 문법 3. 조건문

0
post-thumbnail

[Kotlin 깃북] Ch3 코틀린 사용을 위한 기본 문법

3. 조건문

주석

  • // 한줄: 한 줄을 주석 처리할 때 사용
  • /*여러 줄*/: 여러 줄에 걸쳐서 주석 처리할 때 사용
  • 📌/**문서화*/: 자동화 툴을 사용해서 문서화할 정보를 작성할 때 사용

참고자료

📌Kotlin 코드 문서화를 위한 주석 작성 방법

  • 출처: Kotlin 코드 문서화를 위한 주석 작성 방법

  • Kdoc 주석: Kotlin에서 문서화에 사용되는 주석 형식

    • JavaDoc과 유사한 형태를 가짐
    • 함수, 변수, 클래스 등 Kotlin 코드 문서화하는 데 사용
  • Kdoc 주석을 사용하여 코드를 문서화하는 이유?

    • 코드를 이해하고 사용하기 쉬워짐
    • 코드 유지보수 및 개발시간 단축
  • Kdoc 주석 작성 방법:

    • 일반적으로 변수, 함수, 클래스 등 선언 위에 작성
    • 문서화 주석 형식 이용 (/** ... */)
    • 주석 내부에 변수, 함수, 클래스 등의 이름과 설명, 매개변수와 반환값 등 정보 포함
  • Kdoc 주석 작성 유의할 점:

    • 주석 내부 설명 최대한 간결하게 작성
    • 변수, 함수, 클래스 등의 이름과 설명: 명확하게 작성
    • 매개변수와 반환값에 대한 설명: 최대한 자세하게 작성
    • 모든 요소에 대해 주석 작성할 필요는 X
  • 클래스 문서화 Kdoc 주석 예

/**
* This is a class that represents a person
* @property name The person's name
* @property age The person's age
*/
class Person(val name: String, val age: Int){
	//class Implementation
}
  • 함수 문서화 Kdoc 주석 예
/**
* This is a function that adds two integers
* @property a The first integer
* @property b The second integer
* @return The sum of teo integers 
*/
fun add(a:Int, b:Int):Int{
    return a+b
}
  • 변수 문서화 Kdoc 주석 예
/**
* This is a variable that represents the maximum value
*/
val MAX_VALUE = 100
  • Enum 문서화 Kdoc 주석 예
/**
* This is a enum class that represents a color
* @property colorCode The code of the color
*/
enum class Color(val colorCode: Int){
    RED(0xFF0000),
    GREEN(0x00FF00),
    BLUE(0x0000FF)
}
  • 파일 문서화 Kdoc 주석 예
/**
* This is a Kotlin file that contains some utility functions
*/
package com.example.utils
profile
Be able to be vulnerable, in search of truth

0개의 댓글