discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Properties and objc1


From: Riccardo Mottola
Subject: Re: Properties and objc1
Date: Fri, 17 Aug 2018 21:44:42 +0200
User-agent: Mozilla/5.0 (X11; NetBSD i386; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

Hi,

Ivan explained it already to you, although some matter of taste remains.

I have converted a lot of obj-c2 code a couple of years ago and got quick about it.


I do not like using _ in variable names except in private ivars


On 08/17/18 12:06, Bertrand Dekoninck wrote:
Hi everyone on the list.

I'm enjoying my summertime to do some gnustep stuff. I want to convert the rik.theme to objc1 because I can't have libobjc2 running on my ppc computers.

Fine idea. libobjc2 has issues with gcc, since I cannot use libobjc2 with gnu-gnu-gnu but only with ng-gnu-gnu both with clang and gcc. I was unable to write the testcases David requested and did not pursue that further, I'll ping him again.

As long as you don't have blocks it is quite an easy but tedious rewrite. That's what properties were probably invented for, but their syntax is so ugly I can't stand them.


For now, I'm dealing with properties.

I've managed to convert this one :

@property (retain) NSButtonCell * defaultbuttoncell;

into :

- (NSButtonCell *) defautbuttoncell {
  return defaultbuttoncell;
}

that is fine. I'm with ivan for naming it defaultButtonCell and if that is taken understand why you need two.

- (void) setdefaultbuttoncell: (NSButtonCell *) defaultbuttoncell_ {
  [defaultbuttoncell_ retain];
  [defaultbuttoncell release];
  defaultbuttoncell = defaultbuttoncell_;
}

I would write this differently, just for taste:


- (void) setdefaultbuttoncell: (NSButtonCell *) aButtCell {
  if (defaultbuttoncell != aButtCell)
   {
    [defaultbuttoncell release];
    defaultbuttoncell = aButtCell;
    [defaultbuttoncell retain];
}
}

I like it that way because it is clear that you "release" and "retain" the IVAR. since you do not want to release the same object you are assigning to, you check it is really a different one. This is important! otherwise you would release it before assigning and retaining it!
I learned it the hard way tracking strange crashes...




And I  want to be sure for this one because of the non atomic and assign attributes :

@property (nonatomic, assign) BOOL reverse;

is replaced by :

- (BOOL) reverse {
  return reverse;
}
- (void) setReverse: (Bool) reverse_ {
  reverse = reverse_;
  }

except for BOOL and Bool, it is correct. Avoiding _ applies too.


Happy hacking,

Riccardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]