Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

puuukeey

macrumors 6502
Original poster
Dec 24, 2004
327
1
tristate area
Coming from java/eclipse to c++ xcode I really miss auto-magically creating getters and setters and things like this.

have I missed something or is this just an indispensable feature that xcode doesn't have?
 

rev316

macrumors regular
Nov 7, 2004
156
0
I would like to know as well. It's quite nice having the auto-fill feature. Although, I find myself needing it less & less when working with lower level languages.
 

puuukeey

macrumors 6502
Original poster
Dec 24, 2004
327
1
tristate area
I just wanted maybe to make myself a bit clearer.

How could anyone live without these features?

and the lists of methods once you type "myList."
and code completion
and clicking on variable names to jump the definition.

there were so many amazing features that I thought I couldn't live without. Am I missing something here ?
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
The features are there, but not everyone comes from a VS/Eclipse background where this stuff is always there and always in your face. Apple disables the as-you-type features by default for whatever reason.

You can always right-click a variable or method name and use 'Jump to <blah>' to jump to where it is declared.

In-line autocomplete is turned on in the XCode preferences. If you want a method list, the default is to bring it up using the escape key while typing.

As for getters and setters, Apple's developers seem adverse to adding tools to autogenerate code for the developer. Instead they prefer to allow the developer to write less code. Obj-C 2.0 adds autogeneration of setters/getters to the language (similar to C# 3.0, actually), for example, and Interface Builder builds resource files rather than code (in contrast to .NET Forms). There are still code generators if you are using APIs/tools like CoreData though. It is hard to say that these indispensable features don't exist, they just aren't available in the exact same way Eclipse and Visual Studio implements them.

I don't blame them for wanting to try to find another way to do it, even if theirs isn't perfect. Neither is the Eclipse or Visual Studio way of doing things.
 

puuukeey

macrumors 6502
Original poster
Dec 24, 2004
327
1
tristate area
The features are there, but not everyone comes from a VS/Eclipse background where this stuff is always there and always in your face. Apple disables the as-you-type features by default for whatever reason.

You can always right-click a variable or method name and use 'Jump to <blah>' to jump to where it is declared.

In-line autocomplete is turned on in the XCode preferences. If you want a method list, the default is to bring it up using the escape key while typing.

As for getters and setters, Apple's developers seem adverse to adding tools to autogenerate code for the developer. Instead they prefer to allow the developer to write less code. Obj-C 2.0 adds autogeneration of setters/getters to the language (similar to C# 3.0, actually), for example, and Interface Builder builds resource files rather than code (in contrast to .NET Forms). There are still code generators if you are using APIs/tools like CoreData though. It is hard to say that these indispensable features don't exist, they just aren't available in the exact same way Eclipse and Visual Studio implements them.

I don't blame them for wanting to try to find another way to do it, even if theirs isn't perfect. Neither is the Eclipse or Visual Studio way of doing things.


I dig what you said about everything else. and thanks for the tips.

but I still don't see how criticism or description of any of the other languages excuses them from leaving the feature out of C++ . What does writing less in objective C have to do with painfully hand writing 30 getters and setters in C++? and to clarify, you see code generation as bad because it's redundant for the programmer therefor it's more elegant to use shorthand?
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Coming from java/eclipse to c++ xcode I really miss auto-magically creating getters and setters and things like this.

have I missed something or is this just an indispensable feature that xcode doesn't have?

Can't you use Eclipse for C++ on the Mac? There is a script menu in Xcode
next to Help. Perhaps you could add a script in there which did something near to what Eclipse does.

I can't say I agree with you about it being an indispensable feature though. If I find myself doing a lot of donkey work, like writing 30 accessors in the same class, alarm bells start ringing in my head, and I ask myself perhaps I need to revisit the design. So, having time to think while coding can be a good thing. Just my opinion and I can understand people liking features like that.

b e n
 

puuukeey

macrumors 6502
Original poster
Dec 24, 2004
327
1
tristate area
Can't you use Eclipse for C++ on the Mac? There is a script menu in Xcode
next to Help. Perhaps you could add a script in there which did something near to what Eclipse does.

I can't say I agree with you about it being an indispensable feature though. If I find myself doing a lot of donkey work, like writing 30 accessors in the same class, alarm bells start ringing in my head, and I ask myself perhaps I need to revisit the design. So, having time to think while coding can be a good thing. Just my opinion and I can understand people liking features like that.

b e n

I'm curious. Since I'm entirely self taught, what are those alarm bells? maybe thirty is excessive but, in java, when I code the more controller type of objects, I start with upwards of ten variables. Next, I stripe getters and setters across the board, each with the appropriate modifiers...

then I just run and fill everything in.


When I see other peoples code ( which is really rare ) things seem simpler, but I can't find a way to organize certain things without being unnecessarily bureaucratic.
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
but I still don't see how criticism or description of any of the other languages excuses them from leaving the feature out of C++ . What does writing less in objective C have to do with painfully hand writing 30 getters and setters in C++? and to clarify, you see code generation as bad because it's redundant for the programmer therefor it's more elegant to use shorthand?

Well, on the Mac, Apple's focus is on Obj-C, not C++. So support from Apple will be somewhat minimal for C++.

And while I didn't say code generation was bad (I said Apple thought that way), I would say it is as well. Generated code is code you didn't write, but will have to maintain in the future. That is usually bad.

I find the best way to write maintainable code is to write less code. As you say in a later post, you wind up writing bureaucratic code. This isn't bad, as it is safe code, but it could be bad because it is complex code by design.

Code should be complex by need, not by design. Programmers always need to be wary of over-engineering their code when they first write it. Don't try to make it do everything that you possibly may or may not need of it. Write just the parts you need for it to do its job. Then come back later and tweak for performance, extra functionality, etc as needed. Trying to plan ahead for this sort of stuff from the beginning usually gives you pain.

And yes, I'd agree writing accessors is tedious, I hand-write accessors in C# all the time at work. But I also never write an accessor unless some other class really needs access to a variable. Never before that. Some of our product's most complex classes never reach a dozen. We just never need that many in practice.
 

puuukeey

macrumors 6502
Original poster
Dec 24, 2004
327
1
tristate area
Well, on the Mac, Apple's focus is on Obj-C, not C++. So support from Apple will be somewhat minimal for C++.

And while I didn't say code generation was bad (I said Apple thought that way), I would say it is as well. Generated code is code you didn't write, but will have to maintain in the future. That is usually bad.

I find the best way to write maintainable code is to write less code. As you say in a later post, you wind up writing bureaucratic code. This isn't bad, as it is safe code, but it could be bad because it is complex code by design.

Code should be complex by need, not by design. Programmers always need to be wary of over-engineering their code when they first write it. Don't try to make it do everything that you possibly may or may not need of it. Write just the parts you need for it to do its job. Then come back later and tweak for performance, extra functionality, etc as needed. Trying to plan ahead for this sort of stuff from the beginning usually gives you pain.

And yes, I'd agree writing accessors is tedious, I hand-write accessors in C# all the time at work. But I also never write an accessor unless some other class really needs access to a variable. Never before that. Some of our product's most complex classes never reach a dozen. We just never need that many in practice.
!
very educational. thank you very much.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Coming from java/eclipse to c++ xcode I really miss auto-magically creating getters and setters and things like this.

have I missed something or is this just an indispensable feature that xcode doesn't have?
Look into using @synthesize for automated getters/setters.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
Eclipse annoys me to no end with its brain-dead auto-complete. Maybe I wanted to add some code *inside* the if() statement, so why is the caret at the right of the closing brace?

And many times the auto-complete is wrong so I just ignore it 99% of the time.

I finally got indenting code blocks bound to the square brackets, annoying I had to manually bind those keys when many Mac text editors all have this by default. I move between a Mac (Xcode, Smultron) and Windows (Exclipse, WSAD) all day and having the same behaviors in both places saves me time.

I tend to favor going from Mac to Win in changing behaviors to match up. Windows' shortcuts are so stupid sometimes I don't know how people stand it.
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
Look into using @synthesize for automated getters/setters.

As a note, this is perfect for Obj-C/C++, but not pure C++.

When writing my own code for the Mac in Obj-C I use this a lot, though. Perfect for about 90% of accessors.
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
I'm curious. Since I'm entirely self taught, what are those alarm bells? maybe thirty is excessive but, in java, when I code the more controller type of objects, I start with upwards of ten variables. Next, I stripe getters and setters across the board, each with the appropriate modifiers...

then I just run and fill everything in.


When I see other peoples code ( which is really rare ) things seem simpler, but I can't find a way to organize certain things without being unnecessarily bureaucratic.

I think the trick is to look for relationships between your variables and, where useful, break them out into separate utility classes. In the process you can move code that manipulates those variables into the utility classes and so simplify your existing class in the process. There will be other benefits - for example your class constructors will be simpler to write and nicer to use (less parameters) and destructors will be safer as they will have less responsibility (fewer variables to delete). By breaking variables out from the main class you will be able to define roles for the main and utility classes and have a clearer and less brittle pathway for expanding and adding functionality in the future. As an example think about the role of a vector class and how much simpler it makes designing and writing classes that have position, velocity, colour etc attributes.

b e n
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.