curly braces to return value
curly braces to return value
- Subject: curly braces to return value
- From: Matt Neuburg <email@hidden>
- Date: Tue, 06 Aug 2013 08:41:46 -0700
Just ran across this, and I was wondering what y'all thought of it:
http://cocoa-dom.tumblr.com/post/56517731293/new-thing-i-do-in-code
Of course I knew that you could create a new scope with curly braces, and I sometimes do that just for clarity; for example I might write
{
CGRect f = thing.frame;
// do stuff to f
thing.frame = f;
}
That's mostly just to clarify that these lines go together, making up for the fact that you can't modify a view's frame by assigning directly into its struct members. The local scope is a bonus. However, I never knew that you could return a value from a curly-braces scope and treat it as an rvalue:
thing.frame = {
CGRect f = thing.frame;
// do stuff to f
f;
}
It's like, did C suddenly turn into Ruby? :) Anyway, I'd be interested in hearing opinions of this. I'm a bit leery of taking advantage of GCC extensions to the C language, not least because you never know when they will vanish out from under you; I still haven't recovered from the day that local function-within-method went away and left me twisting in the wind... :))) m.
--
matt neuburg, phd = email@hidden, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden