Clean Code Tip - The expression IS the VALUE 📈

preview_player
Показать описание
y you writing these still?

#csharp #cleancode #programming
Рекомендации по теме
Комментарии
Автор

I tend to change this to an arrow function:
bool CanBeer(int age) => age >= 18;

MayronWoW
Автор

This is pretty basic but very useful for beginners. Cheers!

nutcracker
Автор

18 is a magic number. Consider using a constant to make it more readable

Flavinous
Автор

thanks, went back and changed a line of code :)

gian
Автор

"But but but readability!"

If I hear that one more time I'm gonna write a super long Rx chain and not comment any of it

AvenDonn
Автор

This style of keeping your code clean can also be your enemy. If the function is subject to changes which add complexity you will most likely have to write an if statement again :)
Also, putting if else statements makes your code more explicit and easier to read, imo

meJevin
Автор

actually, if u don't even add the "?" and ":", and only write "return age > 18", it will return either false or true because "age > 18" this is itself a condition which gets executed and returns a Boolean value, which then gets returned with the "return" keyword.

gamingstarzainyt
Автор

Yea I saw that a lot in college. It’s often cause by thinking too hard about a problem

chadkrause
Автор

this code is wrong. it should be:
bool CanBeer(int){
return true;
}
or just make it a macro:
#define CanBeer(age) true

karbonaterol