Friday, February 27, 2009

Templates

In a few of the recent lectures, we've covered function templates and the use of templates for defining new classes. In addition to the lectures, the latest reading assignment from the book (Ch 18) also covers templates (or generics as they're more generally known). For the most part, I haven't really used this to my advantage in the past, but after seeing them in use, it really seems like they can be pretty useful. They do have their drawbacks of course. It may be a little confusing to try and figure out what is going on exactly. What is going on may not be what the user intends. For example, as the lecture on Function Templates demonstrated, making calls to Function Templates can be somewhat confusing (EX: my_max ("stu", "pqr") completely ignores the non-template function that would make it work, but my_max("abc", "def") doesn't). But as shown in the example, it is nice to have a "single" function called my_max that can work with a variety of data types.

Even better is the use of templates for classes. When were producing the code for the stack in class, I thought we were limiting it to just ints (and initially, we were). But by using templates, we quickly allowed the stack to store basically any type T, as long as T supported the various operations stack used. Even further, you could basically pass in a value for the maximum size of the stack using the template syntax. This almost doesn't seem much different that simply passing in the size as an argument, but if there is only a default constructor (which takes no arguments), the max size of the stack can still provided as shown in the example (Stack x;).

The book covers some of the more confusing aspects that might arise when using templates. For example, what is the relationship between two objects that use the same template, but have different types? For example, Stack vs Stack. Or what happens if you extend a templated class in a new class, which doesn't use templates? Things can get a little confusing once you start extending these classes.

In any case, they seem like a pretty nice feature of C++ (and other languages), and I'd like to explore their functionality in the future.

Monday, February 16, 2009

NetBeans

Over the weekend, I spent some time trying out the NetBeans IDE. Basically, it is an IDE by Sun Microsystems, somewhat similar to the Eclipse IDE, which is what I (and most people I know) tend to use for a lot of our Java/C++ projects. Like Eclipse, it natively supports Java, but plugins can be downloaded to enable functionality for C++ and other languages and/or features. Some of these features are actually what I wanted to try it out. For example, one of the plugins allows you to create UML. I haven't really tried it out yet, but I did check out a sample UML project they had which looked pretty good (although the sample was for a Java project if I recall correctly). If I'm not mistaken, Eclipse doesn't have this sort of functionality, so this is a nice advantage to NetBeans. If it does have that functionality, it certainly didn't seem as easy to enable compared to NetBeans (NetBeans did require a plugin, but it was relatively easy to find and enable).

Additionally, NetBeans has support for SVN and other "versioning" tools. Once you import your project into the depository, you can simply do commits, updates, diffs, etc., all within NetBeans. There are probably some more advanced options available, but those are the basics that I was able to quickly figure out. Again, maybe Eclipse has this sort of functionality and I'm unaware of it, but it seemed pretty easy to work with on NetBeans.

I can't say whether I actually prefer NetBeans to Eclipse, at least at this point. I definitly have grown accustomed to the Eclipse layout, so there has been a bit of a learning curve in figuring out how NetBeans works. I've yet to even use the debugger, which is one of my favorite aspects of Eclipse. I've also just worked on C++ (AustralianVoting), so it isn't like I'm using it for its original purpose (Java development).

NetBeans does seem like an interesting IDE. I don't know if I'll ever give up on using Eclipse, but I think I might at least use NetBeans when it comes to certain projects. It definitely seems to have come a long way. I think I checked it out years ago (maybe 2005?), and it didn't seem nearly as good back then. I almost didn't bother to try it out again due to my past experiences, but I'm glad I gave it another shot.

Saturday, February 7, 2009

Computing Large Prime Numbers...Useless?

I used to think so. In fact, I believe it actually was useless, at least up until the 1970s. But since then, the properties of prime numbers have become quite useful for certain applications. One particular use of this computation is RSA encryption, which was briefly covered in a few of the courses I've taken here at UT.

I won't get into the specific mathematics of it all since Wikipedia/Google can provide a much better explanation than me. The basic idea is that it is easy to multiply two prime numbers together, but it is difficult to factor that product back into the original set of prime numbers. This is an example of a one-way function (also known as a trapdoor function), which basically means that the function is easy to compute but "hard to invert." Of course, given a small set of prime numbers, this isn't too difficult, despite the definition.

And that is why it is important to come up with large prime numbers. The larger the prime numbers, the more difficult it will be to factor the product back into the original pair of prime numbers. For example, could you easily factor 26,636,627 into two prime numbers? Certainly wouldn't be easy to do it with pencil and paper. Perhaps a computer could compute it if given enough time to run, but it might take a little while (certainly slower than factoring 6 for example).

Anyway, thought this was an interesting aspect to prime numbers. Oh and by the way, the factors are 3449 and 7723.