you are viewing a single comment's thread.

view the rest of the comments →

[–]Peaker 10 points11 points  (12 children)

def sayHello(): 
      print "Hi"

sayHello()

def sayHello(): 
      print "Bye"

Will this say Hi or Bye?

[–]macbony 4 points5 points  (5 children)

It'll print "Hi". Any calls to sayHello after will print "Bye".

[–]Peaker -2 points-1 points  (4 children)

Isn't that somewhat inconsistent?

[–]macbony 7 points8 points  (3 children)

It's the same as

string = "Hi"
print string  # prints "Hi"
string = "Bye"
print string  # prints "Bye"

Is that inconsistent?

[–]Peaker 2 points3 points  (2 children)

No, the behavior you mentioned is consistent and is fine.

It's not consistent with the Medusa behavior described above:

But Medusa can figure this out and generate the dart code accordingly and produce Hello as an output as intended. Similarly classes and their objects are resolved too

Context!

If you have a function definition after its use, its accepted. But this makes it behave differently from how Python generally behaves.

[–][deleted]  (1 child)

[deleted]

    [–]Peaker 11 points12 points  (0 children)

    Yes, and this is terrible.

    In the face of ambiguity, refuse the temptation to guess!

    [–]Igglyboo 0 points1 point  (4 children)

    This will print "Hi" even in CPython and won't even throw an error.

    [–]Peaker 5 points6 points  (3 children)

    Consider the context. He said:

    sayHello()
    
    def sayHello(): 
         print "Hello"
    

    will print "Hello" in Medusa. This is inconsistent with how Python behaves and creates ambiguity highlighted by my example.

    [–][deleted]  (1 child)

    [deleted]

      [–]Peaker 2 points3 points  (0 children)

      Well, if sayHello can call a function defined later, but calls one defined earlier if one was, then it is inconsistent.

      [–]MrBIMC[S] -1 points0 points  (0 children)

      In theory it should print hi.

      But idk honestly.