return¿ë·ÎÄú¯¼ö¼±¾ðÇϴ°ԾÈÁÁÀº°ÅÀÓ
ºñ°ø°³
(¼Õ´Ô)
2022.05.10 10:36:04
return¿ë ·ÎÄú¯¼ö ¼±¾ðÇÏ´Â°Ô ¾ÈÁÁÀº°ÅÀÓ?
ÇÔ¼ö°°Àº°Å ¸¸µé¶§
int result =  value1 * value2;
return result;
ÀÌ·±½ÄÀ¸·Î ½á¿Ô´Âµ¥

Áö±Ý ÇÁ·ÎÁ§Æ®¿¡¼­ ¼Ò³ª¸°Æ® ¾²´Âµ¥
declaring a variable only to immediately return or throw it is a bad practice.
À̶ó°í ¼öÁ¤±Ç°í ¶ß°Åµç¿ä
return value1 * value2; ÀÌ·±½ÄÀ¸·Î ¾²¶ó±¸¿ä

óÀ½ ¹è¿ï¶§ºÎÅÍ À§¿¡ ¹æ½ÄÀ¸·Î Ç϶ó°í ¹è¿ö¼­ ±×·±°¡
°¡µ¶¼ºµµ ´õ ÁÁ°í µð¹ö±ëÇϱ⵵ ÆíÇÑ°Å °°Àºµ¥
¿Ö bad practiceÀÎÁö Àß ÀÌÇØ°¡ ¾ÈµÊ´Ï´Ù

Àâ´ã | 2,582¸íÀÌ Àоú¾î¿ä.

·¹¾î¡¤À¯¸Ó¡¤ÀÚÀÛ Àαâ±Û
1 Á¿¼Ò°¡ À¯´ÉÇÑ Á÷¿øÀ» ÀÒ´Â °úÁ¤ 17½Ã°£ Àü
2 ¿ä»õ »çȸÃʳâ»ýµéÁß¿¡ °£È¤ º¸Àδٴ À¯Çüµé 8½Ã°£ Àü
3 °üÀåÇü ÇコÀå ¿Â°Å°°´Ù ¤¸µÊ 8½Ã°£ Àü
4 ÇÇÆÄ ÃÊ°í¼ö¸¸ 4½Ã°£ Àü
5 Ä«Æä¿¡ ³ëÆ®ºÏÀ» ¹æÄ¡Çصµ ¾ÈÀüÇÑ ´ëÇѹα¹ 21½Ã°£ Àü
2°³ÀÇ ´ñ±Û
1 ºñ°ø°³
Àúµµ ±Ã±ÝÇؼ­ ã¾Æº¸´Ï
https://stackoverflow.com/questions/31733811/local-variables-before-return-statements-does-it-matter
The method name should be sufficient for callers to know exactly what will be returned.
¶ó°í ½áÀֳ׿ä
ÇÔ¼öÀ̸§ ÀÚü°¡ ¹» ¸®ÅÏÇÏ´ÂÁö ´ã°í ÀÖ¾î¾ß ÇѴٴµ¥ ¸Â´Â¸» °°±âµµ ÇÏ°í..
¾öû Áß¿äÇÑ°Ç ¾Æ´Ñ°Å °°À¸´Ï Á¶Á÷³»¿¡¼­ µ¿ÀÇÇÑ ¹æÇâÀ¸·Î ¸¸µé¸é µÉ°Å °°½À´Ï´Ù
2022/05/10 11:19
2 ºñ°ø°³
¸ð¹æÀÌ Ã¢Á¶ÀÇ ¾î¸Ó´Ï¶ó´Â ¸»µµ ÀÖÁö¸¸..,
±Û¾´´Ô¹æ½Äµµ ÁÁÀº °Å °°¾Æ¿ä~ ±×·¸Áö¸¸..,
ÇÁ·Î±×·¥ ³»¿¡¼­´Â ±× ÇÁ·Î±×·¥ÀÇ ·êÀ» µû¶ó¾ß Çϱ⠶§¹®¿¡.. ¤Ð¤Ì

Àú´Â ºñÁê¾ó½ºÆ©µð¿À 2022¾²´Â µ¥,
C++ À±¼º¿ì(¾âÇ÷°­ÀÇ C++)´Ô µ¿¿µ»ó°­ÀÇ·Î ¹è¿ï·Á´Ï±ñ,
½±Áø ¾È³×¿ë~

±Û¾´´Ô È­ÀÌÆà ^ ^bÇÏÀ̼Ò
2022/09/05 12:20
°Ô½ÃÆÇ ¸ñ·ÏÀ¸·Î µ¹¾Æ°¡±â