Culture is Everything

Rewritten and reposted from a previous post on my personal company blog.

As developers we need to live in many worlds to write effective code. We need to understand multiple languages. And we need to be multi-cultural.

I’ve recently been working in Java. It’s been over 6 years since I dabbled in it, and I didn’t have a good mentor. I learned OOP with PHP (I know, I know, believe me, I know). And the closest I came to cultural Java is ActionScript 3. When coding Flash apps we used annotations, enums, dependency injection, many small classes to increase code-reuse and help with refactoring. I’ve been reminded of AS3 as I work with Java. But I still don’t feel I could write good Java without a template to go off of, without copying someone else’s style. That comes with time.

The past two years I have been working with JavaScript. At first, culture shock. I missed AS3, packages, solid class structure, working with hundreds of classes and files easily. You can’t do that in JavaScript. How are you supposed to organize large amounts of code?? It took me a year before I finally “got it”, fully. Modules are the way to organize related functionality, handle dependencies, and work with large code bases. Each file shouldn’t necessarily represent a class. You don’t write a class for every piece of functionality. Functional programming (to me, like the old days of PHP) is better than OOP in many cases. Lambda functions and callbacks are useful and readable. Function closures are an excellent way to encapsulate data and functions, similar to how classes do for Java. You still use classes, but not like with Java.

You can reduce your JavaScript overhead (size and complexity) by immersing yourself into the JavaScript culture.

Sometimes companies write JavaScript like they do their Java, in the Java culture. With long variable and method names, many classes (for everything), and even sometimes utilities that help provide private, protected, and public variables! They steer clear of closures. They don’t use modules.

When we write JavaScript we should strive to engender a JavaScript culture for our code. And though developers may feel out of place writing this kind of JavaScript, as I did, and as I have recently felt out of place writing Java, with time we will all learn to be multi-cultural.