methodName(argumentList)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

methodName(argumentList)

Fatih Sarıkoç
Class foo {
...

method void f (){
...

do g(5,7) // calls method g of class Foo (on this object)
...
  }
}

In such a code, how can we be sure that there was an object constructed/created before? If there is not any object or there is an object in different class, what is the expected result ?
Reply | Threaded
Open this post in threaded view
|

Re: methodName(argumentList)

cadet1620
Administrator
Fatih Sarıkoç wrote
Class foo {
...

method void f (){
...

do g(5,7) // calls method g of class Foo (on this object)
...
  }
}

In such a code, how can we be sure that there was an object constructed/created before? If there is not any object or there is an object in different class, what is the expected result ?
Jack does not do any checking that the programmer correctly called f().  It is up to the programmer to ensure that they supplied the correct type of object.
    function void main()
    {
        var Foo thing1;
        var Bar thing2;
        var Bar badness;

        do thing1.f();    // calls Foo.f() with this = 0, will likely crash

        let thing1 = Foo.new();
        do thing1.f();    // calls Foo.f() with this = the new Foo object

        let thing2 = Bar.new();
        do thing2.f();    // calls Bar.f() with this = the new Bar object

        let thing2 = thing1;
        do thing2.f();    // calls Bar.f() with this = a Foo object, will likely crash
        return;
    }
Neither of the errors in the above code will be detected by the compiler.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: methodName(argumentList)

Fatih Sarıkoç
Thank you Mark for your prompt answer. It is a pleasure for me to meet this community and the book.