Talk:Program name: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
(→‎Java entry: I think it's still wrong)
Line 11: Line 11:
:: Strange. It printed 'Test' yesterday when I tried it. But maybe I made a change to the code after that. I've added a body to new Object, now it works again. Anyway, the System.getProperty thing is even better. [[User:Fwend|Fwend]] 07:54, 6 August 2011 (UTC)
:: Strange. It printed 'Test' yesterday when I tried it. But maybe I made a change to the code after that. I've added a body to new Object, now it works again. Anyway, the System.getProperty thing is even better. [[User:Fwend|Fwend]] 07:54, 6 August 2011 (UTC)
:::I agree, it's pointless to hardcode the class and then ask for it as a string. Thanks Fwend and Mwn3d for correcting the example. --[[User:Mcandre]]
:::I agree, it's pointless to hardcode the class and then ask for it as a string. Thanks Fwend and Mwn3d for correcting the example. --[[User:Mcandre]]
:::I think it's still not right. The main method can be called from another class, since it's public. You could run the class Test2 which calls <code>Test.main(args)</code> in its main method. The desired output for this task would be "Test2" since that's the "script" that was run, but that example would still print "Test". --[[User:Mwn3d|Mwn3d]] 17:58, 6 August 2011 (UTC)


==Question on the goal of the task==
==Question on the goal of the task==

Revision as of 17:58, 6 August 2011

Java entry

The Java entry is kind of funny because it requires you to type the name of the class in order to print it. Then you might as well print it directly. It really should be using reflection. I've never used reflection in Java, but a after a glance at the documentation, I came up with this. Fwend 03:26, 6 August 2011 (UTC)

<lang java>public class Test {

  public static void main(String[] args) {
      Class c = new Object(){}.getClass().getEnclosingClass();
      System.out.println(c.getName());
  }

}</lang>

That doesn't work. There is no enclosing class for Object so it's an NPE when you try to get the name. I'll correct the example. --Mwn3d 04:32, 6 August 2011 (UTC)
Strange. It printed 'Test' yesterday when I tried it. But maybe I made a change to the code after that. I've added a body to new Object, now it works again. Anyway, the System.getProperty thing is even better. Fwend 07:54, 6 August 2011 (UTC)
I agree, it's pointless to hardcode the class and then ask for it as a string. Thanks Fwend and Mwn3d for correcting the example. --User:Mcandre
I think it's still not right. The main method can be called from another class, since it's public. You could run the class Test2 which calls Test.main(args) in its main method. The desired output for this task would be "Test2" since that's the "script" that was run, but that example would still print "Test". --Mwn3d 17:58, 6 August 2011 (UTC)

Question on the goal of the task

Hi, Is it to:

  1. Give the name of the executable for compiled code
  2. Give the name of the file being interpreted in the case of interpreted code.

The task description seems OK for interpreters, but the C example does not fit the task. Maybe the task description needs an update? --Paddy3118 02:43, 6 August 2011 (UTC)

The point is to identify the program name, which may mean different things in different languages. For compiled languages, the best you can do is identify the final executable. For interpreted languages, the program is often considered to be the source code file name. --User:Mcandre

Re-title?

Suggest the task be renamed "Script name" which is more in line with RC style? --Paddy3118 02:46, 6 August 2011 (UTC)

+1 --Mwn3d 04:32, 6 August 2011 (UTC)
+1 Sure, I don't mind. Consistency above all. --User:Mcandre