All Questions

927
votes
6answers
236616 views

How do servlets work? Instantiation, sessions, shared variables and multithreading

Suppose, I have a webserver which holds numerous servlets. For information passing among those servlets I am setting session and instance variables. Now, if 2 or more users send request to this serve...
182
votes
12answers
81080 views

Should I instantiate instance variables on declaration or in the constructor?

Is there any advantage for either approach? Example 1: class A { B b = new B(); } Example 2: class A { B b; A() { b = new B(); } }
102
votes
6answers
28416 views

Do declared properties require a corresponding instance variable?

Do properties in Objective-C 2.0 require a corresponding instance variable to be declared? For example, I'm used to doing something like this: MyObject.h @interface MyObject : NSObject { NSString *n...
134
votes
4answers
83797 views

Ruby class instance variable vs. class variable

I read "When do Ruby instance variables get set?" but I'm of two minds when to use class instance variables. Class variables are shared by all objects of a class, Instance variables belong to one o...
52
votes
4answers
17262 views

Must every ivar be a property?

I see it recommended all over the place when coding for iOS that properties should be used for accessing instance variables because of the benefits this lends to memory management, among other things....
72
votes
3answers
21345 views

Are ints always initialized to 0?

Is it safe to count on ints always being initialized to 0 in Objective-C? More specifically, when an object with int ivars has been newly instantiated, is it safe to assume that its ivars have value ...
79
votes
2answers
18487 views

What is the difference between ivars and properties in Objective-C

What is the semantic difference between these 3 ways of using ivars and properties in objective-c? 1. @class MyOtherObject; @interface MyObject { } @property (nonatomic, retain) MyOtherObject *othe...
9
votes
4answers
1873 views

Is there any reason to declare ivars if you're using properties exclusively in Objective-C?

I tend to use properties exclusively in my classes, especially now that you can declare properties in a class extension thanks to the modern Objective-C 2.0 runtime—I use this feature to create "pri...
157
votes
6answers
29584 views

Instance variable: self vs @

Here is some code: class Person def initialize(age) @age = age end def age @age end def age_difference_with(other_person) (self.age - other_person.age).abs end protected ...
124
votes
5answers
67518 views

What does @@variable mean in Ruby?

What are Ruby variables preceded with double at signs (@@)? My understanding of a variable preceded with an at sign is that it is an instance variable, like this in PHP: PHP version class Person { ...

Previous Next