Let’s have a look at the hello world program in IronPython; the first language to run on the DLR runtime.
By the way, you can see my previous post here: http://carlosqt.blogspot.com/2010/06/oo-hello-world.html
where I give some details on WHY these "OO Hello World series" samples.
By the way, you can see my previous post here: http://carlosqt.blogspot.com/2010/06/oo-hello-world.html
where I give some details on WHY these "OO Hello World series" samples.
Version 1 (Minimal):
The minimum you need to type to get your program compiled and running.
class Greet(object): name = '' def __init__(self, name): self.name = name.capitalize() def salute(self): print 'Hello ', name, '!' # Greet the world! g = Greet('world') g.salute()
Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.
import System class Greet(object): name = '' def __init__(self, name): self.name = name.capitalize() def salute(self): print 'Hello ', self.name, '!' # Greet the world! def main(): g = Greet('world') g.salute() main()
The Program Output:
IronPython Info:
“IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily.” Taken from: (http://www.ironpython.net/)
Appeared:
|
2006
|
Current Version:
|
2.7 beta 1 (latest version in "Languages" page)
|
Developed by:
|
Jim Hugunin
|
Creator:
|
Jim Hugunin
|
Influenced by:
|
Python (Guido van Rossum)
|
Predecessor Language
| |
Predecessor Appeared
| |
Predecessor Creator
| |
Runtime Target:
|
DLR
|
Latest Framework Target:
|
4.0
|
Mono Target:
|
Yes
|
Allows Unmanaged Code:
|
Yes
|
Source Code Extension:
|
“.py”
|
Keywords:
|
31
|
Case Sensitive:
|
Yes
|
Free Version Available:
|
Yes
|
Open Source:
|
Yes
|
Standard:
|
No
|
Latest IDE Support:
|
Visual Studio 2010 (pro, shell, etc + IronPython Tools)
SharpDevelop 3.2/4.0 (beta)
MonoDevelop 2.2
|
Language Reference:
| |
Extra Info:
|
Line 2 in simple and lines 1, 2 & 5 in verbose are entirely superfluous...
ReplyDeleteAdded to which, line 2 in verbose (the import * form) is actually bad practise... (As well as unneeded if you import the System namespace directly - which is itself unneeded in that example because you don't *use* the System namespace.)
ReplyDeleteAllows unmanaged code is wrong - unless I misunderstand your intent. IronPython now *includes* as standard the ctypes module, which is an FFI specifically to allow access to unmanaged code.
IronPython can do unmanaged code easily. Just use clrtype.py to create a DllImport attribute decorator.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete@Michael Foord
ReplyDeleteFirst of all, thanks for your comments. I agree with you that lines 1, 2 and 5 are entirely superfluous, however, my intent is to show the closest program as possible in all the languages mentioned in one of my previous posts "Most Active .NET and JVM Languages", said that I will try to define the variable name even if there is no use on that just to make it clear and other people new to the language understand.
Also, I try to follow the same program structure I mention on the "OO Hello, World!" post:
[Import / using / etc] <--- even if not needed
Class
Data <--- name = '' even if it is not needed
Constructor
Method
Program
Instantiate Class
Call Method => OUTPUT (Hello, World!)
@Michael Foord and @Jimmy
ReplyDeleteThank you for the clarification on "Allows unmanaged code"
I will update the post to reflect it can handle unmanaged code.
The intent of Allow Unmanaged Code is to say that there is support on the language to allow UNSAFE and pointers syntax on the language itself and not that it allows to use COM or Unmanaged through DllImport. Nevertheless it is true that you can interface with unmanaged code so I will update :) thx again.
Carlos - thanks for the reply.
ReplyDeletePerhaps rather than just yes / no for "Allows Unmanaged Code" you could have no / through library / builtin syntax to distinguish the different ways it is supported.
Glad to see the "import *" go and I understand your motivation for keeping the other "superfluous" lines. :-)
you are welcome,
ReplyDeleteI like the "Allows Unmanaged Code" by type idea. I will update previous posts and use it in the next ones.
bytes!