Scrame

August 8, 2010

Daily #218: Rouguelike in 15 steps.

Filed under: Java,daily — scrame @ 6:14 pm

Stumbled across this when looking for 2D browser game engines. Almost a little inspiring. Though the first few steps for me are the most infuriating (maps and inputs).

http://roguebasin.roguelikedevelopment.org/index.php?title=How_to_Write_a_Roguelike_in_15_Steps

There is an associated article on savefiles:

http://roguebasin.roguelikedevelopment.org/index.php?title=Save_Files

Most of the article is about preventing cheating. My take on save files is that they are data files. People who cheat cheat, people who don’t, dont. I think ease and flexibility of programming are the most important things in just making something like this. If you want to see failures in trying to enforce protected data files, see everything activision has done for the last couple years.

Thinking on this, my first impression was YAML, a readable json. From recent adoption of sqlite through some popular projects (openoffce, mozilla, mongrel2), I considered that, but figured I would rather deal with an editable file that just mapped to a simple dynamic map. SQL is just too heavy. On the other hand, if I were implementing a plug-in system for a roguelike where each place would need distinct data, from disparate sources, then something a little more standardized than a flat file of pretty-printed json would be in order. In this case, though the point is trying to start small. So is saving that kind of state an initial design decision?

Anyway, just musings.

May 19, 2010

Daily #136: Some ill fated tech work.

Filed under: Java,Technology — scrame @ 10:17 pm

I worked through a short tutorial on jquery (its actually already better than what I was doing for an alert(“hello!”) ).

I’ve been curious as to how protocol buffers would work in python, but I’m mostly unfamiliar with it (only done a couple project euler problems with it — easy ones). Unfortunately I just ran out of time tonight, but I did manage to set up a basic environment for it.

I don’t really have a good reason for trying to figure out either of these things except that they are both languages that could interface easily and usefully with the dull grind of code I have to do at work (see: java gripes). While I do appreciate the stability and instrumentation of the JVM, it does suck that there is not a convenient command-line interface to a typical tomcat (or whatever kind of server) interface. They would probably all have deep dependencies to the core model libraries, or need the whole codebase, or configbase or some awful thing.

Being able to create a strongly typed message in python and then just post it to a backend service as a strongly typed java object allows fine grained control, and both messages created against an identical, versioned spec reduces errors in the communication. Long and the short: it would be much easier to write a command dispatch controller in java that just takes messages posted from python, and then write a suite of command and configuration scripts in python (or maybe just a simple dashboard) to control operational issues is much easier than sending XML documents back and forth. Or just curling a great programmer UI, scraping the exact values and automating the response.

Anyway, I had a bit of work to automate it all, but its worked very well for java, so I am encouraged to find a binding to a scripting language so I dont have to live between jUnit and the java debugger.

May 15, 2010

Daily 133#: Java notes part 2 — Eclipse.

Filed under: Java,Technology,daily — scrame @ 9:47 pm

[ Welcome to the second part of java notes. This is in the dislikes pile. ]
I use eclipse for two things: editing java and debugging java. Any other file or task I do in the linux shell, and if I could find better tools for working with java, I would certainly use them. I use emacs in a screen session as a primary editor, and do all my systems work in zsh, with a handful of shell scripts and perl scripts. In the past I have done a fair amount of systems work with

Everyone on my team, and in my general area uses eclipse to work with java, I have tried making the switch to IntelliJ many times, but since I can’t get a work license for it, and no one else uses it around me, it is doubly hard to make the transition (being able to work with people around you to fix problems with the same toolset is hard to match for learning at any level. The problem is, eclipse just sucks. There is probably a great IDE under all of it, but every version I’ve tried (plain, MyEClipse, STS) always ships “convenience” plug-ins that do nothing but get in the way. They also don’t work very well.

An example: plain eclipse wants to work with Maven (the others do, too). I am not using Maven, I will never use Maven, its a huge bloated annoying piece of crap (see yesterday). So having everything ship with, and constantly try to update maven is incredibly annoying, especially without an obvious way to turn it off. The issue is that there is no maven data or metadata or even basic app structure. Again, I understand if “best practices” recommend using at least the app layout for familiarity (my current app is pretty close, but doesn’t have a test/resources folder. But why is this whole subsystem activating when I never told it to, and there is nothing for it to do. Its especially annoying when it hangs, or forces more meaningless updates on restart.

Having gone through several versions of MyEclipse, there is more exasperating crap. It tries to force me to do a Mylyn upgrade, and I don’t even know what the hell that means. The standard “debug” icon _always_ launches some javascript applet, with a warning that I can’t properly debug javascript. What the fuck is that doing on a default choice on a java class, in a java project, where I have never opened a javascript file? I can’t seem to find a way to turn it off.

Spring Source Tools has a “killer feature” of being able to visualize a spring beans hierarchy. Except it just doesn’t work and currently has 95 serious bugs filed against it. Other than that it is a differently packaged version of Eclipse with its own annoying presets.

There are some other nice features, too: you can switch your keybindings to be emacs-like, except that it reverts it to an unspecified layout if you open an XML file. Opening an XML file, of course takes for ever and is laggy, so I still use emacs for that.

The primary use for eclipse is its code navigation, intellisense and debugging. The first two I am pretty good at with standard unix tools, though having the whole library base and being able to read library source is very handy. The debugger, for the most part is fully featured and has some nice abilities to view the state of multiple threads, though it can be pretty cumbersome digging through proxy classes, or request filter chains. This can be mitigated with proper test isolation, but on a legacy code base, there just isn’t much of an option there. So there are things that it does well enough to warrant being used. Unfortunately, they are following the oft-tread path of trying to make it a tool that can do _everything_ when its actually only good at editing and debugging java.

And a little bit of hate for source control plug-ins: Subversion based eclipse tools are fucking awful. They regularly corrupt my workspace, will fall out of sync, or just mark files with strange statuses that takes a good deal of command-line work just to get back to a state that it can be used (usually diffing, reverting and patching). The only benefit is that they configure eclipse to ignore .svn files, which can be done manually. The only benefit is _when_ they work, you can use them to name and move classes easily, which is a bit of a chore on the command-line (i should make some scripts to make that easier).

And the last thing: if eclipse can tell a file is out of sync, why doesn’t it just fucking refresh it? Why can’t it just read it directly from the disk? There is no reason to hit F5 on a page that won’t display because it doesn’t have a freaking buffer open for it.

Stay tuned for part 3: XML

May 14, 2010

Daily #139: Java dislikes part 3 — XML

Filed under: Java,Technology,daily — scrame @ 9:47 pm

XML was a shot at getting off of proprietary binary interfaces when dealing with distributed messages, as well as a general purpose interchange format. It totally blows. Here’s why:

1) It was not supposed to be created and edited by hand. The XML spec required that the documents be human readable, but should only worked with by machine code. This obviously has not happened. Mostly because the parsers are quick enough and reliable enough that people started using it as a config file format so as not to implement their own parsers. This has resulted in things like ant: which is a fairly reliable build system with a horrible pseudo-declarative syntax. There aren’t tools for properly generating these builds because they need to actually be tweaked by hand.

2) It tries to be too flexible. Attributes in xml are completely unnecessary, but they do allow XML documents to be written more tersely in some situations. Unfortunately this creates an ambiguity between the attributes of an element and the subelements of the same element. When is it appropriate to use one or the other? Or accept both? What is the meaningful distinction between the two types? What is the benefit of having multiple places to extract values from.

3) Its based on SGML/HTML. Another crappy document format. While it is the lingua franca of the web, HTML parsers are very relaxed, but XML is supposed to be very rigid. The adoption of HTML into a new standard language seems like more of a populist than a technical decision, just as java and XML were supposed to free us from the tedium of programming, and the headaches of distributed communication. Instead it just ushered in a new era of painful configuration and tedious, verbose coding.

4) Its too complicated for what it is trying to represent. JSON and YAML and other serialization efforts have shown that there is only a handful of actual types that are used: ints, floats, strings, lists and maps. Maybe an enum or something. Note that I dont specify a precision in any of that, that should be handled by the target language implementation.

5) The whole document must be held and validated in memory. Since all parsers must guarantee the document is valid, and the only way to do that is to have access to a full document, the parser requires revalidation with every write operation, and a client receiving the document is blocked from taking action until the whole message is received. This is quite a disadvantage to even a binary format, which still needs the validation, but has a much smaller footprint on the wire (or compared to json which gzips very nicely).

6) Namespacing, DTD’s. XML naturally has ways of helping validation and enforcing proper types and document setups. These are used in large configuration libraries, like spring, but are generally not used for internal application protocols. These extra documents often have urls, and to properly read the schema, actually requires a network trip to properly parse the document. This is another built-in performance penalty. Add to that the fact that DTD’s are actually a different syntax, means an extra task of complexity.

7) SOAP: In order to get around the typing issue, someone had the great idea to generate IDL’s that generate XML that can be used to validate against an incoming xml document. Sound over-engineered? It is, and its fucking hell on earth to use unless you have a full MSDN set up of working with specifically public interfaces. Its easily as much of a failure as the binary messages it was trying to replace, but more opaque and difficult to use, with the added benefit of the heavy overhead of xml parsing.

8) …fuck it, you get the idea.

Daily #132: Java dislikes part 1 — Maven

Filed under: Java,Technology,daily — scrame @ 9:43 pm

[
I was working pretty late tonight, but had some time to reflect on things that I actually like about java.

A while back, on a different blog, under a different name, I made a java rant. I reposted it right before this, without a daily tag, but if you are reading it just on the blog it should be just underneath this. If you care, give it a read. If you don't find it interesting, you won't find the rest of this interesting either.

Anyway, its a rambling post that starts out making two points, but just turns into paragraphs. It wasn't edit well, and just turns in to a tirade. To be fair, I think a lot of those points still stand. However, I have done a lot of java instrumenting work, and trying to upgrade an aging codebase to some of the newer offerings for java, and have found that there are a few things that I like about working with java as opposed to other platforms.

There are other things I don't like. Ill do a brief rundown of some of the dislikes, because they actually pave a basis for some of the better things.

Anyway, part one of an ongoing series about likes and dislikes of dealing with java. This still counts, folks.
]

I don’t use Maven. I most likely never will, its a classically over-engineered java solution to hopelessly preplanned software. Check this out: its “Getting started with Maven”, how to make your first maven project.

Wow! Thats amazing! Just to know that to make an app in java, its as simple as typing:

mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app -DartifactId=my-app
WATCH OUT RAILS!!!!!!1!!
And from there, you can run an empty test case from the command line. It is just so easy! Unless you need to use a third-party library. But wait, there’s more! Maven can manage your dependencies through an XML file, and all _you_ have to do is figure out the exact right version string for the one you need, and then its location. And then a url that will grab it as long as the server has the appropriate metadata. Its a really killer system except for the fact that the primary archives are all “stable” according to apache, which means they are backward compatible with java 1.1: Internet Edition. You can use google to find other packages, but really, this is the efficient, modular way to build an app.

Once you have created and configured your application, you can open your Maven Supporting IDE (Don’t worry, any IDE you will be using will “support” Maven out of the box. Its much simpler that way).

Stay tuned for part 2: Eclipse.

Teaching to the dumbest kid in the room.

Filed under: Java,Technology — scrame @ 9:20 pm

Anyone who has had the displeasure of working around me has probably heard many of my complaints with the dominant corporate paradigm of Java/XML . In general, its inexpressive and bloated, I’m sure ill manage to have a long list of complaints about these things at some other time, but most of the complaints I have are well documented, and often covered in a lot more depth. But here is the overview:

Java was a stab at fixing some of the emergent problems of C++ in the mid-90’s. Some of it was done well (concurrency, garbage collection), but a _lot_ of the decisions just ham-stringed current programmers. The dominant decisions that constantly irk me are these:

1) It trades verbosity for expressiveness.

Java and its configuration system, XML, were heavily marketed under the philosophy that commenting didn’t work in code, and that it should be “Self-Documenting”. This is repeatedly encouraged not only encouraged by the very verbose API for the java platform, but also through the lack of expressiveness available in the language. Simple constructs like closures and function pointers were not implemented because they were too dangerous, or simply couldn’t work in the framework created. Instead they ignored anything that might be abused or could ever conceivably used the wrong way. Which brings me to my second point:

2) It trades power for safety.

Java not only removed delete, but also pointers in general, as well as adding checked exceptions, and heavy type checking. This has only continued with the introduction of anonymous inner classes, generics and other awkward heavyweight hacks that add a modicum of syntactic sugar. No longer do we have the option of just writing a simple imperative style of programming, instead everything has to be wrapped in clunky class declarations and it takes multiple lines of code just to write a hello world program or add two numbers together. Instead of writing answers to the problems we are solving, we are coercing logic into an overbuild object system that stole wholeheartedly from the clunky hack of an object system it was trying to replace.

This is a false sense of safety, as well. Just because there is no obligation to delete objects when you are done with them you are not relieved of the more general problem of resource management, or even managing the memory of your objects. Garbage collection will only work if all references to an object are removed _and_ the garbage collector runs. In general, though, memory allocation is only part of the resource problem. Most modern applications are tied to a database, or some similar system, and often have to work with system level resources like files, and sockets, even though java has tried very hard to not make such basic building blocks easily available.

The secondary problem with erroring so hard on the side of safety is that it has created several methods and workarounds to get around the pain of having to catch and throw every exception that might pass through the stack. In forcing people to do what they thought was the right thing, they ended up encouraging people to find the laziest way around these problems. At the absolute worst is wrapping all of main in a try/catch, and converting everything to run-time exceptions. Larger libraries and frameworks, like hibernate and spring have their own systems for trapping checked exceptions and turning them into run-time exceptions.

Another useful function that they removed was the ability to overload operators. Of course they can fake this out with their autoboxing, but consider BigDecimal. There is no primitive type for a BigDecimal, so auto-boxing won’t properly convert it to primitives to be able to work on it, there is no operator overloading, so if you are dealing with two numbers that could potentially be very large, your only available choice is the very natural expression:

bigDecimalOne.plus(bigDecimalTwo);

This is an excellent example of verbosity removing expressiveness, and hurting readability.

All of this comes down to java being a very strong, statically typed language when they were trying to move in the direction of dynamic behavior. Reflection was in the initial specification of the language, but approached from a method of static type analysis, which is a fundamentally intractable position.

So where does that leave us?

With a very hamstrung language. While the VM as a target is a very powerful platform, its flagship language has a lot of things that made programming fun and conceptually interesting removed in the name of “safety”. Safety meaning, “someone could use it wrong, so you definitely will not and should not be allowed to do this.”

This is the same as teaching math at half the speed to not make the stupid kids feel bad. Instead of enabling programmers to do what they want and trusting their own judgment to do what is right, they precluded that option and assume that we are all morons who will abuse whatever power given to use. What we are left with is an ineffective language where every task is equally tedious and mundane, there are no elegant solutions, there is no way to reduce code.

Their solutions: bloated IDE’s, language extensions that hack on meta-programming to reduce boiler-plate code that they decided should be manually entered with every class to begin with. “Refactoring” operations that double the size of simple classes, and “Interfaces” that increase the amount of indirection and mandatory implementations.

Nothing about this makes coding easier, more enjoyable, or even more maintainable. Instead, we are left with a generation of coders who are reduced to monkeying with XML config files and brainlessly tapping ctrl+enter to auto-complete through their projects.

What we are left is that the dominant language in programming is one that started out being completely dumbed down from the decision that if something could be abused that it would be and should therefore be removed. Every iteration of java since then has added more awkward and bloated syntax to get around these mistakes in the initial design and the rest of us are stuck with an overly-verbose and inexpressive language that caters to programmers with the least foresight and ability.

Powered by WordPress