Pony ORM

I didn’t know how much I didn’t know about the internals of python until reading about
Pony ORM. This ORM allows one to query SQL databases using python-like syntax. For example:

select(p for p in Product)
select((p1, p2) for p1 in Product for p2 in Product if p1.name == p2.name and p1 != p2)
select((p.name, count(p.orders)) for p in Product)

There is a good explanation of how on StackOverFlow. Basically, PonyORM compiles the parameter to select (which is python code) using the python compiler and converts the python AST into SQL.

This blows my mind.

Hello, World!

I have noticed that I tend to say “I’m sorry about that” when someone tells me that they learned to program in Java. I really mean it when it is a student in our department (which, unfortunately, teaches Java as an introductory language). To understand why Java is such a rotten first language, let’s consider a typical instance of “Hello, World!” in Java.

class hello
{  
        public static void main(String args[])
        {
           System.out.println("Hello World!");
        }
}

It is only a handful of lines of code but how many concepts presented in this code? The following list is, sadly, not exhaustive. But in addition to the (1) language syntax you need to understand (2) classes, (3) class methods, (4) public, (5) static, (6) types (String and void), (7) arrays, (8) types libraries (i.e., System), and (9) namespaces. (Did I miss anything?) That is too much to learn up front. Therefore, students are told “do this; we’ll cover it later.”

Additionally, there are many other ways to trip up. For example, the method must be named main.  The type void must be all lowercase, whereas String must be mixedcase.

Compare this to “Hello, World!” in Python.

print "Hello, World!"

This is not just shorter, but it is clear and obvious.

But that is not all. Consider what is need to execute the program. In java, you have to compile the code first and Java is nasty to work with because of silly requirements such as a single source file can contain only one public class and its name must match with name of file. Therefore, if you didn’t name the above file “hello.java” it will cost you an hour of your life–well, that’s what I paid for this “knowledge.” The effort is so taxing that students (with instructors’ encouragement) use an IDE so that students don’t have to learn (and instructors don’t have to teach) what is really going on.

On the other hand, we execute our Python program (assuming it is in the file named spam.py–why? because we can):

python spam.py

Java is a horrible instructional language.

QED.