4 ms·
from https://www.tutorialspoint.com https://www.tutorialspoint.com (high seo, I do not personally endorse) Objective-C: - (return_type) method_name:( argu
by texuf 9y ago
from https://www.tutorialspoint.com https://www.tutorialspoint.com (high seo, I do not personally endorse)
Objective-C:
- (return_type) method_name:( argumentType1 )argumentName1
joiningArgument2:( argumentType2 )argumentName2 ...
joiningArgumentn:( argumentTypen )argumentNamen
{
body of the function
}
Swift:
func funcname(Parameters) -> returntype {
Statement1
Statement2
---
Statement N
return parameters
}
Javascript:
function functionname(parameter-list)
{
statements
}
I know people downvoted op, but when I first learned it, reading Objective-C made me angry. The second two examples are much closer in syntax and style and require much less context switching.
And it wasn't mentioned, but the if let myVar = optionalVar { ... } is a godsend for writing maintainable, crash-free code.
If you want to get a good idea of what good swift looks like, check out https://github.com/raywenderlich/swift-style-guide https://github.com/raywenderlich/swift-style-guide
- ajeet_dhaliwal 9y agoThis is just a visual and fairly shallow similarity. I think the context switch is huge and the same as Objective C. Anyway the future isn’t Swift, it’s JavaScript for everyone :-)
- kalleboo 9y agoAltho TBH most of the objections I've heard against ObjC from non-ObjC developers usually are just as shallow and revolve around how weird or ugly the bracket syntax for messages is.
- valuearb 9y agomy objections to obj C are code quality, pointers and crash rates.
- abritinthebay 9y agoVisual affects reading which affects comprehension. Don’t dismiss visual similarities so out of hand.
- ajeet_dhaliwal 9y agoIt matters yes, I’ve never been completely comfortable with Python and Lua because of their style but in the example above how is the Swift better than the Objective-C? Sure the params syntax is cleaner here but then you have the return type (with the ugly arrow) at the end instead of the start of the line which is unusual compared to many other c style syntax languages and you also lose the -/+ instance/class method syntax i always liked in Objective-C. JavaScript of course doesn’t have to supply a return type at all, I just don’t see how any of this helps someone coming from JS/Python/Ruby combined with the deeper understand required around nullables and types.
- wootness 9y agoFor everyone? Yeah, no.
- Koshkin 9y ago> reading Objective-C made me angry Yet, many programmers love Smalltalk, which is where this "new" syntax came from.
- mgoblu3 9y agoIt's just getting used to []][[][]] and having brackets and @property and lots of things a little different that most first languages people learn nowadays. If you're coming from C, then moving to Objective-C might feel different than coming from languages people tend to learn first nowadays. As someone coming from C++ (and others) when I started programming 4ish years ago, it definitely felt unnatural, but learned to appreciated it a lot and found it pretty sensible. Except for blocks... It has made me really want to look into learning Smalltalk as a throwback hobby.
- texuf 9y agoYou're totally right, after a while you get used to it.
- valuearb 9y agoi agree with all your points , but despite the superficial syntax similarity, Swift’s strong typing, optionals and slow compilation make it the anti-javascript.