A friend of mine, who loves C# and gonna play with Python, asked me about the file hierarchy of the pythonic module/package. For every Java or C# users it’s a bit different.
In the beautiful world of Java, a file is a class. Everything is clean and at it’s own place. The file hierarchy reflects the package hierachy. It can be the jungle in the directories.
package/Foo.java import package package/bar/Bar.java import package.bar
With C#, which is very (very) similar to Java, the one class per file is the usual way to do, but you aren’t forced to. And the hierarchy is also the namespace hierarchy (or not). In the example bellow the both files can be in completely different namespace, strange isn’t it?
package/file.cs using Package package/file2.cs using Package.Foo.Bar
With Python, it’s much more fun because a directory is a package if it
contains a __init__.py
file. You can use this packages with
use directory
. .py
files in it are
modules, you can use them with use directory.file
(without the extention). A module (a file) can contains lots of
variables, functions and classes. For every Java/C# coder it’s very messy.
package/__init__.py use package package/module.py use package.module package/foo/__init__.py use package.foo package/foo/bar.py use package.foo.bar
I don’t think this is messy, this is flexible. You can arrange thing exactly how you will use them.
I’ve written a very messy implementation of the State Pattern in both C#
and Python just for the fun.
C# is full of public
, private
, abstract
,
override
... but in Python you need (if you want) to check
the type of the data you receive. (I definitely love Python but, you
can do a very similar job in both languages). Oh, there is no
documentation because it’s very basic (google around about this design
pattern if you want).
For the curious, I’ll stay in Switzerland for a while. The Dublin offices will not hire me (for the moment, keep believing).