6

devRanters: 1 or 2?

Any alternative?

Comments
  • 3
    For me I go with faster + readable one, in this case I chose 1 it is readable but I don't see any performance difference between both of them

    Out of scope, which language is this? using a single quote for strings, I guess it is Javascript?
  • 2
    Number one definitely!

    Prefer it to be readable and easy to get an overview of
  • 2
    Absolutely 1.
  • 0
    No. 1
    Everything different is not acceptable
  • 1
    Kidding me? Even if you give million dollars, i won't switch to 2
  • 0
    Number 1, out of those two.
  • 5
    [user.first_name, user.last_name].join(' ').trim()
  • 2
    @gitpush yes JavaScript, the second was the original code by other dev, I hated it and the linter hated it, figured there must be a better way.

    @Byscripts nice, didn't know how that would deal with null/undefined like that. Feels like I'm learning new things about JS all the time
  • 0
    @Byscripts definitely that is better. That is why I said 'out of those two' before because neither looked simple enough but I didn't want to test it.
  • 0
    I guess I'm the only one who likes 2 better?
  • 0
    @spongessuck probably not, but it doesn't feel like such a silly question now you have gone against the grain, so thanks!
  • 0
    Absolutely 2.
  • 0
    @bcye why? It's so unreadable for me
  • 0
    @DucksCanCode I hate to see a command on 2 or more lines. It makes me crazy 😂
  • 0
    @bcye what about chaining methods together? Do you do that all on one line?!?
  • 0
    @DucksCanCode umm what's that? Still beginner and don't have much PHP experiences.
  • 0
    @bcye like option one, where you have multiple method calls on the same line for the same object. I don't know if that's the proper name, that's just what I've always called it.
  • 0
    @bcye this is in javascript - basically what is done in the original post is:

    1) create an array with first name & surname
    2) .filter() takes the array created in step1, and applies a function on it, returning a new array with the filtered values
    3) .join() takes the array returned from step2, and joins the array with a space

    Chained methods is basically:
    - Start with an element (array in this case)
    - Apply multiple functions to the element to return new values

    For each chain (.filter, .map, .join etc), the value is returned and passed to the next chain, manipulating your data
  • 0
    @yusijs ok never saw this in swift
  • 0
    I have read that function composition > chaining.
  • 0
    Also if pipes are approved in the new JS spec, function composition will look so much prettier
Add Comment