Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![jurgen meco](https://uploads.teamtreehouse.com/production/profile-photos/2986252/micro_IMG_0561.jpg)
jurgen meco
30 Pointswhy do we need functions in swift, and what is an easy to understand definition of a func, or function?
i need to know, please help
3 Answers
![Derek Scollon](https://secure.gravatar.com/avatar/52d98b13322b6b2fe1dd95f824cea35d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Derek Scollon
8,422 PointsA function is simply a convenient way for you to be able to write a piece of code which carries out a task and allows you to reuse that code by calling the function from different places in your program.
![Digvijay Jaiswal](https://uploads.teamtreehouse.com/production/profile-photos/6294852/micro_03-2015-ford-mustang-1.jpg)
Digvijay Jaiswal
5,565 PointsIn short, due to DRY (Don't Repeat Yourself) principle. would you prefer to write the same code 100 times?
![Assma Al-Adawi](https://uploads.teamtreehouse.com/production/profile-photos/4944562/micro_Assma_pink.jpg)
Assma Al-Adawi
8,723 PointsIn the Swift programming language guide, functions are defined as: "self-contained chunks of code that perform a specific task. You give a function a name that identifies what it does, and this name is used to “call” the function to perform its task when needed".
You don't have to think too hard every time you do some mundane task, like making a sandwich, because your brain has automated it. It's the same with functions. They automate a particular task that you will need to preform several times over without thinking too hard, or taking up too much space as chunks of code.