Forums

Just `base`

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Re: Just `base`

Postby Charles » Thu Jan 23, 2014 12:58 pm

nerdzero is correct.
Charles
 
Posts: 2510
Location: Los Angeles, CA

Re: Just `base`

Postby kirai84 » Thu Jan 23, 2014 1:12 pm

nerdzero wrote:@kirai84, interesting examples. I had to think about it for a bit, but if the intent is that "base" is just shorthand for the explicit call I would expect 'base.someMethod(1)' to be called in the first example and 'base.someMethod(2)' in the second example. Would that be right, Charles?

And what if you want to call a base method with default arguments in the first example? You could do it like this 'base()' or explicitly ('base.someMethod'), but it would be even more inconsistent and confusing.
kirai84
 
Posts: 24

Re: Just `base`

Postby kirai84 » Thu Jan 23, 2014 1:20 pm

I would suggest to use some explicit short syntax like the following
base(*) # or something else instead of '*'
kirai84
 
Posts: 24

Re: Just `base`

Postby Charles » Thu Jan 23, 2014 11:30 pm

kirai84 wrote:
nerdzero wrote:@kirai84, interesting examples. I had to think about it for a bit, but if the intent is that "base" is just shorthand for the explicit call I would expect 'base.someMethod(1)' to be called in the first example and 'base.someMethod(2)' in the second example. Would that be right, Charles?

And what if you want to call a base method with default arguments in the first example? You could do it like this 'base()' or explicitly ('base.someMethod'), but it would be even more inconsistent and confusing.

Do you mean calling an overridden method with default arguments? Like this?
class ClassA
var _ints = List<of int>()
def someMethod(i as int = 0)
_ints.add(i)

class ClassB inherits ClassA
def someMethod(i as int = 0) is override
base.someMethod # didn't pass the value of "i". didn't pass an alternate value. huhwhat?

When you're overriding a method, then you have the same arguments declared and have already received values for them when the overriding method is invoked. Under this proposal, you can implicitly pass your args on with "base" or call the overridden method with explicit args if you want to pass different values. I can't pragmatically imagine getting the value for "i" in ClassB.someMethod but wanting to call back to ClassA.someMethod without the value for "i" and without some explicit alternative such as "i+1", a literal int such as "1", etc.

If you find yourself wanting this, I'd have to wonder if you overrode the correct method. Unless I see a compelling example, I don't consider this an issue.
Charles
 
Posts: 2510
Location: Los Angeles, CA

Re: Just `base`

Postby hopscc » Sat Jan 25, 2014 12:20 am

I second kirai84 - ('base' plus ) some explicit short syntax. ( meaning copy calling values)

otherwise theres an concept override with 2 different outcomes
calling a method with no args/() -> no arg call
calling an overridden method with no args -> some duplicated set of arg values
also using just 'base' is already a shorthand for 'base.overridden_method'

clearer to allow just 'base' but args must be expressed (fully or with shorthand)

class B inherits A
def someMethod(i as int = 0)
base # override call with caller args
.baser # method call with no options (huh?)

# longer arglist and shorthand more useful
def someMethod(i as int =0, s as String, val as GClass)
base.someMethod(i,s,val) # fully expressed
# vs
base(i,s,val)
# vs
base(*) # '*' as explicit notation meaning 'copy of calling args'


( the notation that you are calling a basemethod with the explicit args used is (I think) more useful/clearer than a notational shorthand that you have to decode to determine what it is doing ).

Also (from another direction) what would be the doc statement/sentences/paragraph describing the orig proposal as given ( and compared to non method calls) answering the questions given previously look like ?
hopscc
 
Posts: 631
Location: New Plymouth, Taranaki, New Zealand

Re: Just `base`

Postby Charles » Sat Jan 25, 2014 2:09 pm

class A inherits B

def foo is override
# what does base call look like here, with no args?
Charles
 
Posts: 2510
Location: Los Angeles, CA

Re: Just `base`

Postby hopscc » Sun Jan 26, 2014 3:48 am

class A inherits B

def foo is override
# what does base call look like here, with no args?
# either of
base.foo # as now (shorthand for base.foo() )
# or just
base # call the base overridden method ( no args)
# - shorthand for base.<what I'm in and overriding now>() - i.e base.foo()
hopscc
 
Posts: 631
Location: New Plymouth, Taranaki, New Zealand

Previous

Return to Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron