Re: Are method declarations just comments?
Re: Are method declarations just comments?
- Subject: Re: Are method declarations just comments?
- From: "David P. Henderson" <email@hidden>
- Date: Sun, 8 Jul 2001 09:30:13 -0400
On Sunday, July 8, 2001, at 05:27 , Andreas Monitzer wrote:
>
On Sunday, July 8, 2001, at 08:52 , Chris Gehlker wrote:
>
>
> I'm pretty new to Cocoa, just working my way through "Learning Cocoa"
>
> in
>
> fact. I noticed that the book was having me add methods in .m files
>
> without
>
> declaring them in the corresponding .h file and the programs were still
>
> compiling and running w/o warnings. So I went back and commented out
>
> method
>
> declarations and even changed them so they declared the wrong type of
>
> arguments. Again it didn't seem to matter. I'm beginning to fear that
>
> they're just comments. Someone say it isn't so.
>
>
It isn't so :-)
>
>
Header files are in ObjC (like in C, unlike in C++) just a hint for the
>
compiler and for the user. You can send every message you like to every
>
object, but if it's not declared in the header, the compiler will spit
>
out a warning.
>
And like C, as long as you define a function before you use it, the
compiler won't complain. In Objective-C, return types and parameter
types aren't as important as the method signature. The method signature
is myMethadWith
Data:andFlag:, the compiler will warn you about
mismatches but it won't stop you. Everything in Obj-C is dynamically
bound at runtime, so the runtime only cares that the method signatures
match not the types. Obj-C gives you all the rope you want with which
hang yourself.
Dave
--
Chaos Assembly Werks
"The Trend over the last 20 years or so has been to design computer
languages that enforce a state of paranoia. You're expected to program
every module as if it were in a state of siege In Perl culture, by
contrast, you're expected to stay out of someone's home because you
weren't invited in, not because there are bars on the windows."
from Programming Perl