Xcode: offer to stub out classes and methods which don't exist yet
| Originator: | mike.weller | ||
| Number: | rdar://13420340 | Date Originated: | 14-Mar-2013 04:36 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 4.6 |
| Classification: | UI/Usability | Reproducible: | Always |
Summary: Let's say I'm writing some code, maybe a unit test. I reference a class that doesn't exist: SomeObject *o = [[SomeObject alloc] init]; Xcode will highlight this red because the class does not exist. I want Xcode to offer to create this class for me. This should be quick and easy. After the class is created, I call a method which also does not exist yet: [o doSomethingCool:@"with this"]; Once again, Xcode sees the method does not exist and highlights the line red. I would like Xcode to offer to stub out this method with the appropriate arguments and inferred types. Reasoning: At the moment, writing new code is full of pain points. Developing with TDD is painful. I have to keep stopping to create that protocol or class or method that I've just invented. This may involve right-clicking on a group, selecting "Add", choosing from a large selection of templates, then entering a filename, etc. etc. It's just painful. Almost every other IDE on the planet will offer to stub all this stuff out for you automatically. Xcode should be doing this as well. Xcode knows the classname. Just go and create a damned file with the appropriate name, and make the class inherit from NSObject. *Maybe* ask me which group to put it in (for the case I'm working in a unit test file and want new classes to go in my main app). Please, just make this experience nicer.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
+1 for this feature!
A few examples: Eclipse, IDEA, Visual Studio.
Having these types of helper features ease your work with the code and you can better focus on the functionality rahter than getting lost in the dialogs of the IDE.
Eclipse is especially good at these "clever shortcuts". CTRL+1 is really my best friend. It helps with imports, unimplemented methods, unimplemented classes, renaming, extracting variables, turning a local variable into a field, adding explicit class cast if needed... This is the most used key combination after CTRL+SPACE. Of course there are other ways to activate the aforementioned functions but CTRL+1 is a context sensitive aggregator for all of them, thus, reducin the number of shortcuts I have to remember.
I really miss these features from XCode. Say I get a warning that my class implementation is not complete. If XCode has found out that there are some methods I must implement, then it should also be able to generate the stubs for them if I want that, but at least tell me which ones are missing (this is not stated in the warning, only the fact that the implementation is incomplete). Otherwise I have to find out myself which method is missing and use the semi automatic function declaration generation: "-", start typing the method name, CTRL+SPACE, select method from list. Instead the so desired: click on the warning and select "Generate unimplemented methods".
Visual Studio and Eclipse both provide this feature. Can you name an IDE (other than Xcode) that does not?
"Good programmers design their interfaces, classes and methods before they start writing code" Absolutely true. But often you are in a situation where you are required to implement interfaces or subclasses that are defined by Apple or other parties. Asking Xcode to do the grunt work of creating methods with all the required signatures does not make one a poor programmer or promote spaghetti code.
"Almost every other IDE on the planet will offer to stub all this stuff out for you automatically."
Really? Care to name a few? I'm not so familiar with many other IDEs, yet the ones I know don't do this (or the function is hidden so well, that I haven't found it yet).
Other than that, my only comment here is:
Good programmers design their interfaces, classes and methods before they start writing code. Designing your code while you write it leads to an unmanageable pile of code lines, classes and interfaces, with strange inheritance, strange abstraction, strange interaction in between them, and plenty of well hidden bugs that are even hard to find with all the debugging tools available today.
I mean, why would you try to alloc/init a Class that doesn't even exist so far? That's just crazy. You first write a class, then you write a unit test for it. You don't start with a unit test and then come up with some fictional class this unit test could actually test.