Ad/iklan :

3gp Mp4 HD
Play/Download
Live 3D App
Search.Pencarian Menu

Add text send email to rh3252705.adda@blogger.com or Click this (Text porn Will delete) | Tambah teks kirim email ke rh3252705.adda@blogger.com atau Klik ini (Teks porno akan dihapus)
Total post.pos : 16329+

[Go Make Things] How to structure functions

When it comes to writing functions, there are two extremes:

  1. One really big function that does all the things.
  2. Lots of really small functions that do just a single thing.

In my experience, beginners tend to write really big functions, while more seasoned devs tend to break stuff up into lots of really small "pure" functions.

While I think smaller, more narrowly focused functions are better for readability and maintaining code, it can also lead to code bases that are big nested dolls of functions calling functions that call other functions that call more functions.

That kind of setup is in many ways harder to read and maintain than one really big function (and it's worse for performance, too).

I use three basic guidelines for when to break parts of a function into separate, smaller functions…

  1. Is it getting hard to read?
  2. Is it hard to name because it does too much stuff?
  3. Does any of the same functionality get used elsewhere?

If the answer to any of those is "yes," it's time to split at least some of the function into its own separate thing.

If not, it's probably ok to keep it where it is.

Like this? A Go Make Things membership is the best way to support my work and help me create more free content.

Cheers,
Chris

Want to share this with others or read it later? View it in a browser.

Share :

Facebook Twitter Google+
0 Komentar untuk "[Go Make Things] How to structure functions"

Back To Top