Lets see same program written in java and python . I cannot understand the motive behind python's behavior .
prog.py :
#!/usr/bin/python
print "Hello, World!\n"
def hello(name):
print "Hello " + name
print sample
#hello("harish")
Prog.java
public class Prog {
public static void hello(String name) {
System.out.println("Hello " + name);
System.out.println(sample);
}
public static void main (String... args) {
System.out.println("Hello, World!\n");
//hello("Harish");
}
}
The above python code prog.py executes without any problem but Prog.java raises errors .
My arguments
1) I would prefer python is good , looking from the angle that I need not bother about it until I call the function hello(name) . If i called the function during execution phase , then an error would be flung as "NameError: global name 'sample' is not defined".
2) But it looks danger by looking at the angle that it might fling such errors in execution time . But java tells all these things even during compile time .
3) also if I want to distribute the python code as .pyc file , using py_compile.compile("prog.py") . The pyc file is generated without warning that 'sample' is an undefined variable . This puts me at risk because these errors might be discovered in production ,which is too dangerous .
What am I to interpret from this type of working of python . Why is it designed to be so ? what is the advantage in not being so strict while compilation (py -> pyc ) ? Is it not dangerous ?