Friday, May 29, 2009

Tales of C# Programming for Win32 Beta APIs, Part 1

Many, many people ask me what, exactly, my job is. I work for the Centre for Media Design basically doing whatever my supervisor wants me to do, and my current project is to develop an interactive data visualisation graph utilising information from a database of attendees of the IDMAA conference, being held here in August. This project has had a massive learning curve for me due to the fact that it is in a language I'm unfamiliar with (C#), using an API I'm unfamiliar with (Microsoft WPF/Surface) and with little to no documentation (the Microsoft surface is a brand-new piece of hardware and there isn't even a book written about it yet). Fortunately someone who is a significantly better programmer than me is assisting, and so far we've managed to hack out a pretty impressive looking demo.

One of the major issues with the Microsoft API is, predictably, how non-transparent it is. It appears that everything is designed to be tied directly into the XAML (the MS XML junk that describes the objects you're working with), making the C# clunky and difficult to follow at points (where do these freaking event handlers come from? why do you add them the way you do? no one knows). Threading was another delightful adventure into "wtf..." land; apparently, you cannot access an object inside of a thread unless it was created within that thread. Sure, this helps prevent synchronisation problems, but it's like cutting off your arm so you won't be tempted to reach for that last doughnut. Another major annoyance: drag and drop functionality isn't really "built in"...if you want to implement drag and drop, there's a rather long, detailed tutorial on the topic. Which is extremely useful considering the hardware is a touch surface.

Regardless, the project is going extremely well and I'm enjoying the challenge quite a bit. Once the project is finished it should be fairly impressive, if it's done right. Beyond that, the challenge will simply be to make it engaging enough for users, so we don't run into a trend of people getting bored with it almost immediately. That opens up the possibility of designing in some rudimentary game elements, maybe allowing users to "collect" interesting data, or garner points for connections, things of that nature. More on that as the project expands!

Wednesday, May 27, 2009

Things Visual Studio Does That Piss Me Off: Part 1

If you don't declare a variable, it will try to autocomplete everything. For example, while trying to write for(i=0; i!=thing; i++), it will ALWAYS autocomplete with for(if=0; if!=thing; if++), and even if I change the first if back to i, it will continue to insist that I was, in fact, trying to use if for each proceeding i. It recognizes the for loop structure but is not smart enough to realize an if is not appropriate in this situation.

Also, it fucking copies blank space.

Monday, April 13, 2009

Things I learned this weekend (or: the list with no point)

1) "Accessing" an element in C++ lists (and related structures) means "make an exact copy of this for me to use temporarily".

2) Don't hardboot a server randomly (especially out of laziness), even if said server is giving you all sorts of sass. You may knock it to the curb for a second, but it will trip you into oncoming traffic.

3) Port forwarding for fun and profit. Also, default router passwords are for win. Too bad this resulted in the death of a server...

4) Crunchbang skimps on language packs. This would be more acceptable if one of the language packs I had to install wasn't for the most widely spoken language on earth. Ethno-centric much...

Reinstalling Ubuntu server this weekend...Все идет по плану

Thursday, January 29, 2009

Project 2: String Length Counter in C

This weekend I spent some time exploring C strings, and comparing/contrasting them with strings in C++ after doing a project in which we were required to write a word length counter without using the built-in stringlen functions (oh noes!).

Strings in C++ are nothing like strings in C. I had a vague idea of this when I was doing the project, as I have used C++ strings in the past, and they don't require as much work as C strings. There is a very good reason for this: while C++ strings are very nice containers with nice built-in functions, C strings are, quite literally, nothing but a group of chars. This can be expressed either as an array or a pointer. The difference between the two being one is a pre-sized block of memory containing a line of chars, while the other is an address to a block of memory (not necessarily pre-sized) containing a line of chars. Array do decay into pointers when being passed as parameters and such, but the two are still fundamentally different.

A very interesting thing about pointers and arrays is that, despite the fact they are represented completely different in memory, they can still be treated the same within this context. If you declare two variables:

char array[] = "Kitty";
char *pointer = "Cat";


you can use the same notation to access the individual characters in both, ie:

array[1] to get i
pointer[1] to get a

In the first case, the compiler will start at the first character of array and move one in order to get the value. In the second case, the compiler will fetch the pointer value, add 1 to this value, and then finally go to this location to load the character.

This is what, for me, makes C so interesting. It is far more low-level than C++, and as such, the fact that you're accessing values in memory is far more transparent. The malloc command I used in my homework literally sets aside a block in memory of the size indicated (returning a pointer), and keeps that memory allocated until it is either deallocted by free or until the program ends.

C++ string containers are just special templates that allow you to do far less damage accidentally (though it is said you can pretty epically destroy the world if you do mess up). They do a lot more to automatically manage your memory for you. You can convert them into a c_str (which is actually a const *char, and is necessary for a few file input functions such as fstream), but for all intents and purposes they are their very own, very easy to use data structure.

Anyway, I hope to do more C programming this year as a way to improve my knowledge of pointers, and hopefully allow me to start writing some more heavy-duty projects such as small compilers and what-have-you. Let the C adventures begin!

Thursday, January 22, 2009

Project of the Week

I decided that since I've stopped posting regularly (unfortunately!) I'm going to start post about a Project of the Week. Essentially, this will be some project that I accomplish, either over the entire week or just on a weekend. Posting my experiences will both help me remember it, and provide a reference for myself. And maybe someone else will enjoy reading about it as well :)

This week's was easy: set up my Ubuntu server with SSH and an IP address manager daemon that would allow me to admin the server remotely, and elimiate the need (for the most part) for the splitter box I have between my Mint desktop and the server itself. This is mainly for convenience, of course, and the fact that the splitter box often cuts off access to the mouse/keyboard and makes the monitor look yucky.

Of course, installing Ubuntu Server edition (CLI only!!) was a breeze; the installer is far more stripped down (it made me nastolgic for Slackware), but still very straight forward. It may scare the Linux n00b, but anyone who has installed a few Linux distros in their time would be comfortable with it.

So next up, I wanted to be able to SSH into my box from anywhere. This is both for convenience, and as I mentioned, removes the need to directly interact with the computer, which is a pain when it's sharing a monitor with my main Linux desktop (which, just to mention, is Mint :3). In order to accomplish this hardly daring feat, I created an account with DynDNS.com, which is a free service and allows you to add your computer as a "host". I can't remember if there is a limit to the number of hosts you can add, but I'm inclined to say there is, since they have account upgrades that you need to pay for.

After doing this I installed ddclient (sudo apt-get install ddclient), which is essentially a daemon that keeps track of when your dynamic IP address changes, and notifies DynDNS of the change. DynDNS then updates you host so, voila, your hostname always resolves to the right computer! During the installation Ubuntu automatically configures ddclient for you, more or less. There is a small amount of hand-configuration, but you need only to change a few lines, and you're off and running!

After doing all this (extremely hard (; ) work, you should be able to directly SSH into your server box and admin from any computer you wish.

The next project I'm considering will be a bit more complicated, and more programming-oriented than server-oriented, so hopefully slightly more interesting :)

Thursday, July 31, 2008

Ur Doin It Wrng

I'll be forthright: I only skimmed a bit of The 'Anti-Java' Professor and the Jobless Programmers the first time. After going back and giving it the attention it deserves, I agree with the message it's trying to send, though I must admit it's really an echo of similar arguments I see in other respected programming blogs (see: Joel on Software's The Perils of JavaSchools).

So, really, I'm not trying to say or point out anything particularly new. No, the parts of The 'Anti-Java' Professor I wanted to point out were the following quotes:

Dewar stresses that he’s not against Java itself. But the fact that Java is taught as the core language in so many colleges is resulting in a weak field of computer science grads, he says.

The reason: students’ reliance on Java’s libraries of pre-written code means they aren’t developing the deep programming skills necessary to make them invaluable. Colleges, alarmed by falling CS enrollment, have dumbed down the course requirements. Consequently, CS majors sail through a curriculum of Math Lite, earning a smiley-face on their papers for “developing” projects using pre-built libraries.


Followed by:


But wait a second, Professor Dewar...I wanted to ask him, since this list of popular programming languges puts Java at No. 1 – ahead of biggies like C, C++ and Visual Basic – doesn’t that negate his theory?

I mean, if Java is this popular, maybe universities should teach it first. It called “being in touch with the real world,” isn’t it?


Before continuing any further I'd like to point out I don't specifically have anything against Java. I feel like it is a perfectly adequate language that the right people can do great things with, like all languages. This is not about Java (it could just as easily have been about Python, and so many other languages). It's about the ATTITUDE that is being flaunted; Java just happens to draw this kind of attitude. Take or leave that as you wish.

When I first read this, taking it seriously, it infuriated me, mostly because this is the attitude I see at my own school. So many times I have see my fellow students (in my eyes) just give up because a language "is so much easier" than C, C++, Lisp...whatever. When I mention that I am leaning towards doing a video game project in Lisp for my masters work I always get the exact same question: "Why are you using Lisp?", usually followed by, "Why not just use Java?"

It boggles my mind. It's like asking me "Why are you doing computer science?". I'm doing it because I love computer science and want to learn as much as possible, not just sit around and churn out easy code. If I wanted to do THAT I would just do HTML all day and try to convince people I was a programmer. I mean, it's easy, right? Why spend time learning something more complex like Java?

Why is it so weird when you're devoting at least four solid years and thousands of dollars to something that you would want to learn as much as humanly possible? Is this not the point of college? While I do agree there is a place and time for very good tools (such as the ones Java provides), there is also a place and time to learn how exactly these tools work by building them yourself.

Just as a random anecdote, a friend of mine decided to rewrite a built-in Java search and came up with his own search (in Java as well) that was magnitudes faster. He learned something important from that experience, as we all should.

Wednesday, July 9, 2008

Linux Wants to be Your Friend (Part II)

Wow. Linux Mint...I was really, really impressed. Of all the "user-friendly" Linux systems I've messed with, this one is hands down one of the most solid and truly user-friendly.

Installation was, as expected, a breeze. It took maybe 10 minutes total, and like most modern, desktop-based Linux distros allowed you to explore the LiveCD at your leisure while the partitioning and file-copying and whatnot was being done.

The full installation naturally has the essentials: the excellent Synaptic package management system, Firefox, Pidgin, and a nifty little update program that allows you to update the entire system with a few mouse clicks. The aspect I enjoy most about the update program is it resides in the toolbar along the bottom, very unobtrusively indicating, with nothing more than a slight change in the button, that there are new updates available.

The best part: all internet plug-ins are installed right away, as promised. I was still having issues with applets (they weren't aknowledging keyboard input, very odd...), but there was no need for me to do any manual installs of...well...anything. Probably the easiest Linux install I've ever had to be quite honest.

The only minor issue I had with this distro is it doesn't do root like I normally expect it to do root. You have the *option* of setting a root password, although it's recommended you don't. The first time I did set the root password, just out of habit, and after multiple failed attempts to start up a device manager, I realized that the desktop was, like Mac OS X, asking only for the user's password. sudo asks for the user's password, and, to my horror, the user can even modify important root-level files (for example, the grub boot menu file) just by sudo-ing. Depending on the environment in which this distro is installed, this could be unforgiveable or just cringe-worth.

Outside of this I would highly recommend this system to any Linux n00b who just wants a working system set up quickly and painlessly. This distro will be remaining on this desktop until the techs find out and become engraged at the lack of Vista.