Issue #4824 has been updated by Lazaridis Ilias.


Clifford Heath wrote:
[...]

>  > But "if __FILE__ == $PROGRAM_NAME" is quite long.
[...]
>  To use an API call requires that the user knows (or looks up)
>  the meaning. This kind of semantic hiding is completely
>  unnecessary and *counter-productive*.
[...]

So maybe all rarely used methods should be written in long descriptive statements, to overcome non-semantic-hiding and become more productive?

There's one simple fact:

"if __FILE__ == $PROGRAM_NAME" is inconsistent with the language's elegant OO design - and I don't think that anyone will counter this.

And at this point, the "dispute" is about the method name.

Which method name would you choose, if you had two choices (.main? | .executed?) ?






----------------------------------------
Feature #4824: Provide method Kernel#executed?
http://redmine.ruby-lang.org/issues/4824

Author: Lazaridis Ilias
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 


The current construct to execute main code looks not very elegant:

if __FILE__ == $0
  my_main()          # call any method or execute any code
end

With a Kernel#executed? method, this would become more elegant:

if executed?
  #do this
  #do that
  my_main()
end

or

main() if executed?

This addition would not break any existent behaviour.



-- 
http://redmine.ruby-lang.org