Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
<100 subscribers
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Share Dialog
Share Dialog
함수 안에 있는 선언들을 모두 끌어올려서 해당 함수 유효 범위의 최상단에 선언하는 것을 말한다.
자바스크립트 함수는 실행되기 전에 함수 안에 필요한 변수 값들을 모두 모아서 유효 범위(스코프)의 최상단에 선언하는 것 처럼 보인다.
자바스크립트 엔진은 코드를 실행하기 전에 실행 컨텍스트를 생성한다.
또한 자바스크립트 엔진은 코드를 실행하기 전 실행 컨텍스트를 위한과정에서 모든 선언(var, let, const, function, class)을 스코프에 등록한다.
이 때 자바스크립트 Parser가 함수 실행 전 해당 함수를 한 번 점검하면서 필요한 값들을 끌어올린다.
그렇다면 변수 선언을 굳이 미리 안해도 되는 것일까?
그렇지는 않다. let/const/class 를 이용한 선언과 *함수 표현식에서는 호이스팅이 발생하지 않는것 처럼 보인다.
그러나 모든 선언에 호이스팅이 발생하는 것은 맞다.
다만 let, const 키워드로 선언된 변수는 스코프의 시작에서 변수의 선언까지 일시적 사각지대(Temporal Dead Zone; TDZ)에 빠지기 때문이다.
여기서 중요한 지점은 이 호이스팅이라는 용어가 ‘선언이 먼저 메모리에 저장되었다.’는 것을 의미하기 때문에(선언이 끌어올려진다’는 의미이기 때문에)
모든 선언은 호이스팅이 일어난다는 말은 참이된다.
뭔가 이랬다 저랬다 하는 것 같으니 정리를 해보자.
다음의 명제들은 모두 참이다.
let foo = 1;
{
console.log(foo); // Reference Error
let foo = 2;
}
위의 코드는 foo 변수의 선언이 호이스팅 되지 않았다면, 에러 없이 동작할 것이다.
왜? 스코프 체인에서 현재 스코프부터 상위 스코프로 이동하면서 foo를 찾을 것이기 때문이다.
그러나 현재 스코프에 foo 선언문이 존재하기 때문에, 호이스팅이 발생했으나 값이 초기화 되지 않아 에러가 발생한다!
console.log(a); // undefined
console.log(b); // Reference Error
var a = 1;
let b = 1;
console.log(func); // [Function : func]
function func() {
console.log("What is Hoisting?");
}
console.log(someFunc); // undefined
var someFunc = function () {
console.log("What is Hoisting?");
}
console.log(arrowFunc); // undefined
var arrowFunc = () => {
console.log("What is Hoisting?");
}
console.log(constFunc); // Reference Error
const constFunc = function () {
console.log("Const Func");
}
자바스크립트 Parser 내부의 동작 방식을 유추해보자면 다음과 같을 것이다.
var a; // [Hoistring] 선언
console.log(a); // undefined;
console.log(b); // Reference Error
a = 1; // 할당
let b = 1; // Hoisting 발생 안함
함수선언문은 코드를 구현한 위치와 관계없이 자바스크립트의 특징인 호이스팅에 따라 브라우저가 자바스크립트를 해석할 때 맨 위로 끌어 올려진다.
/* 정상 출력 */
function printName(firstname) { // 함수선언문
var result = inner(); // "선언 및 할당"
console.log(typeof inner); // > "function"
console.log("name is " + result); // > "name is inner value"
function inner() { // 함수선언문
return "inner value";
}
}
printName(); // 함수 호출
==========================================================================
/** --- JS Parser 내부의 호이스팅(Hoisting)의 결과 - 위와 동일 --- */
/* 정상 출력 */
function printName(firstname) {
var result; // [Hoisting] var 변수 "선언"
function inner() { // [Hoisting] 함수선언문
return "inner value";
}
result = inner(); // "할당"
console.log(typeof inner); // > "function"
console.log("name is " + result); // > "name is inner value"
}
printName();
함수표현식은 함수선언문과 달리 선언과 호출 순서에 따라서 정상적으로 함수가 실행되지 않을 수 있다.
함수표현식에서는 선언과 할당의 분리가 발생한다.
함수 표현식의 선언이 호출보다 위에 있는 경우
/* 정상 */
function printName(firstname) { // 함수선언문
var inner = function() { // 함수표현식
return "inner value";
}
var result = inner(); // 함수 "호출"
console.log("name is " + result);
}
printName(); // > "name is inner value"
====================================================================
/* 정상 */
/** --- JS Parser 내부의 호이스팅(Hoisting)의 결과 - 위와 동일 --- */
function printName(firstname) {
var inner; // [Hoisting] 함수표현식의 변수값 "선언"
var result; // [Hoisting] var 변수값 "선언"
inner = function() { // 함수표현식 "할당"
return "inner value";
}
result = inner(); // 함수 "호출"
console.log("name is " + result);
}
printName(); // > "name is inner value"
함수 표현식의 선언이 호출보다 아래에 있는 경우 (var 변수 할당)
/* 오류 */
function printName(firstname) { // 함수선언문
console.log(inner); // > "undefined": 선언은 되어 있지만 값이 할당되어있지 않은 경우
var result = inner(); // ERROR!!
console.log("name is " + result);
var inner = function() { // 함수표현식
return "inner value";
}
}
printName(); // > TypeError: inner is not a function
===========================================================================
/** --- JS Parser 내부의 호이스팅(Hoisting)의 결과 --- */
/* 오류 */
function printName(firstname) {
var inner; // [Hoisting] 함수표현식의 변수값 "선언"
console.log(inner); // > "undefined"
var result = inner(); // ERROR!!
console.log("name is " + result);
inner = function() {
return "inner value";
}
}
printName(); // > TypeError: inner is not a function
함수 표현식의 선언이 호출보다 아래에 있는 경우 (let/const 변수 할당)
/* 오류 */
function printName(firstname) { // 함수선언문
console.log(inner); // ERROR!!
let result = inner();
console.log("name is " + result);
let inner = function() { // 함수표현식
return "inner value";
}
}
printName(); // > ReferenceError: inner is not defined
https://gmlwjd9405.github.io/2019/04/22/javascript-hoisting.html
https://www.edwith.org/boostcourse-web/lecture/16695/
https://hanamon.kr/javascript-%ED%98%B8%EC%9D%B4%EC%8A%A4%ED%8C%85%EC%9D%B4%EB%9E%80-hoisting/
https://tecoble.techcourse.co.kr/post/2021-04-25-hoisting/
https://gmlwjd9405.github.io/2019/04/20/function-declaration-vs-function-expression.html
함수 안에 있는 선언들을 모두 끌어올려서 해당 함수 유효 범위의 최상단에 선언하는 것을 말한다.
자바스크립트 함수는 실행되기 전에 함수 안에 필요한 변수 값들을 모두 모아서 유효 범위(스코프)의 최상단에 선언하는 것 처럼 보인다.
자바스크립트 엔진은 코드를 실행하기 전에 실행 컨텍스트를 생성한다.
또한 자바스크립트 엔진은 코드를 실행하기 전 실행 컨텍스트를 위한과정에서 모든 선언(var, let, const, function, class)을 스코프에 등록한다.
이 때 자바스크립트 Parser가 함수 실행 전 해당 함수를 한 번 점검하면서 필요한 값들을 끌어올린다.
그렇다면 변수 선언을 굳이 미리 안해도 되는 것일까?
그렇지는 않다. let/const/class 를 이용한 선언과 *함수 표현식에서는 호이스팅이 발생하지 않는것 처럼 보인다.
그러나 모든 선언에 호이스팅이 발생하는 것은 맞다.
다만 let, const 키워드로 선언된 변수는 스코프의 시작에서 변수의 선언까지 일시적 사각지대(Temporal Dead Zone; TDZ)에 빠지기 때문이다.
여기서 중요한 지점은 이 호이스팅이라는 용어가 ‘선언이 먼저 메모리에 저장되었다.’는 것을 의미하기 때문에(선언이 끌어올려진다’는 의미이기 때문에)
모든 선언은 호이스팅이 일어난다는 말은 참이된다.
뭔가 이랬다 저랬다 하는 것 같으니 정리를 해보자.
다음의 명제들은 모두 참이다.
let foo = 1;
{
console.log(foo); // Reference Error
let foo = 2;
}
위의 코드는 foo 변수의 선언이 호이스팅 되지 않았다면, 에러 없이 동작할 것이다.
왜? 스코프 체인에서 현재 스코프부터 상위 스코프로 이동하면서 foo를 찾을 것이기 때문이다.
그러나 현재 스코프에 foo 선언문이 존재하기 때문에, 호이스팅이 발생했으나 값이 초기화 되지 않아 에러가 발생한다!
console.log(a); // undefined
console.log(b); // Reference Error
var a = 1;
let b = 1;
console.log(func); // [Function : func]
function func() {
console.log("What is Hoisting?");
}
console.log(someFunc); // undefined
var someFunc = function () {
console.log("What is Hoisting?");
}
console.log(arrowFunc); // undefined
var arrowFunc = () => {
console.log("What is Hoisting?");
}
console.log(constFunc); // Reference Error
const constFunc = function () {
console.log("Const Func");
}
자바스크립트 Parser 내부의 동작 방식을 유추해보자면 다음과 같을 것이다.
var a; // [Hoistring] 선언
console.log(a); // undefined;
console.log(b); // Reference Error
a = 1; // 할당
let b = 1; // Hoisting 발생 안함
함수선언문은 코드를 구현한 위치와 관계없이 자바스크립트의 특징인 호이스팅에 따라 브라우저가 자바스크립트를 해석할 때 맨 위로 끌어 올려진다.
/* 정상 출력 */
function printName(firstname) { // 함수선언문
var result = inner(); // "선언 및 할당"
console.log(typeof inner); // > "function"
console.log("name is " + result); // > "name is inner value"
function inner() { // 함수선언문
return "inner value";
}
}
printName(); // 함수 호출
==========================================================================
/** --- JS Parser 내부의 호이스팅(Hoisting)의 결과 - 위와 동일 --- */
/* 정상 출력 */
function printName(firstname) {
var result; // [Hoisting] var 변수 "선언"
function inner() { // [Hoisting] 함수선언문
return "inner value";
}
result = inner(); // "할당"
console.log(typeof inner); // > "function"
console.log("name is " + result); // > "name is inner value"
}
printName();
함수표현식은 함수선언문과 달리 선언과 호출 순서에 따라서 정상적으로 함수가 실행되지 않을 수 있다.
함수표현식에서는 선언과 할당의 분리가 발생한다.
함수 표현식의 선언이 호출보다 위에 있는 경우
/* 정상 */
function printName(firstname) { // 함수선언문
var inner = function() { // 함수표현식
return "inner value";
}
var result = inner(); // 함수 "호출"
console.log("name is " + result);
}
printName(); // > "name is inner value"
====================================================================
/* 정상 */
/** --- JS Parser 내부의 호이스팅(Hoisting)의 결과 - 위와 동일 --- */
function printName(firstname) {
var inner; // [Hoisting] 함수표현식의 변수값 "선언"
var result; // [Hoisting] var 변수값 "선언"
inner = function() { // 함수표현식 "할당"
return "inner value";
}
result = inner(); // 함수 "호출"
console.log("name is " + result);
}
printName(); // > "name is inner value"
함수 표현식의 선언이 호출보다 아래에 있는 경우 (var 변수 할당)
/* 오류 */
function printName(firstname) { // 함수선언문
console.log(inner); // > "undefined": 선언은 되어 있지만 값이 할당되어있지 않은 경우
var result = inner(); // ERROR!!
console.log("name is " + result);
var inner = function() { // 함수표현식
return "inner value";
}
}
printName(); // > TypeError: inner is not a function
===========================================================================
/** --- JS Parser 내부의 호이스팅(Hoisting)의 결과 --- */
/* 오류 */
function printName(firstname) {
var inner; // [Hoisting] 함수표현식의 변수값 "선언"
console.log(inner); // > "undefined"
var result = inner(); // ERROR!!
console.log("name is " + result);
inner = function() {
return "inner value";
}
}
printName(); // > TypeError: inner is not a function
함수 표현식의 선언이 호출보다 아래에 있는 경우 (let/const 변수 할당)
/* 오류 */
function printName(firstname) { // 함수선언문
console.log(inner); // ERROR!!
let result = inner();
console.log("name is " + result);
let inner = function() { // 함수표현식
return "inner value";
}
}
printName(); // > ReferenceError: inner is not defined
https://gmlwjd9405.github.io/2019/04/22/javascript-hoisting.html
https://www.edwith.org/boostcourse-web/lecture/16695/
https://hanamon.kr/javascript-%ED%98%B8%EC%9D%B4%EC%8A%A4%ED%8C%85%EC%9D%B4%EB%9E%80-hoisting/
https://tecoble.techcourse.co.kr/post/2021-04-25-hoisting/
https://gmlwjd9405.github.io/2019/04/20/function-declaration-vs-function-expression.html
No comments yet