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

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


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.


barenature is offline   0 Reply With Quote
Old Nov 26, 2010, 09:54 AM   #2
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...

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
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
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
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?

barenature is offline   0 Reply With Quote
Old Nov 26, 2010, 02:38 PM   #6
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
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, iPad mini, iPhone 5

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
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.

barenature is offline   0 Reply With Quote

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
MacBook Air 11" owners, is it practical to get an iPad on top of your lineup? anthro iPad 17 Mar 7, 2011 01:51 PM
How to make an XCODE dialog applicaton to stay on top of other window application kpyapali Mac Programming 0 Aug 25, 2009 11:15 AM
Do you keep your mac pro on the floor or on top of your desk?? Also would it be... jjahshik32 Mac Pro 46 Apr 7, 2008 08:22 PM
Programs staying on top of EVERYTHING!! bryantdiaz878 OS X 0 Jan 21, 2008 02:52 PM
Why does my iChat tabbed chat window stay on top of all other windows cheezebob OS X 3 Nov 3, 2007 11:39 PM

All times are GMT -5. The time now is 05:09 PM.

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

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