Clean Code - What is better to read?

Clean Code - What is better to read?
0

#1

Hi campers,

I write the function initilizeTable and call it inside an if-statement:

if (Cookie.filterCookie('tasks') != []) {
  initilizeTable(JSON.parse(Cookie.filterCookie('tasks')));
}

but maybe it would be better to have the if statement inside the function, like this:

function initilizeTable(values) {
  if (Cookie.filterCookie('tasks') != []) {
    //some logik..
  }
}

so I just have to call the function name inside my index.js.
What do you think is better to read?


#2

Use the function. It’s clearer and more obvious what you’re trying to do and you can reuse it. Also, you can treat the function as a black box and change the implementation later on and it wouldn’t affect your main program. Makes sense?


#3

It’s not such a great idea to hard code references to other objects inside of your functions. Maybe something like

function initializeTable(values) {
  if (values.length) {
    //some logic..
  }
}