본문 바로가기

TIL

TIL 072423

Q: FBV와 CBV는 각각 무엇이며, 어떤 차이가 있습니까?

A: 

In Django, views are divided into two major types; function-based views (FBVs) and class-based views (CBVs).

FBV

함수 기반 뷰(Function-Base Views)를 뜻하며, 심플하고 가독성이 좋다.

Function-based views are views in Django that are defined by functions.

http://www.learningaboutelectronics.com/Articles/Function-based-views-in-Django.php

CBV

클래스 기반 뷰(Class-Based Views)를 뜻하며, 상속과 믹스인 기능을 이용하여 코드 재사용하고 뷰를 체계적으로 구성할 수 있다.

A view function, or view for short, is a Python function that takes a web request and returns a web response. This response can be the HTML contents of a web page, or a redirect, or a 404 error, or an XML document, or an image . . . or anything, really. The view itself contains whatever arbitrary logic is necessary to return that response. This code can live anywhere you want, as long as it’s on your Python path. There’s no other requirement–no “magic,” so to speak. For the sake of putting the code somewhere, the convention is to put views in a file called views.py, placed in your project or application directory.

https://docs.djangoproject.com/en/4.2/topics/http/views/

 

Django

The web framework for perfectionists with deadlines.

docs.djangoproject.com

 

https://medium.com/@ksarthak4ever/django-class-based-views-vs-function-based-view-e74b47b2e41b

 

Django : Class Based Views vs Function Based View

Django has two types of views; function-based views (FBVs), and class-based views (CBVs). Django originally started out with only FBVs…

medium.com

https://ssungkang.tistory.com/entry/Django-FBV-%EC%99%80-CBV-%EC%9D%98-decorators-%EC%82%AC%EC%9A%A9%EB%B2%95

 

[Django] FBV 와 CBV 의 decorators 사용법

decorator 는 처음보는 생소할 수 있지만 python 기초 문법입니다. decorator 가 무엇인지 모르신다면 아래 링크를 통해 기초적인 부분을 먼저 공부하고 오시는걸 추천해드립니다. python 장식자, decorator

ssungkang.tistory.com

 

 

 

 

Q: 테스트코드를 작성하는 이유는 무엇이며 어떤 장점이 있습니까?

A: 

8 reasons to write tests

1. Any bugs are found easily and quicker

어떤 버그든지간에 빠르게 더 쉽게 발견할 수 있습니다. 

2. Testing saves time and money

시간과 돈을 아낄 수 있습니다.

3. Testing is an Integral part of extreme programming

익스트림 프로그래밍에서 테스팅이 아주 중요합니다.

CI/CD를 하는 과정에서 이런게 들어갑니다.

test code를 작성하고 push를 해주면 test code가 돌아가면서 알아서 확인을 해주고 그 외 merge와 deploy까지 가는 과정이 CI/CD입니다.

이 과정을 위해서도 테스팅이 아주 중요합니다.

4. Testing provides documentations

테스팅을 작성하는 것만으로도 도큐멘테이션이 됩니다.

도큐멘테이션을 현업에서 되게 중요시 여기는데요,

저희가 작성한 코드, 저희가 작성을 해 놓고도 1년 뒤에 보면은 이게 무슨 뜻인지 읽는데 한참이 걸릴 때가 있습니다.

그런데 남이 작성한 코드는 더더욱 읽기 힘듭니다.

그래서 작성한 코드가 무슨 뜻인지 잘 알기 위해서 꼭 코멘트를 잘 남겨두든가 아니면 리드미를 잘 작성해서 도큐먼트화를 해주는 것이 중요한데

테스트 코드를 작성함으로써 테스트 코드를 보면서 이게 지금 무슨 기능을 하는지 알 수 있다는 장점이 있습니다.

5. Improves Reliability

신뢰도가 높아집니다.

테스트 코드가 있기 때문에 지금 어떤 기능이 제대로 돌아가고 있는지 확인을 할 수가 있습니다.

6. Testing helps gauge performence

퍼포먼스를 체크할 수 있습니다.

뭔가 하나의 기능을 테스트할 때 시간이 얼마나 걸리는지 체크에서 퍼포먼스에 어디에 문제가 있는지도 확인을 할 수 있습니다.

7. Testing improves code coverage

얼만큼 코드가 안전한가에 대한 보장을 해줄 수 있습니다.

8. Testing reduces code complexity

코드의 복잡도를 낮출수 있습니다.

 

https://tamerlan.dev/how-to-test-drf-apis/

 

Introduction to Testing in Django and Django Rest Framework

This article will go over the basics of testing and how to write tests for our Django APIs.

tamerlan.dev

 

'TIL' 카테고리의 다른 글

TIL 072623  (0) 2023.07.26
TIL 072523  (0) 2023.07.25
TIL 072123  (0) 2023.07.24
TIL 072023  (0) 2023.07.20
TIL 071923  (0) 2023.07.19