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

iOS

Why do we not hardcode the upper bound of the random number?

Hello, I am wondering if someone can explain why this answer is wrong? It seems like the correct answer to me?

Why do we not hardcode the upper bound of the random number? A) Because our data source may change and the hardcoded number will give an incorrect range B) Because it is a magic number doesn't provide any information about the range of random numbers C) Because we should strive to hardcode as little info as possible D) All of the Above

I chose D - All of the above because (A) The array size can change and if it gets smaller we're out of index, Also if it gets bigger we may not ever read from the remainder of the array (B) In the video we talked about how putting a hardcoded value, when we return to our projects or a new developer does they will not necessarily know why there is a hardcoded value there (say 10 for example). (C) It seems like we would want to have as little hardcoded as possible and keep it dynamic.

This was the quiz on the build a simple app with Swift 2.0 by the way (Improving Our User Interface)

Pasan Premaratne

For the record, this is the answer it said was correct: A) Because our data source may change and the hardcoded number will give an incorrect range

1 Answer

Pasan Premaratne
STAFF
Pasan Premaratne
Treehouse Teacher

Hey Aaron Kaye,

Your answer should be correct (All of the above). Might have been something on our end. Checking!

Thanks! Just making sure! Thanks for all of the work you put into the swift course. I am loving the swift 2.0 track!