Tuesday, February 24, 2009

No more avoiding databases.

Databases are something that I've managed to avoid working with, and are a gaping void in my programming experience. Luckily, for my iPhone project, I've been told they want a database of every event stored. Databases cannot be avoided anymore, I guess.

I found the SQLiteBooks Example for the iPhone and an excellent collection of tutorials for the iPhone SDK in general. Up until this point, my main sources of help have been the example code and documentation sources from Apple. Expanding my pool of help resources is going to let me learn a lot more a lot quicker.

After looking through the SQLiteBooks code, and looking up every sqlite3 call it makes, the clouds around this previously mysterious database subject are being drawn back a bit. Playing around with sqlite3 from the command line to experiment reminds me of using irb to learn Ruby.

The switching between left and right brain activity is described thoroughly in Pragmatic Thinking and Learning. This applies well to learning a new API or programming language. You get coding a good example (context-rich environment) and read the code and experiment with it. Then you read through some documentation sources about what each part does--the analysis part. You apply this knowledge in context by experimenting a little further in your sandbox code. In turn, by swapping back and forth between your right and left brains, you develop intuition and learn much faster and learn more in-depth.

The discovery of new features is done in the analysis and how they work is done through experimentation. This gives rise to the "code it to figure out how it works" philosophy, which I've used to learn some of the weird nuances of C++.

Friday, February 20, 2009

Color Wheel Demo



This video was captured using xvidcap on my Linux box. It demonstrates the functionality of the color wheel demo in QtRuby. Colors are added by clicking in the center of the ring, and removed by clicking elsewhere. The color selecting tool is a standard widget provided by QColorDialog, which I've mentioned before.

This is my first screencast and it shows the programs functions nicely (though kinda fast), so I might be doing more of this in the future.

Thursday, February 12, 2009



I finished the iPhone tutorial for the second time yesterday. I completed it as the first thing that I wanted to do, just to learn how to get code setup on the iPod touch, and then went to reading documentation. After doing a lot of reading, going back and doing the first tutorial again helped significantly. The first run was making sure I could get the example working, while the second immersion was to explore the different concepts more in-depth. Reading the Objective-C language documentation last night clarified many of the language concepts from the tutorial.

Context helps language learning significantly, especially if you do immerse yourself if the language and don't worry about exactly what it is doing. The important issue is that you understand the general concepts of what is going on. Just as is everyday human languages, you may not be able to represent the same concept using a one-to-one correspondence of smaller components. There may be some building blocks (cases of words, loop structures, etc.) which don't exist in the other language.

Reading the language and actually working to produce a step-by-step example provide a quick method to develop your intuition about the language. Proceeding without any preconceptions of how things are done is what allows children to develop language skills quickly. Thinking in the other language, rather than translating, provides the additional benefit of allowing you to develop new patterns of thinking that are orthogonal to how you do things currently, since it hides your normal way of doing things.

The second time I did the iPhone/iPod touch example, I added additional functionality on top of that provided in the tutorial. I added a button to change the label text to "How are you doing, [name]?" instead of just the provided "Hello, [name]." Also, I added a button to reset the name to placeholder text, and the label to the starting text, "I can say hello!". This predefined environment allows for exploration and play than starting from scratch. "I broke it by doing this, so I'll revert my changes and try something else." The Agile concept of always having a running demo helps us learn languages more quickly and more thoroughly through experimentation.

As seen in the images here, I added an uneditable text view showing the purpose of the program. Also, the "Reset", and "Ask" buttons are new from the tutorial, as is the support for horizontal, "landscape", mode was added. Not an award winning program, but I am proud of being able to extend the functionality of the original program and add some features I wanted. The learning experience was invaluable, but it is still only an initial step toward developing iPhone/iPod Touch applications.

Tuesday, February 10, 2009

iPod Touch/ iPhone Rotation

Rotation code for iPod Touch/iPhone. This is more of a thing you need to know that it exists, because it simply requires a few lines of code. This gets added to your UIViewController class which controls the View. Not very exciting except that it allows the program to be used in portrait or horizontal mode from any direction, even upside down. I still need to figure how to configure the view afterward, but at least the question of how it is done is answered. This is from the WhichWayIsUp app.

-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

Switching Development Methods... Again

By design or accident, I often find myself switching development environments (Microsoft Visual Studio to Eclipse to g++/make) or languages (Java to C++ to Ruby to Objective-C) when I start to get good at one of them. Originally, I began as a C++ programmer in high school, and then was moved over to Java with BlueJ in high school. I later moved to RealJ and then to JCreator LE during the course of school when I started developing using LWJGL. My freshman year in college, we moved to the "next great thing," Eclipse. Luckily, I managed to skip out on using BlueJ again. BlueJ had been a good beginner tool because it hid the unique details of how Java programs run, but it also keeps you in a very limited box.

Sophomore year, I was thrown back into C++ with templates in a data structures class. I got up to speed on C++ as fast as I could by doing a lot of examples, and playing around with as many language structures as I came across. Still, I remember the disbelief of another student who, late in the semester during a pair programming lab, didn't realize there was a delete keyword in C++, and that garbage collection didn't exist. So much for college teaching you the languages you need to learn.

My classes stayed in C++ until a Junior class in Operating Systems, were my classmates and I got to work on implementing features in the Pintos operating system. Did I mention none of us knew any real (pure) C? Of course, C is similar to C++, but there are those gotchas in many similar languages, such as void pointers. I did ok, K & R helped a whole lot, but I still don't feel attached to any language.

It was during the Operating System class that I quit using Windows entirely and switched to Debian Linux/Gnome. The change wasn't related to the class I was taking, but rather being genuinely disgruntled about paying for an operating system that crashed, was susceptible to viruses, and had an aura of a trash can which hasn't been emptied for several months.

Switching to Linux had to be the best thing I've done for my programming ability. I experimented with Bash scripts, and I started learning Perl during the summer by coding every example in the Llama book and pursuing my own projects. This was my first introduction to scripting languages.

Over the summer, my job had me writing in a variety of new languages, without any introduction. JavaScript, PHP, and Ruby rounded out the list, my formal experience before these assignments being merely that I had heard these languages existed. "Here's a book and a few good websites... go do this project," were my instructions, and I did as asked. They weren't critical projects to the team, but rather additional "it would be nice" projects that the team would never get to. This was also where I was introduced to QtRuby, and had a very hard time adapting to the duck-typing of Ruby.

It was at this company where I began my learning of the many in-depth features of Vim. Vim takes the concept of manipulating text and turns it into a super-ability. I've gotten better with it since, but the people I worked with moved like bolts of lightning in Vim.

I reverted back to Java last semester during my Graphics/GUI programming course. After all that C/C++ code, coding Java is about as simple as microwaving a frozen dinner. Combined with my Vim experience, my productivity grew several fold, and I finished the projects more quickly than I ever could have using another IDE. I returned to Swing development from way in high school, and JOGL... another Java binding for OpenGL, except designed for Swing, unlike LWJGL.

Over Christmas break, I applied my Qt knowledge to develop a bunch in Qt with C++ and work in OpenGL as well. I worked a lot in QtRuby, and the recent projects such as the color wheel have been as a result of this. I played with Python for a little while, and tried to decide whether to pursue it or Ruby, and ended up deciding on Ruby, since I kept writing Rubish Python.

Unfortunately, I've now moved over to iPhone development for a school project. This means using a Mac/XCode/Objective-C. This feels exactly like the "Here's some resources go do the job" from before, but by this time I'm getting used to it. Languages and development environments are starting to feel interchangeable. I don't have a lot of attachment to any language, except to Ruby because of a lot of the unique language constructs it offers over C++. I guess "real world" programming requires you to do whatever it takes to get the job done, but it also makes all languages emotionally neutral.

Part of me wishes for the old days of Java development where picking the language for the job was easy, because there was only one that you knew. However, another part wishes I knew more in-depth of each of the languages, and that I'm afraid of hurting myself through not knowing any language really well (though I am very proficient in Java, C++, and Ruby). Languages have become merely notations for doing something, pawns to get a computer to accomplish whatever you wish.

My journey is not yet complete. I want to explore more into Haskell (I played with Erlang a few months ago), Lisp, SQL, and Smalltalk to see more of the world of programming, but sort of want some language to call home.

Thursday, February 5, 2009

Radial Space Filling Tree


I've been continuing work with my color wheel using radial space filling trees, inspired in part because of DocBurst. I've modified the original source code to allow multiple levels of rings, though only three are seen here (the center circle is considered a segment, but I set it to the background color). Children sectors in the ring are constrained to the angle bounds of its parent.

Further steps include click detection on segments based to select different segments, and extracting a child segment to form a new color wheel.

Wednesday, February 4, 2009

Rings of Color




I've been thinking of making a color wheel for playing around with color palettes. This is an initial concept that I came up where sectors display colors. To actually get the ring effect I painted all of the colors as pies, and then filled the center of the circle containing the color pies with the background color.



Adding more colors creates more sections of the ring and the spacers prevent them from getting too close together. Future steps are to add a feature to generate shades of a color at given steps from a certain hue based upon saturation or brightness. Adding and saving of color palettes and exporting as Qt style sheets would also be useful.

Creating and editing colors is done using the already provided QColorDialog. Unfortunately, it doesn't provide as many options as the Java Swing Color Chooser, but it gets the job done for now.

Tuesday, February 3, 2009

Porting QT between C++ and Ruby

I have an assignment due next week for a graphics class I'm taking and I have given the ability to use whatever language or windowing libraries I want, provided they are portable. The only condition is that we are required to use OpenGL. Well, I wrote the project initially using C with GLUT, and then after realizing that my C code is really sketch, and ported it to a more familiar environment C++/Qt.

OpenGL with Qt is not really a much different animal than with GLUT, but it seems like OpenGL integrates better with the interface in Qt. I'd like to also try out OpenGL with FxRuby and WxWidgets to get a better idea of how to work with both traditional GUI interfaces while adding OpenGL effects to the mix. The OpenGL page for Ruby has a lot of helpful tips.