From: Lew on
Pidgeot18(a)verizon.invalid

How come you don't use the handle for citations, but the email address? I
know that "pee-djyo" means "beer" in Mandarin, but I really, really had to
work to figure out that you were quoting Joshua Cranmer, who
> says...
>> Even C++ requires that superconstructors be called before the
>> constructor executes (although it does permit you to wrap the whole
>> initializer in a try-catch block, which was incidentally the feature
>> that originally prompted this IIRC).

Pitch wrote:
> I belive Java picked it up from C.

Picked what up? Not constructors, surely.

Joshua:
>> I can't think of a language which treats constructors as regular
>> methods.

Pitch wrote:
> Delphi has virtual constructors but bas class TObject has a non-virtual
> empty destructor which you cannot override.

That doesn't say that Delphi (i.e., Pascal, right?) treats constructors as
regular methods. Does it?

> In the other thread I mentioned some .NET languages have this rule, but
> some don't like VB.NET, and the compiled code is interchangeable. It is
> perfectly ok to use a class with such loose constructor in C# e.g.

That doesn't say that those .NET languages treat constructors as regular
methods. Do they?

Joshua:
>> It is a very sensible restriction, and the expectation by programmers
>> coming from other languages is that it will be. Constructors have the
>> notion of actually reserving the memory space and then initializing it
>> at the same time--hence we have the `new' keyword and the actual
>> constructor call. If you were to separate the memory space reservation
>> and initialization out, then it would make sense to allow constructors
>> to be called multiple times. But Java doesn't allow you to do so, so the
>> point is moot.

Pitch wrote:
> I belive we have three steps in object construction: memory allocation
> (new), member initialization, and constructor body execution. Keyword
> new is also used in allocating structures bz name or by a pointer.

Java?

> I can also add that memory allocation means the object is alive at that
> moment we have a refetence to this. After is only language specific
> implementation.

--
Lew
From: Mike Schilling on
Pitch wrote:
> In article <hl4729$j8s$1(a)news.eternal-september.org>,
> mscottschilling(a)hotmail.com says...
>>
>> Pitch wrote:
>>> In article <hl1ban$hes$1(a)news.eternal-september.org>,
>>> mscottschilling(a)hotmail.com says...
>>>>
>>>> Pitch wrote:
>>>>> In article <hkvi82$usn$1(a)news.eternal-september.org>,
>>>>> mscottschilling(a)hotmail.com says...
>>>>>>
>>>>>> Suppose the call to "super()" needn't be the first line of a
>>>>>> constructor. Discuss the effect and/or legality of the following
>>>>>> code:
>>>>>>
>>>>>> class MyClass extends YourClass
>>>>>> {
>>>>>> public MyClass(int i)
>>>>>> {
>>>>>> if ( i > 0)
>>>>>> {
>>>>>> super(i);
>>>>>> }
>>>>>> }
>>>>>> ...
>>>>>
>>>>> If you look at super() as just another method call it's perfectly
>>>>> ok.
>>>>
>>>> But it isn't "just another method call", which is the point of the
>>>> example. It's the call that guarantees that the superclass,
>>>> starting from a completely uninitialized state, has been fully
>>>> initialized. It needs to be called precisely once, and that needs
>>>> to be done before any instance methods are called or instance
>>>> fields accessed.
>>>
>>>
>>> I though we are talking about changes in the language so it doesn't
>>> mater if it's not a method right now, or if it's allowed only once
>>> to be called. If we are talking of possible changes to Java it
>>> could be just another method and it could be called more than once,
>>> ok?
>>>
>>> In that case your example works perfectly ok.
>>
>> As I explained above, it breaks all guarantees about class
>> construction. That's a bad thing.
>
> Well, I keep talking hypothetically and you keep sticking with Java.
> Nevermind.

I would have said that I keep explaining that conventions and rules are
important for keeping software comprehensible and reliable, and you keep
saying "but that gets in the way of hacking".


From: Tom Anderson on
On Fri, 12 Feb 2010, Joshua Cranmer wrote:

> On 02/12/2010 09:59 AM, Pitch wrote:
>> In article<U5mdnVQN4rmk9ejWnZ2dnUVZ_qSdnZ2d(a)earthlink.com>,
>> pats(a)acm.org says...
>>>
>>> Pitch wrote:
>>> ...
>>>> I though we are talking about changes in the language so it doesn't
>>>> mater if it's not a method right now, or if it's allowed only once to be
>>>> called. If we are talking of possible changes to Java it could be just
>>>> another method and it could be called more than once, ok?
>>> ...
>>>
>>> That would be the most dangerous possible type of change to the
>>> language, one that changes the semantics of existing syntax.
>>
>> Of course. I don't think this can be changed, I just want people to
>> agree this restricton should have not be introduced at all.
>
> Even C++ requires that superconstructors be called before the constructor
> executes (although it does permit you to wrap the whole initializer in a
> try-catch block, which was incidentally the feature that originally prompted
> this IIRC).
>
> I can't think of a language which treats constructors as regular
> methods. C++ lists it as a "special member function", it's one of two
> special functions in Java (the other being, essentially, <clinit>). I
> think python also treats it specially as well.

I can't think of anything special about it in python. Consider:



Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
.... def __init__(self, bar):
.... self.bar = bar
....
>>> f = Foo(23)
>>> f.bar
23
>>> f.__init__(17)
>>> f.bar
17
>>> class Bar(Foo):
.... def __init__(self, qux):
.... self.qux = qux
....
>>> b = Bar("fnord!")
>>> b.qux
'fnord!'
>>> b.bar
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Bar' object has no attribute 'bar'



That is, you can call an __init__ method on an already-constructed object,
and construction doesn't implicitly call the superclass __init__. There's
the special semi-magic super function (actually, a class) that you have to
use if you want to invoke a superclass __init__ function.

I suppose the subtlety is that __init__ isn't a constructor - it's an
initialisation method. It gets called by the construction code, but it's
just a normal function itself.

tom

--
First man to add a mixer get a shoeing! -- The Laird
First  |  Prev  | 
Pages: 2 3 4 5 6 7 8 9 10 11 12
Prev: Ugly SAX
Next: Ploblem doing HTTP POST via URLConnection