Subtext: Visual Programming, New Angle

2. March, 2009

If you have no idea what subtext is, lean back and watch this presentation.

It’s nice to finally find another person concerned about the state of programming languages. I started with C, toyed a bit with some other languages, moved to Java and today, I’m working mostly with Java, Groovy and Python. I’m doing all my spare-time code in Python. Why Python? Because I get more bang for the key press. And my spare time is most valuable.

So while I thoroughly agree that the idea of subtext is convincing, it’s too limiting at the same time: There are simple problems which you can’t express well in subtext, for example: A switch with 10 cases and some complex code in each case. It would just become too wide. The same applies when formulas have more than ten parameters. Your flow tree looks nice but it takes more screen real estate than the “traditional” version.

So my argument is that we need a way to choose. Software projects need to give up the holy grail of “one language to rule them all.” The IDE should allow to mix and match various languages and more complex “objects” like tables, rich text, animations. Why do I have to waste my time formatting tabular content in a Java file (think array of values) when I can have Excel? Why can’t Java read the data directly from Excel? Why can’t I embed Excel tables in Java source code and access them like a 2D O array? Why can’t I use a rich word processor to write my comments? Why is TAB 1-8 spaces instead of “one level of indent”? Why do I have to use braces when I already indent my code?

Because our computers are not powerful enough today. With every key we press, we have to worry about RAM and performance. Because companies still believe in lock in. Sun would probably add a cross-platform COM API into Java but will Microsoft port Excel to any platform where a Java compiler is available? Oh, we could use OpenOffice. Let’s see. People working for a software development company that has more then two employees: Comment here if your company policy allows to use OO instead of Office. Now let’s see how long it takes to get 10 comments.

In the end, what we have today is the most simple thing that actually works and doesn’t take too much RAM. I hope the time is ripe for the next step. I’m sick of fixed-width fonts, curly braces and source code which is 1% functionality and 99% “make the damn compiler happy”.


Java Tricks: Commenting Out Code

25. February, 2009

How do you comment out code? Using /*...*/? Using your IDE to put // before each line? There is a third method:

    if (0 == 1) {
        ... code ...
    }

Pros:

  • Nests
  • You need only change a single character to “flip” the comment: Replace the 0 with 1.
  • You won’t get warnings because of suddenly unused imports or local variables.
  • The Java compiler will remove this block of code in the optimization step, so no runtime penality.

Cons:

  • Can only be used inside of methods.

If you need a fast way to repeatedly comment in/out a piece of code elsewhere, use this syntax:

    //* Fast flip comment starts here
        ... code ...
    /* and ends here */

Inside of a /*...*/ comment, the sequence “/*” has no special meaning. To comment out the block of code, remove the first “/” in “//*”:

    /* Fast flip comment starts here
        ... code ...
    /* and ends here */

Wikianswers vs. StackOverflow

23. February, 2009

I’ve mentioned StackOverflow a few times. If you have a question related to software development, that’s the place to go. But there is no place to ask other questions.

Well, five days ago, wikianswers started and … there is still no place to ask other questions. I do not doubt that Jimmy Whales knows what he’s doing but for some reason, he didn’t notice Web 2.0. Yes, wikianswers looks nice (well, the top of the page does; let’s not go into the rest, especially the search results and such).

Obviously, this site runs on top of the MediaWiki software. While the guys on StackOverflow pulled every string to make it as simple as possible to ask and answer a question, I feel that the workflow on wikianswers drains a lot of my enthusiasm even before I get to answer a question.

Good luck, Jimmy! We really need a place to ask questions.


Mutation Testing

23. February, 2009

From the website:

How do you know your test suite is “good enough”?

One of the best ways to tell is mutation testing. Mutation testing seeds artificial defects (mutations) into a program and checks whether your test suite finds them. If it does not, this means your test suite is not adequate yet.

Read more about Javalanche on the website.


Fallout 3 or How To Annoy The Customer

17. February, 2009

Math anyone? It’s simple. Bethesda sold 4.7 million copies of Fallout 3. They made $300 million from that. Not bad for a game. Someone got rich. vgchartz.com estimates 1.24m sales for the PS3 version, 2.02m for the XBox. Since there are no figures for the PC version, I assume that this was somewhere between the two. Amazon’s sales rank (111 XBox 360, 157 Vista and 188 PS3) support this.

For a simple minded person like me, this means that Bethesda made between $50 and $80 million dollars with the PS3 version. Obviously not enough to supply the game with more patches and downloadable content (DLC). A pity. I liked the game. I didn’t like the gore; too much blood for my tastes and no way to switch it off. Distracts me from the good parts. I like the immersion, though. Touch decisions. Who to save and who to sacrifice. Seeing the results of your “help”. Going for your own good or the common good. I find myself spending more time in the dialogs than in the fights, trying to find my way in the options, wondering what evil twists the designers might have hidden behind each.

Since Bethesda treats a third of their customers second class citizen, I guess when Fallout 4 comes out, they won’t need to bother for one of the three supported platforms at all. I’m sure that the decision makers have thought long and hard about this, probably watching a big heap of money piled up in their front lawn by Microsoft. And rightly so; why should Microsoft care whether they ruin other peoples lives? They never did, and, since it’s such a successful strategy, they never will.

If you find that legal document hard to read, try this one. Microsoft has made a total revenue of $16.37 billion of which $6.48 billion are operating income. To drive the point home: For every buck Microsoft charges you for anything, they make 39% profit. Not bad for a company in a business area where a 6% margin is “a lot” (Dell, the world largest computer distributor has a meager 6.48% profit margin). Someone with a conscience would say, hey, we make enough dough, we can reduce our prices. My point exactly. Someone with a conscience.

Yeah, I’m in a foul mood. Microsoft is responsible for most of the pain and misery in my life and now, they are telling me which games I can buy. Or which console. Great. That will really make me reconsider. Guys, I don’t buy from Microsoft because other products are better, I don’t buy from Microsoft because I hate them. I’d rather buy a broken PS3 for $500 than a working XBOX 360 with a lifetime warranty for $1.

Or well, yeah, I’d buy the 360 for $1 … to smash it to bits when I’m angry. Can someone recommend a paint shop who can put Bill’s face on it? If the warranty would cover that, we’d have a winner. Or when one of the plastic pieces scratches my skin, I could sue Microsoft for 1% of their profit. Whow! I’d be insanely rich. I could buy a small country. Gibraltar is probably too expensive. Liberia doesn’t look like a nice place. How about British Virgin Islands? Heck, why not? I’d even have some small change left.

So if you’re pissed like me and would like to do something about it, sign here.


On Blindly Following Advice

12. February, 2009

In his post “Thoughts on Developer Testing“,

“Unfortunately, you can’t write better software by blindly following dogma of ‘industry experts’.”

Just as “an eye for an eye” leaves everyone blind, staggering around in a changing environment with your eyes closed shut will not help you getting closer to any goal you might strive for.

A mind is like a parachute: It’s only working when it’s open.


Graph Layout in Java

11. February, 2009

If you need to layout a graph in Java, these might help:

  • yed Free version of a once commercial framework
  • prefuse.org very slick transitions; you will want to use Java 6
  • jung great demos, doesn’t look as slick as prefuse but might be more powerful.
  • gvf Just the basics, probably dead, too.
  • JGraph – commercial, thanks to David@jgraph.com.

There is also a collection of algorithms for graphs: JGraphT It uses JGraph as the default UI library but you can use the algorithms without that.


Why Good Developers Don’t Document

10. February, 2009

I don’t document because I know what I’m doing. Seriously. I sit down in front of the computer and beautiful code flows out of my fingertips. No idea how I do it. It’s like digesting for me. It just happens. For me, with my vast experience, my code is so obvious that I can’t think of any question someone might have (okay, let’s just say I need a bit of distance to come up with questions, say a year or so). For me, it’s as simple to understand as hello world. So why make things worse by adding unnecessary comments?

I do understand that other people see this differently but that doesn’t help. I’m not those other people and I simply can’t think what questions they may have. In my case, the solution was unit tests. I need them anyway (they make me more productive) and for the rest of the team, they serve as example how to use the code I write. This is much better than documentation because

1. a test is small, so the answer to your question lies in 10 lines of code. 10 lines of code can’t take long to understand.
2. it is always correct and up to date (unlike documentation which tends to rot)
3. after getting used to test things, you feel how it improves your output (in all ways); documentation, OTOH, is always a drag (“we have to do it … not again … oh man!”).


Distributed Software Development With Git

5. February, 2009

Real Men do it Themselves

There is stuff that changes the way you work. Then, there is stuff that changes the way you think.

When Donald E. Knuth wanted to write a series of books about The Art of Computer Programming, he found himself missing a program to convert his words into a beautiful book. To solve that problem, he invented TeX. When there were no nice fonts around, he added METAFONT. In a similar way, when Linus Torvalds found himself lacking a good version control system (VCS) after Bitkeeper decided to close access for OSS developers, he chose the only solution he had: He wrote his own.

And thus, Git was born and a lot of people living in abuse-protected web forums were in deep trouble. Even before them, the critics soared: What, another VCS?

Subversion vs. Git

Especially the people around Subversion were not so pleased and many people wondered why Linus chose to do his own thing instead of building on existing code. One of the reasons is that Subversion can be thought as a very elaborate bug fix for CVS. It didn’t try to reinvent the wheel.

It also inherits some legacy: You have to setup a central server if you want to do distributed development outside of your LAN. Certain operations are slow, like checkout and update. Agreed, they are faster than CVS but try these with Git. And it’s monolithic software unless you’re willing to use your C compiler. There are only very few ways to interact with the repository from a shell script, only a few hooks to do custom stuff (like sending email). If you just wanted to add a small feature, it would mean real programming work instead of whipping together a quick shell script.

I’m by no means a critic of Subversion; I’m using it every day and I’m happy with it. My point is that it’s confining me in a pretty small box, just a little bit larger than CVS and with less problems. That doesn’t make it larger, though. An example.

Oh, the Pain

You have some files which you want to take home to work on. So you copy them on an USB drive, take them home, edit them, bring them back. When you return to work, a co-worker has changed one of the files. He tells you after you copied all the files from your USB drive back onto your work PC (“Who has time to read all those warnings? Yes to All!”)

The next day, you’re smarter and check in the files into Subversion (SVN). There is no need for a central server and when you ignore the warnings from SVN, you can create the repository on a network drive. When the drive fails in an inopportune moment, your repository will be data trash, but there are certain risks one has to take.

You checkout a copy on your USB drive and take that home. Since working on the file from your USB stick is too slow, you copy everything on your home PC and edit it there. When copying the files back on the USB stick, you notice a lot of write-protected files in .svn directories. Oh well, time for “Yes to All!” again.

After returning to work, you synchronize your checkout with the SVN repository. Life is great. Unless you have Linux at home and were not so careful about Carriage Return/Line Feed conversion and you find the copy of your data on the USB drive is now currupt. But who is using Linux anyway?

The real trouble starts when you feel the need to carry the repository with you. Imagine you have a great idea, you have the USB drive with you, but you’re neither at work nor at home. If you have a computer closeby, you could work on the copy on the USB drive but at the cost of either getting out of sync with your home or work copy.

Subversion, like CVS, only supports a single, central repository unless you use tools like SVK. SVK depends on Perl, though, and it adds nice little … err … rather big cryptic code strings to the commit in messages.

Git

Git, on the other hand, has been built on the “greenfield”. Torvalds could add all the features he wanted and avoid all the common mistakes inherited by the CVS legacy. From a 1000 feet, it’s a set of loosely coupled commands which work on an object database which allows to version objects. Git doesn’t care what an object is, it just versions it. This is pretty similar to SVN, maybe except that Git handles large files better. And that Git is faster for most operations.

The main difference between Git and SVN is that Git is decentralized. This means you can create as many repositories as you want and synchronize them. So in the example above, you can have one repository at work, one on your USB drive and one at home. You can work on all three of them independently and then use Git to figure out how to merge everything.

Remember the dreaded branches from CVS? SVN eased the pain considerably but with Git, everything is a branch to begin with.

To become happy with Git, there are two major steps you need to take. First, you must understand that there is no server. Forget about the idea of server. Git allows to synchronize different copies of a couple of files in different places without a server. To do this effectively, Git keeps some information in the .git directory. If you want do to this remotely, you can use Git as a server, too, but that is basically the same thing as using it locally. Except that the name of a different computer is involved.

The second step is that you don’t put more than one project into one Git repository. With CVS, we are used to use modules. With Subversion, you create subtrees with trunk and branch. With Git, you have one repository per project. Setting up a repository is so cheap, it really doesn’t make sense to have more than one project in it.


Testing the Impossible: Hardware

5. February, 2009

Victor Lin asked on StackOverflow.com:Should I write unit test for everything?

In his case, he wanted to know how to test an application which processes audio: Reads the sound from a microphone, does something with the audio stream, plays the result on the speaker. How can you possibly test a class which reads audio from a microphone? How can you test playing sound on a speaker?

As Steve Rowe pointed out: Use a loopback cable. Play a well defined sound on the speaker and check what the microphone receives.

I suggest to move this test case into a separate test suite so you can run it individually. Print a message to plug in the loopback cable before the test and wait for the user to click “OK”. This is a unit test but not an automated one. It covers the setup steps of the hardware.

The next thing you will want to do is to check the code between the mic and speaker parts. These are now no longer dependent on the hardware and therefore simple to test.