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 Build an Interactive Story App with Swift Creating a Story Creating an Adventure

computed type vs old fashioned OOP

not really a question. a discussion maybe..

this computed type is so confusing, i think old fashioned object oriented like java etc with data member and function to access data member is better

unlike java, only provides one strict way so all programmer easily understand because it only provides 1 way. imagine if working with other 20 programmers, and 20 programmers have its own preference of using helper method. some is using function, some extension. imagine if someone is a newbie in swift or obj c, then he read some function that has been extension implemented by other programmer, he could mislead if its function is originated by swift or objc

thankyou. please share your opinion.

Jeff McDivitt
Jeff McDivitt
23,970 Points

Hi valkyrie - I am a fan of computed properties and find them very useful. Although there are pros and cons to each language I find Swift to be one of my favorite languages to program in. I have attached a link for you to read more about computed properties and see how they can benefit your code :)

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html

Jeff McDivitt hey jev thanks for your reply. really appreciated it

yes i know. it becomes very handy plus there is a new properties watcher

but it will caused inconsistency of programing style among 20 developers developing together isnt it? even worse with xcode IDE which is slow. with basic prefix "get" and "set" name function, like

getConstraint()
setConstraint(String, int)

//or
//start writing bank.get                -> then ide autocomplete the rest  
bank.getSallary()
bank.setSallary(23)

//or
textField.setEnabled(true)

would give more clues to developer to know what he can do for an object. just write the prefix and all important functions come up... rather than

class bank{
var sallary:Int =  {get{} set{}}
}

//while a new comer developer wouldnt really know what class bank is
//start writing bank.get           -> tada nothing shows up
//then programmer confused what he can do with object bank

most of OOP protect its properties / datamember from the outside (default protected), while swift with computed properties let outside directly change its value (default public)

what do you think? :D

2 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

valkyrie wing as Swift as still in its infant stages maybe it will be more clear in later releases of the language. :)

Jeff McDivitt yes i agree.. i always wonder how does it feel to be a programmer in early stage of computer era.. now here it goes. hahaha full of grumbling.. ok nice discussion

Jeff McDivitt
Jeff McDivitt
23,970 Points

Do you come from a background in programming in another language? I came from objective C and Java and feel that Swift is leaps and bounds above these two languages. Also the confusion for some developers I feel would be easily overcame once they saw the ease of use for Swift. Thoughts?

yes. c++, java, php, python, javascript

i guess i just hate the function name without prefix get and set in the computed type.. for example

would you guess what are view.constraint's getter and setter? by having prefix get or set in the function name, you would know at the first glance, but not computed type. hence you must scroll down the sugestion box getting worse with inconsistent function naming of swift 2.

swift enum is great tho.. yea i am trying to make peace with swift lol.. thankyou Jeff McDivitt

bonus.. what the heck is this UIControlEventValueChanged, UIControlEventEditingChanged, shouldChangeCharactersInRange, UITextFieldTextDidChangeNotification, all of them aim the same.

other example, this is obj c: value for NSStringEncoding is NSUTF8StringEncoding, wtf??? should be NSStringEncoding.utf8

what the heck. so inconsitent.