Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compact Convention

In the case that each method and variable will only be used once, which is the more correct convention?

Creating as many variables as necessary:

var x = GmailApp.getInboxUnreadCount();
var email = GmailApp.getInboxThreads (0, x);

Composing the code in one line:

var email = GmailApp.getInboxThreads (0, GmailApp.getInboxUnreadCount());
like image 869
Christopher Markieta Avatar asked Aug 15 '26 20:08

Christopher Markieta


1 Answers

The latter, within reason. But this is largely a matter of style in the simple cases.

Meaning that if you have a function call that takes 10 arguments, and each of those arguments comes from a large function call itself, dont do this. Think of who gets your code base afterward.

"Is this line of code readable using less local variables? Or do I need to break it up to better illustrate what the line is doing?" is the question you should ask yourself. And in this case, the latter is totally readable.


In fact, I would argue the first example is less readable due to a useless local variable name x. If instead that were named better, it might be a more viable option.

var unreadCount = GmailApp.getInboxUnreadCount();
var email = GmailApp.getInboxThreads (0, unreadCount);

This is better, but still pretty unnecessary in this very simple case.

like image 125
Alex Wayne Avatar answered Aug 17 '26 08:08

Alex Wayne