![]() |
Declare Members at top of Class or Just Before Use? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Declare Members at top of Class or Just Before Use? (/showthread.php?tid=34729) Pages:
1
2
|
Declare Members at top of Class or Just Before Use? - El Forum - 10-11-2010 [eluser]OliverHR[/eluser] [quote author="n0xie" date="1286696727"]One usually doesn't 'declare' variables.[/quote] I mean declaring in general programming terms. Declaring Variables [quote author="n0xie" date="1286696727"]The right way to do it, is to declare them at the top of your class so that whenever another developer looks at your class.[/quote] I think is better to use comments for this. Anyway it is my point of view. Declare Members at top of Class or Just Before Use? - El Forum - 10-11-2010 [eluser]n0xie[/eluser] [quote author="OliverHR" date="1286828043"][quote author="n0xie" date="1286696727"]One usually doesn't 'declare' variables.[/quote] I mean declaring in general programming terms. Declaring Variables What use would declaring a variable have in a dynamic weak typed language? [quote author="n0xie" date="1286696727"]The right way to do it, is to declare them at the top of your class so that whenever another developer looks at your class.[/quote] I think is better to use comments for this. [/quote] You use comments to declare class properties? Declare Members at top of Class or Just Before Use? - El Forum - 10-11-2010 [eluser]OliverHR[/eluser] [quote author="n0xie" date="1286831764"]What use would declaring a variable have in a dynamic weak typed language?[/quote] Man I never say that, you Do [quote author="n0xie" date="1286547958"]If you declare them at the top, you get the added bonus that your IDE will pick them up and will help you when using them.[/quote] Even I think it is the right way no matter if php, vb6 an so... let to put variables in any place. what I say its if a variable its only used inside a method whay "Declare" it as a class property. [quote author="n0xie" date="1286831764"]You use comments to declare class properties?[/quote]You are confused. Anwser: No, I not, comment everything, but beacuse I forget to do. But in my work I always must comment everything.(If I miss to comment my code, I could get fired) Code: ... ??? As I say It is my point of view, I am not forcing you to do things like me. Declare Members at top of Class or Just Before Use? - El Forum - 10-11-2010 [eluser]techgnome[/eluser] I think there's some confusion here... I don't think any one said that you should declare class level variable just for use inside of a function... Even still ... if you are to use a varaible inside a function, do you declare it at the top of the function, or on the line just before you use it? So, let's consider a different code example that is less trivial a User class... with three public properties:FirstName, LastName and EMail. Let's also say that there are two methods, one for getting the name ,one for the email. Which of the following would you do it: Code: // Option 1 - OR - Code: // Option My preference is to keep all my vars at the top of what ever block/scope in which I plan to use it. -tg |