Re:RubyMotion Goes 2.0 And Gets OSX Support, Templates and P...
by sandoze on Thursday May 09, 2013 @04:46PM
(#5682846)
Your header file is your interface and documentation to anyone using your code/class. Why wouldn't you want to declare your public interface there?
As for readability. Ruby is getting there but currently:
- (void)employersWithCarrierID:(uint)carrierID withMaxReturnCount:(uint)count;
[self employersWithCarrierID:123 withMaxReturnCount:10];
is a lot more readable and verbose than def employers (id, count)
employer 123 10
Re:RubyMotion Goes 2.0 And Gets OSX Support, Templates and P...
by bjeanes on Thursday May 09, 2013 @10:22PM
(#5684182)
Except in Ruby, you'd just as likely see named arguments too.
`employer carrier_id: 123, max_return_count: 10` is very much valid ruby.
Re:RubyMotion Goes 2.0 And Gets OSX Support, Templates and P...
by kemiller on Friday May 10, 2013 @10:48AM
(#5686459)
Beyond that, RM has "real" named arguments based on the objective-C core.
Re:RubyMotion Goes 2.0 And Gets OSX Support, Templates and P...
by rimantas on Thursday May 09, 2013 @01:01PM
(#5681535)
> That means, no writing everything twice (header files,
> type declarations)
Your header files can be practically empty if you don't need to show something to outside. Just put your @property'ies into class extension. Even @synthesize no longer needed (most of the time, there are exceptions).
> Working with collections like arrays and hashes is MUCH
> more convenient. You can spend a good part of your time
> doing just that.
With latest versions of XCode it is possible to use foo[5] instead of [foo objectAtIndex:5] and foo[@"bar"] instead of [foo objectForKey:@"bar"];
There are also array and dictionary literals @[…], @{…} and you can also just type @1 to get NSNumber from primitive.
Re:RubyMotion Goes 2.0 And Gets OSX Support, Templates and P...
by kemiller on Thursday May 09, 2013 @01:10PM
(#5681596)
I'm aware of all that, but of course you DO want to show things to the outside, all the time. I also know about the newer syntax, which is awesome the few times I still dip into ObjC, but I'm more thinking of map/each/select/detect/etc. There are builtin methods for doing those, but their sheer verbosity tends to discourage the sort of free and easy chaining that Ruby encourages. (Some might argue that's a benefit. Not me.)
Cocoa is a fantastic system to build on top of. NSDate is MILES better than the Ruby time stuff, for example. NS/UI solid core plus Ruby's flexible syntax and culture of sensible defaults is a marriage made in heaven.
Re:RubyMotion Goes 2.0 And Gets OSX Support, Templates and P...
by gdubs on Thursday May 09, 2013 @01:38PM
(#5681802)
>> I'm aware of all that, but of course you DO want to show things to the outside, all the time.
Well, there's a solid argument to be made in favor of limiting how much internals are exposed to other objects. I personally like keeping my headers as minimal as possible.
Re:RubyMotion Goes 2.0 And Gets OSX Support, Templates and P...
by kemiller on Thursday May 09, 2013 @08:44PM
(#5683864)
To clarify: Ruby has public and private. You can control visibility all you want, you just don't have to use a separate header file.
Re:RubyMotion Goes 2.0 And Gets OSX Support, Templates and P...
by mightykan on Thursday May 09, 2013 @05:39PM
(#5683133)
I found BlockKit [1] to be very useful for any Ruby-like collection methods. BlockKit, as the name says, uses blocks extensively to provide all the most common collection methods one would find in Ruby. Some examples of these methods, taken from the NSArray(BlocksKit) [2] documentation are "each", "apply", "map" & "reduce". There are much more.
[1]: https://github.com/pandamonia/BlocksKit [2]: http://pandamonia.github.io/BlocksKit/Documentation/Categori...
But the real payoff is threefold:
1) You can use and write very ruby-ish wrappers for things. A great example is teacup, which lets you essentially write stylesheets for your UIViews (and I guess now NSViews).
2) Working with collections like arrays and hashes is MUCH more convenient. You can spend a good part of your time doing just that.
3) Command-line toolchain. It's not for everyone, of course, but for those who work better like that, it's a revolution.
Right now it's pretty wild west. There's no obvious winner in terms of libraries for the data layer, for example. So taking on an RM project right now either means rolling up your sleeves and hacking on the infrastructure, or just living with raw Cocoa, without benefit of autocomplete. Give it another 6-12 months and I think you'll see a very strong contender.