Generic Programming and Type Parameter

2023. 11. 12. 17:40·개발

What is Generic Programming?

- Generic programming is a style of computer programming in which algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provides as parameter.

 

Type parameter?

- Type parameter like 'T' in TypeScript, are a fundamental aspect of generic programming, a programming style where algorithms are written in terms of types to-be-specified-later. These parameters allow you to rite flexible, reusable functions and clases that work with any type.

 

Basics of Type Parameters

1. Generic Functions and classes : Type parameters are used in the definition of generic functions, classes, or interfaces. They act as placeholders for the types that are passed in when the function is called or the clas is instantiated.

 

2. Syntax : In typescript, type parameteres are typically named with single uppercase letters like 'T','U','V', but they can have more desriptibe names. They are defined using angle brackets('<>') 

 

Why use type parameters

1. Type safety: enable you to write code with better type safety. The typescript compiler can enforce correct usage of the types passed to generic functions or classes.

2. Reusabillity : They increase code reusabillity. You can write a function or a class that works with any type, avoiding code duplication for different types.

3. Flexible Yet Strict : Generics provice a way to use types flexibly while sill maintaining strict type check. The actual type for a type paramter is determined at the time of invocation or instantiation.

 

 

저작자표시 비영리 (새창열림)

'개발' 카테고리의 다른 글

0. HTTP란?  (1) 2024.07.28
Typescript Custom Decorator  (1) 2024.02.03
Typescript Type narrowing  (0) 2023.11.12
Static and non-static(instance) methods  (2) 2023.11.12
NestJs - Mircoservices  (2) 2023.11.08
'개발' 카테고리의 다른 글
  • 0. HTTP란?
  • Typescript Custom Decorator
  • Typescript Type narrowing
  • Static and non-static(instance) methods
senyalog
senyalog
개발 블로그 https://github.com/iamyunjuda
  • senyalog
    Senya의 개발 블로그
    senyalog
  • 전체
    오늘
    어제
    • 분류 전체보기 (77)
      • 일상 (6)
      • 알고리즘 이론 (14)
        • 백준 (8)
      • 개발 (47)
        • Server (7)
        • 인턴 (11)
        • Javascript (0)
      • 경제 (4)
  • 블로그 메뉴

    • Github
    • 홈
  • 링크

    • Github
  • 공지사항

  • 인기 글

  • 태그

    공대생
    알고리즘공부
    C++
    알고리즘
    대학생
    개발공부
    생각
    TypeScript
    백준
    GIT
    백준풀이
    개발
    깃
    컴공
    코딩테스트
    백준문제
    코딩
    개발자
    대학생인턴
    카페
    일상
    공부
    백엔드
    이마고웍스
    MSA
    경제
    nestjs
    인턴
    서버
    인턴생활
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
senyalog
Generic Programming and Type Parameter
상단으로

티스토리툴바