Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 26, 2010, 07:50 AM   #1
barenature
macrumors newbie
 
Join Date: Oct 2010
Staying on top of your code

Hello,

Even though I have been programming for quite some time, a problem I run into every time again is that I get lost in my own code from the moment the project has crossed a certain scope.

How do you stay on top of your code? How do you get a clear picture that tells you exactly which object has a reference to another or how process x unfolds in your application? Do you use only comments (lots of them) or do you write everything down using a notepad or a whiteboard?

For your information, I do clean up my code and use comments. I am just wondering if there are tools out there that help me with this task.

Thanks,

BN
barenature is offline   0 Reply With Quote
Old Nov 26, 2010, 09:54 AM   #2
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
I find version control (CVS/Subversion/Git) to be a very useful tool in that even if there is only one contributor to the code. If nothing else it helps you trace how your code got to that point.

I also find it very useful to KISS keep it small stupid. Focused code modules that are short and to the point are much easier to stay on top of than long rambling code even when that might be more efficient performance wise. That means breaking out sections of code into helper modules, etc...

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Nov 26, 2010, 10:02 AM   #3
wpotere
Guest
 
Join Date: Oct 2010
As mentioned above... Break long code up into smaller modules if possible and document the heck out of it if necessary.
wpotere is offline   0 Reply With Quote
Old Nov 26, 2010, 10:05 AM   #4
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
1. Methodnames that say exactly what a method does. Quite easy to achieve in Objective-C. I should be able to guess exactly what _your_ method call does without having read the source code.

2. Self-contained objects that do one thing and do it well.

3. Blocks in 10.6 help cutting down the number of helper methods that you need, especially for multithreaded apps.

4. "Refactor" is your friend; easy to change names to something that makes more sense.

5. Use Objective-C 2.0 features (properties, iterators) to cut down on lines of code written.

Just a few things.
gnasher729 is offline   0 Reply With Quote
Old Nov 26, 2010, 11:40 AM   #5
barenature
Thread Starter
macrumors newbie
 
Join Date: Oct 2010
Great suggestions! Most of them are familiar, but I guess I should make an extra effort to better implement those in my workflow. I haven't used version control yet (mainly due to the fact that I am not familiar with it), but I think I should take a look at that soon.

What I am actually looking for in particular, though, is a way to build schemes like you can make mind maps, the so called object graphs (if I'm not mistaken). Do you use such graphs and do you simply write them down on paper or a whiteboard?

BN
barenature is offline   0 Reply With Quote
Old Nov 26, 2010, 02:38 PM   #6
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
What I tend to do is push chunks of functionality out (conceptually at least, sometimes literally) into libraries. Then you can define an API boundary, write tests for that API, maybe even document it, and then treat it as almost a separate project.

The key is to figure out where to draw the API boundary; my rule of thumb is that anywhere there needs to be a two-way interaction (like a calls a method on b which calls another method on a, not via some sort of explicit callback system), both sides of it need to be on one side of the API line.
Catfish_Man is offline   0 Reply With Quote
Old Nov 26, 2010, 05:41 PM   #7
firewood
macrumors 603
 
Join Date: Jul 2003
Location: Silicon Valley
That's what code structure and OOP were designed for (at least one of the main reasons).

This is good, because you now realize that you will soon forget what you were doing when you wrote any line of code. So start writing stuff that you can plan on forgetting right after you've debugged it and checked it in.

Start breaking your code up into objects, with well enough defined and self-documented interfaces so that it doesn't matter if you forget what's inside. When that starts getting hard to stay on top of, break these objects up into bigger groups of code objects, making these bigger groups again with well defined interfaces. Then you can start forgetting what's inside huge amounts of your code. Rinse and repeat and you have done what large companies do with projects so large than even lead programmers may have no idea what 90% of the other programmers on the project are doing, in any detail, yet still manage to create stuff that works (well enough).

The goal is to make the maximum amount of your own code forgettable (as if it were written by a (good) subcontractor of a subcontractor of yours in China/India). Then any "mind map" or graphical doc stuff becomes far simpler, with less objects and arrows, etc.
__________________
Apple II+, Mac 128k->512ke, Duo 210, MacBook Air 11, iPhone 5, iPad Mini Retina

Last edited by firewood; Nov 26, 2010 at 05:47 PM.
firewood is offline   0 Reply With Quote
Old Nov 26, 2010, 06:20 PM   #8
barenature
Thread Starter
macrumors newbie
 
Join Date: Oct 2010
Thanks for the replies. That is solid advice and I'll keep it in mind. At the moment, I am mainly working with Objective-C, but this obviously applies to any programming language that is OOP centered.

Looking back, when I was doing quite a bit of PHP programming, I can't believe I was not thinking in objects. I know it's not always necessary to use an OOP approach, but once you get the hang of it, it seems hard to go back.

BN
barenature is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Top IMAC 27" VS Top Macbook pro Retina for video editing dany74m iMac 1 May 12, 2014 02:53 AM
Staying on 7.0 or 7.1? theapplefanboyj iPod touch 5 Mar 13, 2014 10:58 PM
Staying with my 5S until September jimbo1mcm iPhone 13 Mar 12, 2014 11:32 PM
The art of staying on top jimbo1mcm Alternatives to iOS and iOS Devices 11 Aug 6, 2013 07:46 AM
How many here are staying up to preorder ? Che Castro iPhone 64 Sep 14, 2012 12:17 AM

Forum Jump

All times are GMT -5. The time now is 03:49 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC