Re: WEIRD bug thing; 'shared' as reserved word? can you explain it?
Re: WEIRD bug thing; 'shared' as reserved word? can you explain it?
- Subject: Re: WEIRD bug thing; 'shared' as reserved word? can you explain it?
- From: "Marcelo Ruiz Camauer" <email@hidden>
- Date: Fri, 7 Feb 2003 11:08:39 -0300
When coding systems here in Argentina I use Spanish names for variables and
methods/procedures, even though it makes the code look like it's written in
Spanglish. I could use English just as easily, but I find that it's useful
to avoid these kinds of problems with reserved words. It also makes "my"
code stand out more from the framework code, so that for someone just coming
into the project and maybe the technology, it's easier to distinguish what
they are looking at.
There would be many advantages, likewise, to doing everything in English,
besides coherence. If I found someone I could sell my code to, it would be
a much easier sell. But most systems are not generic, and this way I don't
have to keep a list of reserved words handy.
What position do the rest of you take, from non-English-speaking countries?
Regards,
Marcelo Ruiz Camaukr
----- Original Message -----
From: "Jonathan Rochkind" <email@hidden>
To: <email@hidden>; <email@hidden>
Sent: Thursday, February 06, 2003 6:20 PM
Subject: WEIRD bug thing; 'shared' as reserved word? can you explain it?
> Okay, I kind of have this figured out now, but it took me half a day to
> track down. Can anyone explain why 'shared' is a name you should avoid
> using for an attribute in your EOs? In my migration from 5.0 to 5.2, I
> discovered this. Even though it didn't cause a problem in 5.0, it caused a
> weird problem I can't entirely explain in 5.2, but changing the attribute
> name fixed it.
>
> For those really interested, here's a description. If you can come up with
> a coherent explanation of what's going on, you get my eternal respect as a
> true WebObjects genius-guru-expert.
>
> I have an attribute called 'shared'. I use it as a boolean switch,
> although in the db it's a numeric type. In 5.0, this means EOF would
return
> it as an Integer, and I wrote my own method to convert it to a small-b
> boolean, no problem:
> public boolean shared() {
> return numberToBoolean( storedValueForKey("shared" );
> }
> public void setShared(boolean newShared) {
> takeStoredValueForKey( booleanToNumber( newShared ), "shared");
> }
>
> Everything worked fine, but (this is important in a second), there COULD
be
> null values in the db. No problem, my conversion method converted them to
> false. There were no problems.
>
> Now, I convert to 5.2. In 5.2, if you have an attribute named 'foo', and
a
> method named foo() returning a boolean, like I had for 'shared',
> storedValueForKey will automatically translate the numeric data to a
> capital-B Boolean. Of course, I'm using a small-b boolean, no big deal,
> but now my methods can simply look like this:
> public boolean shared() {
> return ((Boolean) storedValueForKey("shared")).booleanValue();
> }
> public void setShared(boolean newShared) {
> takeStoredValueForKey( new Boolean(newShared), "shared");
> }
>
> Okay, no problem, for values in the db 1 and 0 (which is most of them),
> this actually works fine. BUT. For null values in the db.... upon
fetching
> a row that has a null in the 'shared' column, I get an key value coding
> exception, unable to assign null to key shared. Of course I can't assign
> null with the setShared method, but why is it even using the setShared
> method, it should just be using takeStoredValueForKey to initialize the
new
> EO, no? And the million dollar question---if my attribute is called
> anything else but shared, this works FINE. NULL is reasonably translated
> to a Boolean 'false', there is no exception. It's only when the attribute
> is called 'shared' that there is a problem.
>
> So, after a day of messing with this, I know I need to change the name of
> my attribute to something to something other than 'shared'. Good enough,
> it's a pain to make sure I haven't missed any EOQualifiers with 'shared'
in
> them, but at least I know what must be done. But I am still completely
> baffled as to why. What's so special about the word 'shared' that makes
> things fail in such a truly bizarre way----that is, only fail in very
> unusual circumstances (null value in the db that normally you wouldn't
> expect), and only when the attribute is named 'shared'. Anyone?
>
> --Jonathan
> _______________________________________________
> webobjects-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
> Do not post admin requests to the list. They will be ignored.
************************************************************************
Visite http://www.bancorio.com.ar y tenga el Banco al alcance de su mano.
************************************************************************
NOTA DE CONFIDENCIALIDAD / CONFIDENTIALITY NOTE
Este mensaje (y sus anexos) es confidencial y puede contener informacion
(i) de propiedad exclusiva de Banco Rio de la Plata S.A. sus afiliadas o
subsidiarias; o (ii) amparada por el secreto profesional. Si usted ha
recibido este fax o e-mail por error, por favor comuniquelo
inmediatamente via fax o e-mail y tenga la amabilidad de destruirlo; no
debera copiar el mensaje ni divulgar su contenido a ninguna persona.
Muchas gracias.
This message (including attachments) is confidential. It may also
contain information that (i) is exclusively property of Banco Rio de la
Plata S.A. or its affiliates or subsidiaries; or (ii) is privileged or
otherwise legally exempt from disclosure. If you have received it by
mistake please let us know by fax or e-mail immediately and destroy or
delete it from your files or system; you should also not copy the
message nor disclose its contents to anyone. Thank you.
**************************************************************************
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.