Wednesday, January 28, 2009

XML

According to Wikipedia, "XML's purpose is to aid information systems in sharing structured data, especially via the Internet, to encode documents, and to serialize data."

*sigh*

Yes, let's use a general text format to pass messages over TCP, that's not a waste of bandwidth at all. Seeing how bandwidth is not a limited resource these days, it doesn't really matter anyway. Packing data into bits and bytes is hardly important anymore.

<PLAYER>
  <MOVEMENT>
    <X_VELOCITY>
      <VALUE TYPE=DECIMAL>
        3.7
      </VALUE>
    </X_VELOCITY>
    <Y_VELOCITY>
      <VALUE TYPE=DECIMAL>
        2.1
      </VALUE>
    </Y_VELOCITY>
    <Z_VELOCITY>
      <VALUE TYPE=DECIMAL>
        0.0
      </VALUE>
    </Z_VELOCITY>
  </MOVEMENT>
</PLAYER>

Yep, slimmed down to the max.

A general text format for encoding documents saved from applications tailored to the particular needs of, let's say, the marketing department at a company in some specialized niche sounds really useful, because so many other applications will want in on that action, probably. At the very least, if any competing software is released in the future, it might be able to catch up more easily, and that's a good thing, in some way.

<DATA>
  <DEPT_NO>
    42
  </DEPT_NO>
  <PARTIAL_SRH>
    76.45
  </PARTIAL_SRH>
  <MBZ>
    "active"
  </MBZ>
</DATA>

Someone is sure to find a use for this fascinating data.

Serializing data into human readable text for saving to file or passing to another application across a pipe of some sort before deserializing it back into binary again is surely great for something, I just can't quite think of what that might be yet, give me some time to mull it over... Perhaps it's good for security, yes? Packet sniffers must definitely appreciate it, and why let data remain machine readable only when humans might want to have a look eventually?

<EMPLOYEE>
  <SSN>
    19670918-1234
  </SSN>
  <SALARY>
    43000
  </SALARY>
  <ACCT>
    5312-00004223
  </ACCT>
</EMPLOYEE>

This format now featured in "Phreaking for Dummys", in a book store near you.

</SARCASM>

Learn to handle binary formats. Text formats are for beginners learning VB. Don't tell me that parsing XML is so much easier than fread(&data, sizeof data, 1, file) because that's just not true. There might, MIGHT, be a few times where XML is a good idea, but when you're the one implementing both the client application and the server application, it's just ridiculous.

Oh, and one last thing - XML isn't a "technology" any more than INI files are the remedy for cancer.

Tuesday, January 27, 2009

Design Patterns

You guessed it, I don't approve. Here we go!

Communicating with other coders or teaching a youngling the skills of our trade obviously requires a specialized language, but why should such a language be needlessly convoluted? Acronyms are fine, I enjoy baffling civilians on the Information Highway as much as the next fellow, but I don't see why some of my peers apparently enjoy throwing around words that aren't in our common vocabulary.

"You ought to enlarge your vocabulary then," they proudly boast. Meaning, of course, that my base knowledge of the art of programming is not enough, and that I should strive to continue learning. I don't see anything wrong with that motive, besides perhaps the inevitable unveiling that there is no Santa. What makes my bile rise, however, is the suggestion that I should learn so-called "patterns".

Remember how someone once told you about the Singleton Pattern, and you thought to yourself, "Yeah, I can see how that would be useful"? Well, it's hard not to see how a global variable can be useful. Funny thing is, you already knew what that was, but you hadn't heard the fancy name before. In fact, what's hard to see is why such a simple concept as this needs to be given a name at all.

Granted, the word "singleton" communicates a little bit more than just "global variable". Fine. So how many times has the word "singleton" been bandied about in a useful context? A setting where the concept of a singleton actually made sense? Few, I wager. How often is it really necessary to enforce that a class be instanced only once? Dude, if you only support one graphics adapter, then simply create a single instance of your GraphicsAdapter class! Exactly who are you protecting your code from by turning it into a singleton? Code in your sleep a lot, do you? Moreover, rather than improving upon existing code, the singleton will more likely just add to code complexity.

What's more, the singleton is just an example; it's definitely not the only design pattern to suffer from complexity. I daresay any pattern adds clutter and increases opacity. I base that statement on this simple observation: If your design needs to be explained, it is too complicated.

As soon as you find yourself wading through code in order to find out what is really going on, something is amiss. Stepping through function calls into other function calls of class methods ridiculously and indecipherably abstracted to the extremes, with useful comments such as //I just learned the Utility pattern lol :) is enough to make a grown man cry. Naturally, this problem doesn't always stem from the use of patterns alone, but frivolous use of them will certainly lead downhill.

I heard someone say this: "I'm not proud of this code, it isn't a very good pattern." I'm sorry, what? Here's another quote: "We need to think of a better pattern for this part." Woah, hold it - buzzword alert. Is code in any shape now equivalent to some sort of pattern? Is a for-loop a pattern then? Seemingly, it's not enough to just write code anymore, oh no, it has to be designed. It has to be architected. Cue Vader's theme.

Architecting code doesn't imply creating dense structures that are difficult to navigate and understand. The use of patterns for the sole reason of using patterns, however, does. This is the main problem with patterns. Naive application of perceived superior dogmas by fanatics and bumbling fools who believe that "refactoring" is a new and revolutionizing concept. Sit down Java programmers, nobody cares about your "humble opinion" or otherwise.

It all boils down to the definition of perfect code, the shimmering idea of a brilliantly logical construct that only exists in our mind's perfect world. Some seek to live by the rules of The One True Brace, while some pray in the Hungarian church of True Notation. Others again kneel at the chapel of Patterns. I propose that we all put ourselves above these mere tools, instead of bowing and scraping to them as our gods or demons. Less crusading for the causes would also be nice. But then again, so would world peace.

First!

Oh no, Lord please protect and defend us from "first" posts.
Powered By Blogger