Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is judging a fish on it's ability to fly. In other words, it is judging an object oriented program on its ability to resemble top-to-bottom sequential execution style programming, while ignoring that the language is commited to a different paradigm.

Some of the criticism is really superficial:

    function createEmployee(firstName, lastName) {
        return {
           firstName: firstName,
           lastName: lastName,
       };
    }

OO-Programs have these weird factory functions called constructors that do exactly that. To me, it makes sense that such functions should share their living space with the class that they are creating. Where else would you like to put these functions? "Utils"?

As for classes, namespaces and objects: as others have pointed out, this is an implementation detail. In Python, for example, classes are objects. Besides, classes and objects are functions (and the other way around) so it doesn't matter all that much in practice.

What buggs me more is code like this:

    class SayHello {
        public static void toPerson(String name) {
            System.out.println("Hello " + name);
        }
    }

Sure, comparing it to an empty Python file which just says "print" this looks like an aweful lot of code. However if the paradim is poorly understood, it will seem to be working against you:

    class Name {
        public Name (string name) {
            this.name = name;
        }

        public static void greet() {
            System.out.println("Hello " + this.name);
        }
    }

The programming is different in that you create a declarative network of objects that then ... act. At this level, there is hardly any difference, except that the name has been introduced as a proper concept. Many people will argue that such value objects are expensive or inefficient (which they are) but if that cost hits you hard, you should be asking yourself why you picked a high level language to begin with.

Yes, in such a paradigm a place is needed where the entry point lives, but I found it fundamentally useful. Whatever you call the class it: - Can read and encapsulate access to env variables - It can accept commandline arguments (as main(argv[]) indicates) - It's the place to setup and configure your (object)- dependency tree (what IoC/Dependency Injection-Containers are doing) - Or it can be the ultimate exception handler for messages deeper in your program, e.g. where you would start your main message pump / game loop, etc.

The rest is ergonomics.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: