Fun poll. Which version do you guys prefer? I ju...
# cfml-general
b
Fun poll. Which version do you guys prefer? I just found myself writing the first version without thinking about it, but then wondered why I didn't write the second version. Then after typing out version 2, I couldn't decide which was actually clearer to read. Use the emoji's to vote, and the thread to discuss 🙂 1️⃣
Copy code
var headerReducer = (headers) => {
	return headers.reduce( ( list, header)=>{
		list = list.listAppend( "#header.name#: #header.value#", chr(13) & chr(10) );
		return list;
	}, '' );
};
2️⃣
Copy code
var headerReducer = (headers) =>
    headers.reduce( ( list, header) =>
        list.listAppend( "#header.name#: #header.value#", chr(13) & chr(10) ), '' );
1️⃣ 9
2️⃣ 5
I do prefer to avoid closure bodies
{}
when I can, but I get caught needing to do more than one thing or a silly member function that returns a non-useful value often enough that I still type the body by default many times and then refactor it down later if I can.
d
for this example I'd always go with using body. the only time I do not use bodies is when its a one liner
firstheader = (headers) => headers.first()
✔️ 1
s
For me 1️⃣ just makes it easier to read... the extra brackets and structure help me to more quickly visualize what is going on.. it's just how my brain works
✔️ 1
could also just be that I am Used to doing it that way and if I started doing it the other way more often, I would adapt
b
Yeah, I was curious how much of my preference was my my bias for what I'm used to reading. I'm curious what JS-heavy people normally do here.
s
I certainly have a heavy JS influence in my cfscript choices
d
I would say the preferred way in angular and nextjs communities is to do 1️⃣ for multiple lines and 2️⃣ for single lines. But now that this is my 2nd time looking at your example I would agree that 2️⃣ is easy to ready.
s
list.listAppend( header.name & ": " & header.value, .. )
🙂
d
& that too lol
return list.listAppend( header.name & ": " & header.value, ... )
🙂
b
Heh, yes. That function was a copy of another that reduced E-mail addresses with
Copy code
list.listAppend( "#address.emailAddress.name# <#address.emailAddress.address#>", ', ' )
and I thought that more readable than
Copy code
list.listAppend( address.emailAddress.name & ' <' & address.emailAddress.address & '>', ', ' )
Once I get to a point where I'm concatenating enough strings, I'll go back to string interpolation usually.