eerolanguage / eero

Eero was a fully binary- and header-compatible dialect of Objective-C, implemented with a modified version of the Apple-sponsored LLVM/clang open-source compiler. It featured a streamlined syntax, Python-like indentation, and other features that improve readability and code safety. It was inspired by languages such as Smalltalk, Python, and Ruby.
https://web.archive.org/web/20171101134337/http://eerolanguage.org/
288 stars 7 forks source link

@|some:method:| to mean NSStringFromSelector(@selector(some:method:)) #45

Open jpmhouston opened 10 years ago

jpmhouston commented 10 years ago

Saw this tip in the recent NSHipster, which I think is good idea although it's crying out for a nicer syntax:

Passing strings as key paths is strictly worse than using properties directly, as any typo or misspelling won't be caught by the compiler, and will cause things to not work. A clever workaround to this is to use NSStringFromSelector and a @selector literal value: NSStringFromSelector(@selector(isFinished))

I'm suggesting that the syntax @|isFinished| would fit nicely into eero. Forgive me if this is already in the language.

Also, even though there may be less call for using NSStringFromProtocol, why not use similar syntax on protocol literals, even if only for completeness?

jpmhouston commented 10 years ago

I see this is still on here. Forget about my original syntax idea, I had forgot about eero's removal of @ signs in general. How about '|isFinished|'?

andyarvanitis commented 10 years ago

I think your original idea of @|isFinished| is still pretty good, even though eero does get rid of most @s. After all, the ObjC box operator @() is still supported. The problem with '|isFinished|' is that it is the same as the NSString literal for "|isFinished|" (I'm reading your snippet as being enclosed in single quotes).

Another idea might be to extend the box operator to recognize selectors -- e.g. @(|isFinished|). Yet another could be to extend the cast-like box operator to recognize (String)|isFinished|. Or maybe both would be most appropriate, for consistency.

Right now, you can use StringFromSelector(|isFinished|) (taking advantage of prefix lookups), which isn't too bad. Sill, it might be worth exploring some of these ideas (or others).