• 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: Style Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Style Question


  • Subject: Re: Style Question
  • From: Rob Ross <email@hidden>
  • Date: Sat, 28 Jun 2008 07:27:22 -0700

On Jun 28, 2008, at 6:39 AM, Sam Mo wrote:

On Jun 28, 2008, at 4:54 AM, Robert Claeson wrote:

On 28 Jun 2008, at 06:30, Alex Wait wrote:

I have noticed, coming from C++ and Visual Studio (at school), a couple
style differences


if (value) {
   //do something
}

insteasd of

if (value)
{
   //do something
}

Also since I am using this style, XCode doesn't tab in for me when I type {
then a return. This is the style I "taught" and I would like to continue the
good habits
during the summer.

I learned C on Unix long before Microsoft had started producing Windows 1.0. The first style was the first style I learned. I believe it's called the K&R style (from the inventors of C) and it also seems to be the preferred style in Java if you look in Sun's Java documentation. When I then learned C++ back in 1988 (from Bjarne Stroustrup, nonetheless), the K&R style was still the style being used.


The first time I came across the latter style was when I had to work on some Windows C and C++ style. I believe the style was more or less invented by Microsoft. Most of the Unix/Linux/Cocoa code I've worked on has used the K&R style.

I got the impression that the latter style was rooted from Pascal (or even Algo) programmers where they usually place the "begin" and "end" on separate lines.


If you look at an example BCPL program, you'll see the block style is similar to the second example above, except the closing curly brace is on the same line as the last line of the block - the mirror image of the first example

You can d/l the BCPL reference manual that contains an example program here:

http://www.fh-jena.de/~kleine/history/languages/Richards-BCPL- ReferenceManual.pdf

(This manual is actually from a TYPEWRITER )

The example starts on page 29. BCPL is using $( and $) as the equivalent of { and }

BCPL is the ancestor of B which is the ancestor of C, so this style predates C.




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Style Question (From: "Alex Wait" <email@hidden>)
 >Re: Style Question (From: Robert Claeson <email@hidden>)
 >Re: Style Question (From: Sam Mo <email@hidden>)

  • Prev by Date: Re: Why aren't my bindings firing?
  • Next by Date: Re: switching content views
  • Previous by thread: Re: Style Question
  • Next by thread: KVO Question -- Really Simple for Pros
  • Index(es):
    • Date
    • Thread