Giter Club home page Giter Club logo

Comments (8)

vogelino avatar vogelino commented on July 20, 2024

Signature typing

I think that both ways are valid but I prefer the tightly coupled way because:

  1. It doesn't contain the => twice, making the readability better (we avoid confusing the signature for the real function)
  2. It shares the way of typing it with functions written with the function keyword

If you wish to share signatures between multiple functions, prefer using a type. That makes its reusability explicit:

type ClickHandleSignature = (id: string) => void

const onClickHandler: ClickHandlerSignature = (id) => {
  // ...
}

I prefer not to makes things generic until really necessary. It is way simpler to refactor.

Function keyword

I don't use the function keyword in most cases for a few reasons:

  1. It is less verbose and can return without a return keyword, making it easy to write composable on-liners
  2. It makes it explicit that the this keyword isn't used here. You don't even think about it. Wit a function that has a function keyword, you never know.

from giessdenkiez-de.

ff6347 avatar ff6347 commented on July 20, 2024

It doesn't contain the => twice, making the readability better (we avoid confusing the signature for the real function)

Funny I find your way harder to digest then the one I prefer. :)

from giessdenkiez-de.

ff6347 avatar ff6347 commented on July 20, 2024

If you wish to share signatures between multiple functions, prefer using a type. That makes its reusability explicit:

That's what I said. :)

I prefer not to makes things generic until really necessary. It is way simpler to refactor.

Me too. But if I have to my way is faster 🚀

from giessdenkiez-de.

vogelino avatar vogelino commented on July 20, 2024

Funny I find your way harder to digest than the one I prefer. :)

Common, could we not talk about your way/ my way? An can you elaborate on why do you think it is easier to digest?

from giessdenkiez-de.

vogelino avatar vogelino commented on July 20, 2024

That's what I said. :)

Your suggestion included the signature as a prefix to the parameters, which as I said, has to risk to make the readability of the function more difficult as it contains two =>. The developer has to first identify which is the signature and which is the function declaration.

In my suggestion, the signature is external to the function declaration. I would only use that in the case it really is used multiple time.

from giessdenkiez-de.

vogelino avatar vogelino commented on July 20, 2024

Me too. But if I have to my way is faster 🚀

Coding with speed is only good if it doesn't compromise the readability of the code. But sure, you might save some milliseconds.

from giessdenkiez-de.

ff6347 avatar ff6347 commented on July 20, 2024

Let's move that to discussions.

from giessdenkiez-de.

ff6347 avatar ff6347 commented on July 20, 2024

Let's keep on in #297

from giessdenkiez-de.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.