📜 ⬆️ ⬇️

Boo is a python-like .NET language

Greetings to dear Habra users, I want to tell you about “one more programming language” bearing the name Boo. This language is surprisingly little-known, but at the same time it is very powerful and convenient, and most importantly, it shows a great example of borrowing good ideas in a new and interesting context, namely the implementation of a language that is syntactically very close to Python as a component of .NET infrastructure.

This note is written primarily from the perspective of a person who has worked with Python in the past, so there will practically be no dotnet here, the next article will be devoted to the specifics of Boo in conjunction with .NET.

Let's turn to a scant Wikipedia article to find out what Boo is.
Boo is an object-oriented, statically typed programming language for the .NET platform. Appeared in 2003. Supports syntax similar to Python.

Python lovers at this point should start rubbing their hands, and for good reason. Python is a very good language, but alas, it is not a panacea for all problems, for example, its dynamic nature does not have the best effect on performance and, alas, IronPython and Jython do not improve the situation much. Of course, you can always take out problematic calculations to external modules, for example, on C, but this means - goodbye the ability to run code on different platforms without recompilation, and how many Pythonists will be happy to write C code ...

This is where Boo comes in handy, it’s most likely that the existing project cannot be run - the syntax is not fully compatible with Python, and the external libraries will have to be replaced by .NET analogues, but to consider it as an alternative when writing new applications is a great idea.

Let's see what the code looks like on Boo, and we will not be sprayed into separate pieces, but let's look at most of the language features in one example (about ducks, they impress me, you know). It can be launched in 3 ways, in the interpreters booish and booi (interactive and non-interactive, respectively), or by compiling the code and running it. Under Linux, the easiest way to do this is to install MonoDevelop with the add-on under Boo, or by booc from the command line.
')
class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  1. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  2. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  3. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  4. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  5. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  6. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  7. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  8. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  9. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  10. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  11. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  12. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  13. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  14. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  15. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  16. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  17. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  18. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  19. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  20. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  21. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  22. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  23. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  24. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  25. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  26. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  27. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  28. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  29. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  30. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  31. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  32. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  33. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  34. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  35. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  36. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  37. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  38. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  39. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  40. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  41. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  42. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
  43. class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .
class BaseDuck: def Quack(times): for time in range(times): print "Quack!" virtual def Fly(): print "Off we go!" def ToString(): return "Hi, I am BaseDuck" eyes = 2 EyesProperty: get : return eyes set : raise "Sorry, but no" class ChildDuck(BaseDuck): def ToString(): return "Hi, I am ChildDuck" override def Fly(): print "I don't know how to fly" testDuck = BaseDuck() print testDuck testDuck.Quack(2) testDuck.Fly() print testDuck.EyesProperty try : testDuck.EyesProperty = 3 except: pass print testDuck2 = ChildDuck() print testDuck2 testDuck2.Quack(2) testDuck2.Fly() print ducks = ( BaseDuck(), ChildDuck(), BaseDuck()) for oneDuck in ducks: print oneDuck oneDuck.Fly() print duckList = [oneDuck for oneDuck in ducks] for oneDuck in duckList: print oneDuck (oneDuck as BaseDuck).Fly() * This source code was highlighted with Source Code Highlighter .


This, of course, is far from the full functionality of the language, while not using the .NET functions at all. Those interested can familiarize themselves with all the features of the language after studying the manual at the link boo.codehaus.org/Language+Guide , we will go over it, comparing the code to what we would have written using standard Python.

So, first of all, we will define the base class BaseDuck, what does a person who is used to Python catch up with?

In my opinion 4 things:

In Python, there is no concept of access level modifiers; all attributes of objects have a public access level. (Emulation of private fields is partly possible through the construction of __, but this construction only changes the order of access to the property). In that case, if it is necessary to determine getter and setter, either decorators of the property @property come to the rescue, and in 2.6 even @ .setter, or get_ and set_ functions. Boo, being a full-fledged heir of .NET, carries with it the entire set of access modifiers, while the eyes variable receives the protected access level by default and cannot be used from outside the class. But the default EyesProperty is public , and allows you to set the values ​​of the eyes variable. In this particular case, we will not give the set value, but throw out an exception (this does not make much sense, I just like ducks with 2 eyes the most).

Attentive habrachelovek may suddenly wonder why there are no declarations like variables anywhere, because Boo is a statically typed language? And this is one of the most pleasant features of the language, wherever possible the compiler will determine the types of variables for us. At the same time, no one bothers to write us for example

eyes as int = 2

thus clearly indicate what type of variable.

The next step is to define the child's duck class, its base class is the class of the basic duck, previously created by us, which means that all the properties of the basic duck will be available for the child's duck.
Now is the time to return to the Fly function defined in the basic duck, as can be seen from the child duck code, the Fly function is defined as override .

We could omit the definition of the virtual function and its overlapping, and thus get the code again exactly the same with the Python implementation, but could potentially step on the rake associated with static typing. A pair of virtual - override ensures that the child’s duck will be called precisely by its function, and not the function of the parent class (If this is not clear, I advise you to ask Google about Virtual Functions). We can erase these definitions and see how the output of the program changes - in line 55, the constructor of the base duck will be called up three times, despite the fact that the second element is created as an object of another class.

Next, in the code, we create an object of type BaseDuck (line 30), we look at how its string representation is fulfilled (line 31), we call functions (noticing that Boo supports generators), and we also read and try to set the values ​​of the eyes property. Since we cannot establish it, we demonstrate silent hiding of an exception in try - except (36-41) blocks.

Having played enough with the first duck, we create a duck child and see how the function defined in its class replaces the parent function. (This code will work in the same way without virtual - override directives, because the type of the variables is set explicitly)

But line 52 may seem confusing. But everything is simple, we create an array with BaseDuck elements and initialize it with 3 ducks, which we create on the fly. At the same time, oddly enough, we can write and

ducks = (BaseDuck (), ChildDuck (), BaseDuck ())

Boo will create an array of objects of type object, but will check that all subsequent calls work as it should, and will not even require casting objects using one of the elements of the array if we want to call some BaseDuck property.

And finally, we will create a list of objects using the excellent Python syntax and reiterate it again like an array, but here we will have to specify the type of the object, because the list unfortunately does not know anything about what is placed in it.

As you can see, the language is syntactically very close to Python, which means writing on it quickly and pleasantly.

Advantages and disadvantages

Without claiming objectivity, I will describe the pros and cons of Boo, which were found in the process.

pros
Minuses

Links
Official site

Source: https://habr.com/ru/post/66592/


All Articles