Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Functions in Swift Adding Power to Functions Argument Labels

Michael Williams
PLUS
Michael Williams
Courses Plus Student 8,059 Points

Why have local values at all?

I understand the concept, and while it's not duplicating code it does seem like we're adding unnecessary code and making things more verbose?

2 Answers

IF I’m reading your question properly, they reason for it is simply readability. When using external frameworks, one of the most frustrating things to deal with is bad naming conventions, as it makes it hard to understand what’s going on when calling a function. By adding a local name to a variable, it makes it easier for the person writing/editing the function to see what they are working with, but allowing the external name to give more context to the variable that the function caller needs to pass in. This makes sharing code and working with external frameworks/libraries much nicer, even if it adds an extra word or two to the function definition.

Oziel Perez
Oziel Perez
61,321 Points

While it does make sense, I'm wondering if this is a huge hinderance to developers of foreign languages who don't understand the naming convention of prepositions. It kinda feels like apple only took into consideration the English speaking developers.

Oziel Perez its no so much Apple, but standard practice for programming languages in general. Every language I can think of is based in English as far a variables and syntax, but the programmer is more than able to write all comments, variables, user written classes and methods are in their own language.

First, makes no sense calling the function and specify the label, instead of writing the arguments by the order in the function constructor... and then I need to have an external and internal label, not to mention the crazy convention with the prepositions. For god sake... Hope you have an English grammar class in the Library... This is so much Apple.... This is just confusing for developers... to much to write just to assign an argument in a function.