• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Good Habits (was: Re: C question for you old guys ;-))
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Good Habits (was: Re: C question for you old guys ;-))


  • Subject: Re: Good Habits (was: Re: C question for you old guys ;-))
  • From: Oscar Morales Vivó <email@hidden>
  • Date: Mon, 9 Jun 2003 17:45:06 +0200

What "good habits" does anyone else have?

A few of mine. Some of them are C++isms (although I think C99 gets them too). Some are probably personal manias too :P.

- Always use references if a null pointer isn't valid in that place (for function params, temporary and local variables...). Tends to make null pointer errors easier to locate.

- Always use the '=' operator only for assignments, never for initialization (although the quirks of C++ make that impossible in a few cases).

- Use the logical operator keywords instead of the traditional operators ('and' instead of '&&', 'or' instead of '||', 'not' instead of '!'). I find it makes the code far more readable.

- Use comments in then and else clauses if the condition is not specially trivial. Like:

if(<very complex expression>)
{
// This means Jupiter is in the house of Libra.
...
}
else
{
// Jupiter is not in the house of Libra.
...
}

/*
Oscar Morales Vivs

Eternal Computer Science Student. Master of C++ Templates. Cocoa Nut. Computer Graphics Illuminati. UI Guru in Training. Dabbler in all things CS and most which are not.

Web stuff: http://homepage.mac.com/oscarmv/index.html
*/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Good Habits (was: Re: C question for you old guys ;-))
      • From: Joe Osborn <email@hidden>
References: 
 >Good Habits (was: Re: C question for you old guys ;-)) (From: Shimaron Greywolf <email@hidden>)

  • Prev by Date: Re: Fw: NSBitmapImageRep bitmapData and 16 bits per sample
  • Next by Date: [SOLUTION] Re: The Little NSOutlineView That Couldn't
  • Previous by thread: Good Habits (was: Re: C question for you old guys ;-))
  • Next by thread: Re: Good Habits (was: Re: C question for you old guys ;-))
  • Index(es):
    • Date
    • Thread